]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.10.11-201309081953.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.10.11-201309081953.patch
CommitLineData
51844ada
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..79768fb 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29+*.vim
30 *.xml
31 *.xz
32 *_MODULES
33+*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38-.*
39+.[^g]*
40+.gen*
41 .*.d
42 .mm
43 53c700_d.h
44@@ -69,9 +75,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52+TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56@@ -80,6 +88,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60+ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64@@ -92,19 +101,24 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68+builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74+clut_vga16.c
75+common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82+config.c
83 config.mak
84 config.mak.autogen
85+config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89@@ -115,9 +129,11 @@ devlist.h*
90 dnotify_test
91 docproc
92 dslm
93+dtc-lexer.lex.c
94 elf2ecoff
95 elfconfig.h*
96 evergreen_reg_safe.h
97+exception_policy.conf
98 fixdep
99 flask.h
100 fore200e_mkfirm
101@@ -125,12 +141,15 @@ fore200e_pca_fw.c*
102 gconf
103 gconf.glade.h
104 gen-devlist
105+gen-kdb_cmds.c
106 gen_crc32table
107 gen_init_cpio
108 generated
109 genheaders
110 genksyms
111 *_gray256.c
112+hash
113+hid-example
114 hpet_example
115 hugepage-mmap
116 hugepage-shm
117@@ -145,14 +164,14 @@ int32.c
118 int4.c
119 int8.c
120 kallsyms
121-kconfig
122+kern_constants.h
123 keywords.c
124 ksym.c*
125 ksym.h*
126 kxgettext
127 lex.c
128 lex.*.c
129-linux
130+lib1funcs.S
131 logo_*.c
132 logo_*_clut224.c
133 logo_*_mono.c
134@@ -162,14 +181,15 @@ mach-types.h
135 machtypes.h
136 map
137 map_hugetlb
138-media
139 mconf
140+mdp
141 miboot*
142 mk_elfconfig
143 mkboot
144 mkbugboot
145 mkcpustr
146 mkdep
147+mkpiggy
148 mkprep
149 mkregtable
150 mktables
151@@ -185,6 +205,8 @@ oui.c*
152 page-types
153 parse.c
154 parse.h
155+parse-events*
156+pasyms.h
157 patches*
158 pca200e.bin
159 pca200e_ecd.bin2
160@@ -194,6 +216,7 @@ perf-archive
161 piggyback
162 piggy.gzip
163 piggy.S
164+pmu-*
165 pnmtologo
166 ppc_defs.h*
167 pss_boot.h
168@@ -203,7 +226,10 @@ r200_reg_safe.h
169 r300_reg_safe.h
170 r420_reg_safe.h
171 r600_reg_safe.h
172+realmode.lds
173+realmode.relocs
174 recordmcount
175+regdb.c
176 relocs
177 rlim_names.h
178 rn50_reg_safe.h
179@@ -213,8 +239,12 @@ series
180 setup
181 setup.bin
182 setup.elf
183+signing_key*
184+size_overflow_hash.h
185 sImage
186+slabinfo
187 sm_tbl*
188+sortextable
189 split-include
190 syscalltab.h
191 tables.c
192@@ -224,6 +254,7 @@ tftpboot.img
193 timeconst.h
194 times.h*
195 trix_boot.h
196+user_constants.h
197 utsrelease.h*
198 vdso-syms.lds
199 vdso.lds
200@@ -235,13 +266,17 @@ vdso32.lds
201 vdso32.so.dbg
202 vdso64.lds
203 vdso64.so.dbg
204+vdsox32.lds
205+vdsox32-syms.lds
206 version.h*
207 vmImage
208 vmlinux
209 vmlinux-*
210 vmlinux.aout
211 vmlinux.bin.all
212+vmlinux.bin.bz2
213 vmlinux.lds
214+vmlinux.relocs
215 vmlinuz
216 voffset.h
217 vsyscall.lds
218@@ -249,9 +284,12 @@ vsyscall_32.lds
219 wanxlfw.inc
220 uImage
221 unifdef
222+utsrelease.h
223 wakeup.bin
224 wakeup.elf
225 wakeup.lds
226+x509*
227 zImage*
228 zconf.hash.c
229+zconf.lex.c
230 zoffset.h
231diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
232index 2fe6e76..889ee23 100644
233--- a/Documentation/kernel-parameters.txt
234+++ b/Documentation/kernel-parameters.txt
235@@ -976,6 +976,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
236 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
237 Default: 1024
238
239+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
240+ ignore grsecurity's /proc restrictions
241+
242+
243 hashdist= [KNL,NUMA] Large hashes allocated during boot
244 are distributed across NUMA nodes. Defaults on
245 for 64-bit NUMA, off otherwise.
246@@ -1928,6 +1932,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
247 noexec=on: enable non-executable mappings (default)
248 noexec=off: disable non-executable mappings
249
250+ nopcid [X86-64]
251+ Disable PCID (Process-Context IDentifier) even if it
252+ is supported by the processor.
253+
254 nosmap [X86]
255 Disable SMAP (Supervisor Mode Access Prevention)
256 even if it is supported by processor.
257@@ -2195,6 +2203,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
258 the specified number of seconds. This is to be used if
259 your oopses keep scrolling off the screen.
260
261+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
262+ virtualization environments that don't cope well with the
263+ expand down segment used by UDEREF on X86-32 or the frequent
264+ page table updates on X86-64.
265+
266+ pax_sanitize_slab=
267+ 0/1 to disable/enable slab object sanitization (enabled by
268+ default).
269+
270+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
271+
272+ pax_extra_latent_entropy
273+ Enable a very simple form of latent entropy extraction
274+ from the first 4GB of memory as the bootmem allocator
275+ passes the memory pages to the buddy allocator.
276+
277+ pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
278+ when the processor supports PCID.
279+
280 pcbit= [HW,ISDN]
281
282 pcd. [PARIDE]
283diff --git a/Makefile b/Makefile
284index 595076d..9b52b98 100644
285--- a/Makefile
286+++ b/Makefile
287@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
288
289 HOSTCC = gcc
290 HOSTCXX = g++
291-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
292-HOSTCXXFLAGS = -O2
293+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
294+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
295+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
296
297 # Decide whether to build built-in, modular, or both.
298 # Normally, just do built-in.
299@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
300 # Rules shared between *config targets and build targets
301
302 # Basic helpers built in scripts/
303-PHONY += scripts_basic
304-scripts_basic:
305+PHONY += scripts_basic gcc-plugins
306+scripts_basic: gcc-plugins
307 $(Q)$(MAKE) $(build)=scripts/basic
308 $(Q)rm -f .tmp_quiet_recordmcount
309
310@@ -576,6 +577,65 @@ else
311 KBUILD_CFLAGS += -O2
312 endif
313
314+ifndef DISABLE_PAX_PLUGINS
315+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
316+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
317+else
318+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
319+endif
320+ifneq ($(PLUGINCC),)
321+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
322+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
323+endif
324+ifdef CONFIG_PAX_MEMORY_STACKLEAK
325+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
326+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
327+endif
328+ifdef CONFIG_KALLOCSTAT_PLUGIN
329+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
330+endif
331+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
332+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
333+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
334+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
335+endif
336+ifdef CONFIG_CHECKER_PLUGIN
337+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
338+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
339+endif
340+endif
341+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
342+ifdef CONFIG_PAX_SIZE_OVERFLOW
343+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
344+endif
345+ifdef CONFIG_PAX_LATENT_ENTROPY
346+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
347+endif
348+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
349+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
350+endif
351+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
352+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
353+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
354+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
355+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
356+ifeq ($(KBUILD_EXTMOD),)
357+gcc-plugins:
358+ $(Q)$(MAKE) $(build)=tools/gcc
359+else
360+gcc-plugins: ;
361+endif
362+else
363+gcc-plugins:
364+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
365+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
366+else
367+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
368+endif
369+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
370+endif
371+endif
372+
373 include $(srctree)/arch/$(SRCARCH)/Makefile
374
375 ifdef CONFIG_READABLE_ASM
376@@ -733,7 +793,7 @@ export mod_sign_cmd
377
378
379 ifeq ($(KBUILD_EXTMOD),)
380-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
381+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
382
383 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
384 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
385@@ -782,6 +842,8 @@ endif
386
387 # The actual objects are generated when descending,
388 # make sure no implicit rule kicks in
389+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
390+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
391 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
392
393 # Handle descending into subdirectories listed in $(vmlinux-dirs)
394@@ -791,7 +853,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
395 # Error messages still appears in the original language
396
397 PHONY += $(vmlinux-dirs)
398-$(vmlinux-dirs): prepare scripts
399+$(vmlinux-dirs): gcc-plugins prepare scripts
400 $(Q)$(MAKE) $(build)=$@
401
402 # Store (new) KERNELRELASE string in include/config/kernel.release
403@@ -835,6 +897,7 @@ prepare0: archprepare FORCE
404 $(Q)$(MAKE) $(build)=.
405
406 # All the preparing..
407+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
408 prepare: prepare0
409
410 # Generate some files
411@@ -942,6 +1005,8 @@ all: modules
412 # using awk while concatenating to the final file.
413
414 PHONY += modules
415+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
418 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
419 @$(kecho) ' Building modules, stage 2.';
420@@ -957,7 +1022,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
421
422 # Target to prepare building external modules
423 PHONY += modules_prepare
424-modules_prepare: prepare scripts
425+modules_prepare: gcc-plugins prepare scripts
426
427 # Target to install modules
428 PHONY += modules_install
429@@ -1023,7 +1088,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
430 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
431 signing_key.priv signing_key.x509 x509.genkey \
432 extra_certificates signing_key.x509.keyid \
433- signing_key.x509.signer
434+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
435
436 # clean - Delete most, but leave enough to build external modules
437 #
438@@ -1063,6 +1128,7 @@ distclean: mrproper
439 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
440 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
441 -o -name '.*.rej' \
442+ -o -name '.*.rej' -o -name '*.so' \
443 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
444 -type f -print | xargs rm -f
445
446@@ -1223,6 +1289,8 @@ PHONY += $(module-dirs) modules
447 $(module-dirs): crmodverdir $(objtree)/Module.symvers
448 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
449
450+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
451+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
452 modules: $(module-dirs)
453 @$(kecho) ' Building modules, stage 2.';
454 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
455@@ -1359,17 +1427,21 @@ else
456 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
457 endif
458
459-%.s: %.c prepare scripts FORCE
460+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
461+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
462+%.s: %.c gcc-plugins prepare scripts FORCE
463 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
464 %.i: %.c prepare scripts FORCE
465 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
466-%.o: %.c prepare scripts FORCE
467+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
468+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
469+%.o: %.c gcc-plugins prepare scripts FORCE
470 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
471 %.lst: %.c prepare scripts FORCE
472 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
473-%.s: %.S prepare scripts FORCE
474+%.s: %.S gcc-plugins prepare scripts FORCE
475 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
476-%.o: %.S prepare scripts FORCE
477+%.o: %.S gcc-plugins prepare scripts FORCE
478 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
479 %.symtypes: %.c prepare scripts FORCE
480 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
481@@ -1379,11 +1451,15 @@ endif
482 $(cmd_crmodverdir)
483 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
484 $(build)=$(build-dir)
485-%/: prepare scripts FORCE
486+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
487+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
488+%/: gcc-plugins prepare scripts FORCE
489 $(cmd_crmodverdir)
490 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
491 $(build)=$(build-dir)
492-%.ko: prepare scripts FORCE
493+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495+%.ko: gcc-plugins prepare scripts FORCE
496 $(cmd_crmodverdir)
497 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
498 $(build)=$(build-dir) $(@:.ko=.o)
499diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
500index c2cbe4f..f7264b4 100644
501--- a/arch/alpha/include/asm/atomic.h
502+++ b/arch/alpha/include/asm/atomic.h
503@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
504 #define atomic_dec(v) atomic_sub(1,(v))
505 #define atomic64_dec(v) atomic64_sub(1,(v))
506
507+#define atomic64_read_unchecked(v) atomic64_read(v)
508+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
509+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
510+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
511+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
512+#define atomic64_inc_unchecked(v) atomic64_inc(v)
513+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
514+#define atomic64_dec_unchecked(v) atomic64_dec(v)
515+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
516+
517 #define smp_mb__before_atomic_dec() smp_mb()
518 #define smp_mb__after_atomic_dec() smp_mb()
519 #define smp_mb__before_atomic_inc() smp_mb()
520diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
521index ad368a9..fbe0f25 100644
522--- a/arch/alpha/include/asm/cache.h
523+++ b/arch/alpha/include/asm/cache.h
524@@ -4,19 +4,19 @@
525 #ifndef __ARCH_ALPHA_CACHE_H
526 #define __ARCH_ALPHA_CACHE_H
527
528+#include <linux/const.h>
529
530 /* Bytes per L1 (data) cache line. */
531 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
532-# define L1_CACHE_BYTES 64
533 # define L1_CACHE_SHIFT 6
534 #else
535 /* Both EV4 and EV5 are write-through, read-allocate,
536 direct-mapped, physical.
537 */
538-# define L1_CACHE_BYTES 32
539 # define L1_CACHE_SHIFT 5
540 #endif
541
542+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
543 #define SMP_CACHE_BYTES L1_CACHE_BYTES
544
545 #endif
546diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
547index 968d999..d36b2df 100644
548--- a/arch/alpha/include/asm/elf.h
549+++ b/arch/alpha/include/asm/elf.h
550@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
551
552 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
553
554+#ifdef CONFIG_PAX_ASLR
555+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
556+
557+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
558+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
559+#endif
560+
561 /* $0 is set by ld.so to a pointer to a function which might be
562 registered using atexit. This provides a mean for the dynamic
563 linker to call DT_FINI functions for shared libraries that have
564diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
565index bc2a0da..8ad11ee 100644
566--- a/arch/alpha/include/asm/pgalloc.h
567+++ b/arch/alpha/include/asm/pgalloc.h
568@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
569 pgd_set(pgd, pmd);
570 }
571
572+static inline void
573+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
574+{
575+ pgd_populate(mm, pgd, pmd);
576+}
577+
578 extern pgd_t *pgd_alloc(struct mm_struct *mm);
579
580 static inline void
581diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
582index 81a4342..348b927 100644
583--- a/arch/alpha/include/asm/pgtable.h
584+++ b/arch/alpha/include/asm/pgtable.h
585@@ -102,6 +102,17 @@ struct vm_area_struct;
586 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
587 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
588 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
589+
590+#ifdef CONFIG_PAX_PAGEEXEC
591+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
592+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
593+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
594+#else
595+# define PAGE_SHARED_NOEXEC PAGE_SHARED
596+# define PAGE_COPY_NOEXEC PAGE_COPY
597+# define PAGE_READONLY_NOEXEC PAGE_READONLY
598+#endif
599+
600 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
601
602 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
603diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
604index 2fd00b7..cfd5069 100644
605--- a/arch/alpha/kernel/module.c
606+++ b/arch/alpha/kernel/module.c
607@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
608
609 /* The small sections were sorted to the end of the segment.
610 The following should definitely cover them. */
611- gp = (u64)me->module_core + me->core_size - 0x8000;
612+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
613 got = sechdrs[me->arch.gotsecindex].sh_addr;
614
615 for (i = 0; i < n; i++) {
616diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
617index b9e37ad..44c24e7 100644
618--- a/arch/alpha/kernel/osf_sys.c
619+++ b/arch/alpha/kernel/osf_sys.c
620@@ -1297,10 +1297,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
621 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
622
623 static unsigned long
624-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
625- unsigned long limit)
626+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
627+ unsigned long limit, unsigned long flags)
628 {
629 struct vm_unmapped_area_info info;
630+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
631
632 info.flags = 0;
633 info.length = len;
634@@ -1308,6 +1309,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
635 info.high_limit = limit;
636 info.align_mask = 0;
637 info.align_offset = 0;
638+ info.threadstack_offset = offset;
639 return vm_unmapped_area(&info);
640 }
641
642@@ -1340,20 +1342,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
643 merely specific addresses, but regions of memory -- perhaps
644 this feature should be incorporated into all ports? */
645
646+#ifdef CONFIG_PAX_RANDMMAP
647+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
648+#endif
649+
650 if (addr) {
651- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
652+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
653 if (addr != (unsigned long) -ENOMEM)
654 return addr;
655 }
656
657 /* Next, try allocating at TASK_UNMAPPED_BASE. */
658- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
659- len, limit);
660+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
661+
662 if (addr != (unsigned long) -ENOMEM)
663 return addr;
664
665 /* Finally, try allocating in low memory. */
666- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
667+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
668
669 return addr;
670 }
671diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
672index 0c4132d..88f0d53 100644
673--- a/arch/alpha/mm/fault.c
674+++ b/arch/alpha/mm/fault.c
675@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
676 __reload_thread(pcb);
677 }
678
679+#ifdef CONFIG_PAX_PAGEEXEC
680+/*
681+ * PaX: decide what to do with offenders (regs->pc = fault address)
682+ *
683+ * returns 1 when task should be killed
684+ * 2 when patched PLT trampoline was detected
685+ * 3 when unpatched PLT trampoline was detected
686+ */
687+static int pax_handle_fetch_fault(struct pt_regs *regs)
688+{
689+
690+#ifdef CONFIG_PAX_EMUPLT
691+ int err;
692+
693+ do { /* PaX: patched PLT emulation #1 */
694+ unsigned int ldah, ldq, jmp;
695+
696+ err = get_user(ldah, (unsigned int *)regs->pc);
697+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
698+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
699+
700+ if (err)
701+ break;
702+
703+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
704+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
705+ jmp == 0x6BFB0000U)
706+ {
707+ unsigned long r27, addr;
708+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
709+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
710+
711+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
712+ err = get_user(r27, (unsigned long *)addr);
713+ if (err)
714+ break;
715+
716+ regs->r27 = r27;
717+ regs->pc = r27;
718+ return 2;
719+ }
720+ } while (0);
721+
722+ do { /* PaX: patched PLT emulation #2 */
723+ unsigned int ldah, lda, br;
724+
725+ err = get_user(ldah, (unsigned int *)regs->pc);
726+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
727+ err |= get_user(br, (unsigned int *)(regs->pc+8));
728+
729+ if (err)
730+ break;
731+
732+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
733+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
734+ (br & 0xFFE00000U) == 0xC3E00000U)
735+ {
736+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
737+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
738+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
739+
740+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
741+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
742+ return 2;
743+ }
744+ } while (0);
745+
746+ do { /* PaX: unpatched PLT emulation */
747+ unsigned int br;
748+
749+ err = get_user(br, (unsigned int *)regs->pc);
750+
751+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
752+ unsigned int br2, ldq, nop, jmp;
753+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
754+
755+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
756+ err = get_user(br2, (unsigned int *)addr);
757+ err |= get_user(ldq, (unsigned int *)(addr+4));
758+ err |= get_user(nop, (unsigned int *)(addr+8));
759+ err |= get_user(jmp, (unsigned int *)(addr+12));
760+ err |= get_user(resolver, (unsigned long *)(addr+16));
761+
762+ if (err)
763+ break;
764+
765+ if (br2 == 0xC3600000U &&
766+ ldq == 0xA77B000CU &&
767+ nop == 0x47FF041FU &&
768+ jmp == 0x6B7B0000U)
769+ {
770+ regs->r28 = regs->pc+4;
771+ regs->r27 = addr+16;
772+ regs->pc = resolver;
773+ return 3;
774+ }
775+ }
776+ } while (0);
777+#endif
778+
779+ return 1;
780+}
781+
782+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
783+{
784+ unsigned long i;
785+
786+ printk(KERN_ERR "PAX: bytes at PC: ");
787+ for (i = 0; i < 5; i++) {
788+ unsigned int c;
789+ if (get_user(c, (unsigned int *)pc+i))
790+ printk(KERN_CONT "???????? ");
791+ else
792+ printk(KERN_CONT "%08x ", c);
793+ }
794+ printk("\n");
795+}
796+#endif
797
798 /*
799 * This routine handles page faults. It determines the address,
800@@ -133,8 +251,29 @@ retry:
801 good_area:
802 si_code = SEGV_ACCERR;
803 if (cause < 0) {
804- if (!(vma->vm_flags & VM_EXEC))
805+ if (!(vma->vm_flags & VM_EXEC)) {
806+
807+#ifdef CONFIG_PAX_PAGEEXEC
808+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
809+ goto bad_area;
810+
811+ up_read(&mm->mmap_sem);
812+ switch (pax_handle_fetch_fault(regs)) {
813+
814+#ifdef CONFIG_PAX_EMUPLT
815+ case 2:
816+ case 3:
817+ return;
818+#endif
819+
820+ }
821+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
822+ do_group_exit(SIGKILL);
823+#else
824 goto bad_area;
825+#endif
826+
827+ }
828 } else if (!cause) {
829 /* Allow reads even for write-only mappings */
830 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
831diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
832index 18a9f5e..ca910b7 100644
833--- a/arch/arm/Kconfig
834+++ b/arch/arm/Kconfig
835@@ -1766,7 +1766,7 @@ config ALIGNMENT_TRAP
836
837 config UACCESS_WITH_MEMCPY
838 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
839- depends on MMU
840+ depends on MMU && !PAX_MEMORY_UDEREF
841 default y if CPU_FEROCEON
842 help
843 Implement faster copy_to_user and clear_user methods for CPU
844diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
845index da1c77d..2ee6056 100644
846--- a/arch/arm/include/asm/atomic.h
847+++ b/arch/arm/include/asm/atomic.h
848@@ -17,17 +17,35 @@
849 #include <asm/barrier.h>
850 #include <asm/cmpxchg.h>
851
852+#ifdef CONFIG_GENERIC_ATOMIC64
853+#include <asm-generic/atomic64.h>
854+#endif
855+
856 #define ATOMIC_INIT(i) { (i) }
857
858 #ifdef __KERNEL__
859
860+#define _ASM_EXTABLE(from, to) \
861+" .pushsection __ex_table,\"a\"\n"\
862+" .align 3\n" \
863+" .long " #from ", " #to"\n" \
864+" .popsection"
865+
866 /*
867 * On ARM, ordinary assignment (str instruction) doesn't clear the local
868 * strex/ldrex monitor on some implementations. The reason we can use it for
869 * atomic_set() is the clrex or dummy strex done on every exception return.
870 */
871 #define atomic_read(v) (*(volatile int *)&(v)->counter)
872+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
873+{
874+ return v->counter;
875+}
876 #define atomic_set(v,i) (((v)->counter) = (i))
877+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
878+{
879+ v->counter = i;
880+}
881
882 #if __LINUX_ARM_ARCH__ >= 6
883
884@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
885 int result;
886
887 __asm__ __volatile__("@ atomic_add\n"
888+"1: ldrex %1, [%3]\n"
889+" adds %0, %1, %4\n"
890+
891+#ifdef CONFIG_PAX_REFCOUNT
892+" bvc 3f\n"
893+"2: bkpt 0xf103\n"
894+"3:\n"
895+#endif
896+
897+" strex %1, %0, [%3]\n"
898+" teq %1, #0\n"
899+" bne 1b"
900+
901+#ifdef CONFIG_PAX_REFCOUNT
902+"\n4:\n"
903+ _ASM_EXTABLE(2b, 4b)
904+#endif
905+
906+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
907+ : "r" (&v->counter), "Ir" (i)
908+ : "cc");
909+}
910+
911+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
912+{
913+ unsigned long tmp;
914+ int result;
915+
916+ __asm__ __volatile__("@ atomic_add_unchecked\n"
917 "1: ldrex %0, [%3]\n"
918 " add %0, %0, %4\n"
919 " strex %1, %0, [%3]\n"
920@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
921 smp_mb();
922
923 __asm__ __volatile__("@ atomic_add_return\n"
924+"1: ldrex %1, [%3]\n"
925+" adds %0, %1, %4\n"
926+
927+#ifdef CONFIG_PAX_REFCOUNT
928+" bvc 3f\n"
929+" mov %0, %1\n"
930+"2: bkpt 0xf103\n"
931+"3:\n"
932+#endif
933+
934+" strex %1, %0, [%3]\n"
935+" teq %1, #0\n"
936+" bne 1b"
937+
938+#ifdef CONFIG_PAX_REFCOUNT
939+"\n4:\n"
940+ _ASM_EXTABLE(2b, 4b)
941+#endif
942+
943+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
944+ : "r" (&v->counter), "Ir" (i)
945+ : "cc");
946+
947+ smp_mb();
948+
949+ return result;
950+}
951+
952+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
953+{
954+ unsigned long tmp;
955+ int result;
956+
957+ smp_mb();
958+
959+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
960 "1: ldrex %0, [%3]\n"
961 " add %0, %0, %4\n"
962 " strex %1, %0, [%3]\n"
963@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
964 int result;
965
966 __asm__ __volatile__("@ atomic_sub\n"
967+"1: ldrex %1, [%3]\n"
968+" subs %0, %1, %4\n"
969+
970+#ifdef CONFIG_PAX_REFCOUNT
971+" bvc 3f\n"
972+"2: bkpt 0xf103\n"
973+"3:\n"
974+#endif
975+
976+" strex %1, %0, [%3]\n"
977+" teq %1, #0\n"
978+" bne 1b"
979+
980+#ifdef CONFIG_PAX_REFCOUNT
981+"\n4:\n"
982+ _ASM_EXTABLE(2b, 4b)
983+#endif
984+
985+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
986+ : "r" (&v->counter), "Ir" (i)
987+ : "cc");
988+}
989+
990+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
991+{
992+ unsigned long tmp;
993+ int result;
994+
995+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
996 "1: ldrex %0, [%3]\n"
997 " sub %0, %0, %4\n"
998 " strex %1, %0, [%3]\n"
999@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1000 smp_mb();
1001
1002 __asm__ __volatile__("@ atomic_sub_return\n"
1003-"1: ldrex %0, [%3]\n"
1004-" sub %0, %0, %4\n"
1005+"1: ldrex %1, [%3]\n"
1006+" subs %0, %1, %4\n"
1007+
1008+#ifdef CONFIG_PAX_REFCOUNT
1009+" bvc 3f\n"
1010+" mov %0, %1\n"
1011+"2: bkpt 0xf103\n"
1012+"3:\n"
1013+#endif
1014+
1015 " strex %1, %0, [%3]\n"
1016 " teq %1, #0\n"
1017 " bne 1b"
1018+
1019+#ifdef CONFIG_PAX_REFCOUNT
1020+"\n4:\n"
1021+ _ASM_EXTABLE(2b, 4b)
1022+#endif
1023+
1024 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1025 : "r" (&v->counter), "Ir" (i)
1026 : "cc");
1027@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1028 return oldval;
1029 }
1030
1031+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1032+{
1033+ unsigned long oldval, res;
1034+
1035+ smp_mb();
1036+
1037+ do {
1038+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1039+ "ldrex %1, [%3]\n"
1040+ "mov %0, #0\n"
1041+ "teq %1, %4\n"
1042+ "strexeq %0, %5, [%3]\n"
1043+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1044+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1045+ : "cc");
1046+ } while (res);
1047+
1048+ smp_mb();
1049+
1050+ return oldval;
1051+}
1052+
1053 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1054 {
1055 unsigned long tmp, tmp2;
1056@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1057
1058 return val;
1059 }
1060+
1061+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1062+{
1063+ return atomic_add_return(i, v);
1064+}
1065+
1066 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1067+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1068+{
1069+ (void) atomic_add_return(i, v);
1070+}
1071
1072 static inline int atomic_sub_return(int i, atomic_t *v)
1073 {
1074@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1075 return val;
1076 }
1077 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1078+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1079+{
1080+ (void) atomic_sub_return(i, v);
1081+}
1082
1083 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1084 {
1085@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1086 return ret;
1087 }
1088
1089+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1090+{
1091+ return atomic_cmpxchg(v, old, new);
1092+}
1093+
1094 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1095 {
1096 unsigned long flags;
1097@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1098 #endif /* __LINUX_ARM_ARCH__ */
1099
1100 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1101+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1102+{
1103+ return xchg(&v->counter, new);
1104+}
1105
1106 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1107 {
1108@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1109 }
1110
1111 #define atomic_inc(v) atomic_add(1, v)
1112+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1113+{
1114+ atomic_add_unchecked(1, v);
1115+}
1116 #define atomic_dec(v) atomic_sub(1, v)
1117+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1118+{
1119+ atomic_sub_unchecked(1, v);
1120+}
1121
1122 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1123+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1124+{
1125+ return atomic_add_return_unchecked(1, v) == 0;
1126+}
1127 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1128 #define atomic_inc_return(v) (atomic_add_return(1, v))
1129+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1130+{
1131+ return atomic_add_return_unchecked(1, v);
1132+}
1133 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1134 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1135
1136@@ -241,6 +428,14 @@ typedef struct {
1137 u64 __aligned(8) counter;
1138 } atomic64_t;
1139
1140+#ifdef CONFIG_PAX_REFCOUNT
1141+typedef struct {
1142+ u64 __aligned(8) counter;
1143+} atomic64_unchecked_t;
1144+#else
1145+typedef atomic64_t atomic64_unchecked_t;
1146+#endif
1147+
1148 #define ATOMIC64_INIT(i) { (i) }
1149
1150 #ifdef CONFIG_ARM_LPAE
1151@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1152 return result;
1153 }
1154
1155+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1156+{
1157+ u64 result;
1158+
1159+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1160+" ldrd %0, %H0, [%1]"
1161+ : "=&r" (result)
1162+ : "r" (&v->counter), "Qo" (v->counter)
1163+ );
1164+
1165+ return result;
1166+}
1167+
1168 static inline void atomic64_set(atomic64_t *v, u64 i)
1169 {
1170 __asm__ __volatile__("@ atomic64_set\n"
1171@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1172 : "r" (&v->counter), "r" (i)
1173 );
1174 }
1175+
1176+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1177+{
1178+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1179+" strd %2, %H2, [%1]"
1180+ : "=Qo" (v->counter)
1181+ : "r" (&v->counter), "r" (i)
1182+ );
1183+}
1184 #else
1185 static inline u64 atomic64_read(const atomic64_t *v)
1186 {
1187@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1188 return result;
1189 }
1190
1191+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1192+{
1193+ u64 result;
1194+
1195+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1196+" ldrexd %0, %H0, [%1]"
1197+ : "=&r" (result)
1198+ : "r" (&v->counter), "Qo" (v->counter)
1199+ );
1200+
1201+ return result;
1202+}
1203+
1204 static inline void atomic64_set(atomic64_t *v, u64 i)
1205 {
1206 u64 tmp;
1207@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1208 : "r" (&v->counter), "r" (i)
1209 : "cc");
1210 }
1211+
1212+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1213+{
1214+ u64 tmp;
1215+
1216+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1217+"1: ldrexd %0, %H0, [%2]\n"
1218+" strexd %0, %3, %H3, [%2]\n"
1219+" teq %0, #0\n"
1220+" bne 1b"
1221+ : "=&r" (tmp), "=Qo" (v->counter)
1222+ : "r" (&v->counter), "r" (i)
1223+ : "cc");
1224+}
1225+
1226 #endif
1227
1228 static inline void atomic64_add(u64 i, atomic64_t *v)
1229@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1230 __asm__ __volatile__("@ atomic64_add\n"
1231 "1: ldrexd %0, %H0, [%3]\n"
1232 " adds %0, %0, %4\n"
1233+" adcs %H0, %H0, %H4\n"
1234+
1235+#ifdef CONFIG_PAX_REFCOUNT
1236+" bvc 3f\n"
1237+"2: bkpt 0xf103\n"
1238+"3:\n"
1239+#endif
1240+
1241+" strexd %1, %0, %H0, [%3]\n"
1242+" teq %1, #0\n"
1243+" bne 1b"
1244+
1245+#ifdef CONFIG_PAX_REFCOUNT
1246+"\n4:\n"
1247+ _ASM_EXTABLE(2b, 4b)
1248+#endif
1249+
1250+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1251+ : "r" (&v->counter), "r" (i)
1252+ : "cc");
1253+}
1254+
1255+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1256+{
1257+ u64 result;
1258+ unsigned long tmp;
1259+
1260+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1261+"1: ldrexd %0, %H0, [%3]\n"
1262+" adds %0, %0, %4\n"
1263 " adc %H0, %H0, %H4\n"
1264 " strexd %1, %0, %H0, [%3]\n"
1265 " teq %1, #0\n"
1266@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1267
1268 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1269 {
1270- u64 result;
1271- unsigned long tmp;
1272+ u64 result, tmp;
1273
1274 smp_mb();
1275
1276 __asm__ __volatile__("@ atomic64_add_return\n"
1277+"1: ldrexd %1, %H1, [%3]\n"
1278+" adds %0, %1, %4\n"
1279+" adcs %H0, %H1, %H4\n"
1280+
1281+#ifdef CONFIG_PAX_REFCOUNT
1282+" bvc 3f\n"
1283+" mov %0, %1\n"
1284+" mov %H0, %H1\n"
1285+"2: bkpt 0xf103\n"
1286+"3:\n"
1287+#endif
1288+
1289+" strexd %1, %0, %H0, [%3]\n"
1290+" teq %1, #0\n"
1291+" bne 1b"
1292+
1293+#ifdef CONFIG_PAX_REFCOUNT
1294+"\n4:\n"
1295+ _ASM_EXTABLE(2b, 4b)
1296+#endif
1297+
1298+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1299+ : "r" (&v->counter), "r" (i)
1300+ : "cc");
1301+
1302+ smp_mb();
1303+
1304+ return result;
1305+}
1306+
1307+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1308+{
1309+ u64 result;
1310+ unsigned long tmp;
1311+
1312+ smp_mb();
1313+
1314+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1315 "1: ldrexd %0, %H0, [%3]\n"
1316 " adds %0, %0, %4\n"
1317 " adc %H0, %H0, %H4\n"
1318@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_sub\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " subs %0, %0, %4\n"
1322+" sbcs %H0, %H0, %H4\n"
1323+
1324+#ifdef CONFIG_PAX_REFCOUNT
1325+" bvc 3f\n"
1326+"2: bkpt 0xf103\n"
1327+"3:\n"
1328+#endif
1329+
1330+" strexd %1, %0, %H0, [%3]\n"
1331+" teq %1, #0\n"
1332+" bne 1b"
1333+
1334+#ifdef CONFIG_PAX_REFCOUNT
1335+"\n4:\n"
1336+ _ASM_EXTABLE(2b, 4b)
1337+#endif
1338+
1339+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1340+ : "r" (&v->counter), "r" (i)
1341+ : "cc");
1342+}
1343+
1344+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1345+{
1346+ u64 result;
1347+ unsigned long tmp;
1348+
1349+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1350+"1: ldrexd %0, %H0, [%3]\n"
1351+" subs %0, %0, %4\n"
1352 " sbc %H0, %H0, %H4\n"
1353 " strexd %1, %0, %H0, [%3]\n"
1354 " teq %1, #0\n"
1355@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1356
1357 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1358 {
1359- u64 result;
1360- unsigned long tmp;
1361+ u64 result, tmp;
1362
1363 smp_mb();
1364
1365 __asm__ __volatile__("@ atomic64_sub_return\n"
1366-"1: ldrexd %0, %H0, [%3]\n"
1367-" subs %0, %0, %4\n"
1368-" sbc %H0, %H0, %H4\n"
1369+"1: ldrexd %1, %H1, [%3]\n"
1370+" subs %0, %1, %4\n"
1371+" sbcs %H0, %H1, %H4\n"
1372+
1373+#ifdef CONFIG_PAX_REFCOUNT
1374+" bvc 3f\n"
1375+" mov %0, %1\n"
1376+" mov %H0, %H1\n"
1377+"2: bkpt 0xf103\n"
1378+"3:\n"
1379+#endif
1380+
1381 " strexd %1, %0, %H0, [%3]\n"
1382 " teq %1, #0\n"
1383 " bne 1b"
1384+
1385+#ifdef CONFIG_PAX_REFCOUNT
1386+"\n4:\n"
1387+ _ASM_EXTABLE(2b, 4b)
1388+#endif
1389+
1390 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1391 : "r" (&v->counter), "r" (i)
1392 : "cc");
1393@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1394 return oldval;
1395 }
1396
1397+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1398+{
1399+ u64 oldval;
1400+ unsigned long res;
1401+
1402+ smp_mb();
1403+
1404+ do {
1405+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1406+ "ldrexd %1, %H1, [%3]\n"
1407+ "mov %0, #0\n"
1408+ "teq %1, %4\n"
1409+ "teqeq %H1, %H4\n"
1410+ "strexdeq %0, %5, %H5, [%3]"
1411+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1412+ : "r" (&ptr->counter), "r" (old), "r" (new)
1413+ : "cc");
1414+ } while (res);
1415+
1416+ smp_mb();
1417+
1418+ return oldval;
1419+}
1420+
1421 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1422 {
1423 u64 result;
1424@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1425
1426 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1427 {
1428- u64 result;
1429- unsigned long tmp;
1430+ u64 result, tmp;
1431
1432 smp_mb();
1433
1434 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1435-"1: ldrexd %0, %H0, [%3]\n"
1436-" subs %0, %0, #1\n"
1437-" sbc %H0, %H0, #0\n"
1438+"1: ldrexd %1, %H1, [%3]\n"
1439+" subs %0, %1, #1\n"
1440+" sbcs %H0, %H1, #0\n"
1441+
1442+#ifdef CONFIG_PAX_REFCOUNT
1443+" bvc 3f\n"
1444+" mov %0, %1\n"
1445+" mov %H0, %H1\n"
1446+"2: bkpt 0xf103\n"
1447+"3:\n"
1448+#endif
1449+
1450 " teq %H0, #0\n"
1451-" bmi 2f\n"
1452+" bmi 4f\n"
1453 " strexd %1, %0, %H0, [%3]\n"
1454 " teq %1, #0\n"
1455 " bne 1b\n"
1456-"2:"
1457+"4:\n"
1458+
1459+#ifdef CONFIG_PAX_REFCOUNT
1460+ _ASM_EXTABLE(2b, 4b)
1461+#endif
1462+
1463 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1464 : "r" (&v->counter)
1465 : "cc");
1466@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1467 " teq %0, %5\n"
1468 " teqeq %H0, %H5\n"
1469 " moveq %1, #0\n"
1470-" beq 2f\n"
1471+" beq 4f\n"
1472 " adds %0, %0, %6\n"
1473-" adc %H0, %H0, %H6\n"
1474+" adcs %H0, %H0, %H6\n"
1475+
1476+#ifdef CONFIG_PAX_REFCOUNT
1477+" bvc 3f\n"
1478+"2: bkpt 0xf103\n"
1479+"3:\n"
1480+#endif
1481+
1482 " strexd %2, %0, %H0, [%4]\n"
1483 " teq %2, #0\n"
1484 " bne 1b\n"
1485-"2:"
1486+"4:\n"
1487+
1488+#ifdef CONFIG_PAX_REFCOUNT
1489+ _ASM_EXTABLE(2b, 4b)
1490+#endif
1491+
1492 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1493 : "r" (&v->counter), "r" (u), "r" (a)
1494 : "cc");
1495@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1496
1497 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1498 #define atomic64_inc(v) atomic64_add(1LL, (v))
1499+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1500 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1501+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1502 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1503 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1504 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1505+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1506 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1507 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1508 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1509diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1510index 75fe66b..ba3dee4 100644
1511--- a/arch/arm/include/asm/cache.h
1512+++ b/arch/arm/include/asm/cache.h
1513@@ -4,8 +4,10 @@
1514 #ifndef __ASMARM_CACHE_H
1515 #define __ASMARM_CACHE_H
1516
1517+#include <linux/const.h>
1518+
1519 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1520-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1521+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1522
1523 /*
1524 * Memory returned by kmalloc() may be used for DMA, so we must make
1525@@ -24,5 +26,6 @@
1526 #endif
1527
1528 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1529+#define __read_only __attribute__ ((__section__(".data..read_only")))
1530
1531 #endif
1532diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1533index 17d0ae8..014e350 100644
1534--- a/arch/arm/include/asm/cacheflush.h
1535+++ b/arch/arm/include/asm/cacheflush.h
1536@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1537 void (*dma_unmap_area)(const void *, size_t, int);
1538
1539 void (*dma_flush_range)(const void *, const void *);
1540-};
1541+} __no_const;
1542
1543 /*
1544 * Select the calling method
1545diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1546index 6dcc164..b14d917 100644
1547--- a/arch/arm/include/asm/checksum.h
1548+++ b/arch/arm/include/asm/checksum.h
1549@@ -37,7 +37,19 @@ __wsum
1550 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1551
1552 __wsum
1553-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1554+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1555+
1556+static inline __wsum
1557+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1558+{
1559+ __wsum ret;
1560+ pax_open_userland();
1561+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1562+ pax_close_userland();
1563+ return ret;
1564+}
1565+
1566+
1567
1568 /*
1569 * Fold a partial checksum without adding pseudo headers
1570diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1571index 4f009c1..466c59b 100644
1572--- a/arch/arm/include/asm/cmpxchg.h
1573+++ b/arch/arm/include/asm/cmpxchg.h
1574@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1575
1576 #define xchg(ptr,x) \
1577 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1578+#define xchg_unchecked(ptr,x) \
1579+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1580
1581 #include <asm-generic/cmpxchg-local.h>
1582
1583diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1584index 6ddbe44..b5e38b1 100644
1585--- a/arch/arm/include/asm/domain.h
1586+++ b/arch/arm/include/asm/domain.h
1587@@ -48,18 +48,37 @@
1588 * Domain types
1589 */
1590 #define DOMAIN_NOACCESS 0
1591-#define DOMAIN_CLIENT 1
1592 #ifdef CONFIG_CPU_USE_DOMAINS
1593+#define DOMAIN_USERCLIENT 1
1594+#define DOMAIN_KERNELCLIENT 1
1595 #define DOMAIN_MANAGER 3
1596+#define DOMAIN_VECTORS DOMAIN_USER
1597 #else
1598+
1599+#ifdef CONFIG_PAX_KERNEXEC
1600 #define DOMAIN_MANAGER 1
1601+#define DOMAIN_KERNEXEC 3
1602+#else
1603+#define DOMAIN_MANAGER 1
1604+#endif
1605+
1606+#ifdef CONFIG_PAX_MEMORY_UDEREF
1607+#define DOMAIN_USERCLIENT 0
1608+#define DOMAIN_UDEREF 1
1609+#define DOMAIN_VECTORS DOMAIN_KERNEL
1610+#else
1611+#define DOMAIN_USERCLIENT 1
1612+#define DOMAIN_VECTORS DOMAIN_USER
1613+#endif
1614+#define DOMAIN_KERNELCLIENT 1
1615+
1616 #endif
1617
1618 #define domain_val(dom,type) ((type) << (2*(dom)))
1619
1620 #ifndef __ASSEMBLY__
1621
1622-#ifdef CONFIG_CPU_USE_DOMAINS
1623+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1624 static inline void set_domain(unsigned val)
1625 {
1626 asm volatile(
1627@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1628 isb();
1629 }
1630
1631-#define modify_domain(dom,type) \
1632- do { \
1633- struct thread_info *thread = current_thread_info(); \
1634- unsigned int domain = thread->cpu_domain; \
1635- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1636- thread->cpu_domain = domain | domain_val(dom, type); \
1637- set_domain(thread->cpu_domain); \
1638- } while (0)
1639-
1640+extern void modify_domain(unsigned int dom, unsigned int type);
1641 #else
1642 static inline void set_domain(unsigned val) { }
1643 static inline void modify_domain(unsigned dom, unsigned type) { }
1644diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1645index 56211f2..17e8a25 100644
1646--- a/arch/arm/include/asm/elf.h
1647+++ b/arch/arm/include/asm/elf.h
1648@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1649 the loader. We need to make sure that it is out of the way of the program
1650 that it will "exec", and that there is sufficient room for the brk. */
1651
1652-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1653+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1654+
1655+#ifdef CONFIG_PAX_ASLR
1656+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1657+
1658+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1659+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1660+#endif
1661
1662 /* When the program starts, a1 contains a pointer to a function to be
1663 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1664@@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 extern void elf_set_personality(const struct elf32_hdr *);
1666 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1667
1668-struct mm_struct;
1669-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1670-#define arch_randomize_brk arch_randomize_brk
1671-
1672 #ifdef CONFIG_MMU
1673 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1674 struct linux_binprm;
1675diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1676index de53547..52b9a28 100644
1677--- a/arch/arm/include/asm/fncpy.h
1678+++ b/arch/arm/include/asm/fncpy.h
1679@@ -81,7 +81,9 @@
1680 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1681 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1682 \
1683+ pax_open_kernel(); \
1684 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1685+ pax_close_kernel(); \
1686 flush_icache_range((unsigned long)(dest_buf), \
1687 (unsigned long)(dest_buf) + (size)); \
1688 \
1689diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1690index e42cf59..7b94b8f 100644
1691--- a/arch/arm/include/asm/futex.h
1692+++ b/arch/arm/include/asm/futex.h
1693@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1694 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1695 return -EFAULT;
1696
1697+ pax_open_userland();
1698+
1699 smp_mb();
1700 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1701 "1: ldrex %1, [%4]\n"
1702@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1703 : "cc", "memory");
1704 smp_mb();
1705
1706+ pax_close_userland();
1707+
1708 *uval = val;
1709 return ret;
1710 }
1711@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1712 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1713 return -EFAULT;
1714
1715+ pax_open_userland();
1716+
1717 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1718 "1: " TUSER(ldr) " %1, [%4]\n"
1719 " teq %1, %2\n"
1720@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1721 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1722 : "cc", "memory");
1723
1724+ pax_close_userland();
1725+
1726 *uval = val;
1727 return ret;
1728 }
1729@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1730 return -EFAULT;
1731
1732 pagefault_disable(); /* implies preempt_disable() */
1733+ pax_open_userland();
1734
1735 switch (op) {
1736 case FUTEX_OP_SET:
1737@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1738 ret = -ENOSYS;
1739 }
1740
1741+ pax_close_userland();
1742 pagefault_enable(); /* subsumes preempt_enable() */
1743
1744 if (!ret) {
1745diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1746index 83eb2f7..ed77159 100644
1747--- a/arch/arm/include/asm/kmap_types.h
1748+++ b/arch/arm/include/asm/kmap_types.h
1749@@ -4,6 +4,6 @@
1750 /*
1751 * This is the "bare minimum". AIO seems to require this.
1752 */
1753-#define KM_TYPE_NR 16
1754+#define KM_TYPE_NR 17
1755
1756 #endif
1757diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1758index 9e614a1..3302cca 100644
1759--- a/arch/arm/include/asm/mach/dma.h
1760+++ b/arch/arm/include/asm/mach/dma.h
1761@@ -22,7 +22,7 @@ struct dma_ops {
1762 int (*residue)(unsigned int, dma_t *); /* optional */
1763 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1764 const char *type;
1765-};
1766+} __do_const;
1767
1768 struct dma_struct {
1769 void *addr; /* single DMA address */
1770diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1771index 2fe141f..192dc01 100644
1772--- a/arch/arm/include/asm/mach/map.h
1773+++ b/arch/arm/include/asm/mach/map.h
1774@@ -27,13 +27,16 @@ struct map_desc {
1775 #define MT_MINICLEAN 6
1776 #define MT_LOW_VECTORS 7
1777 #define MT_HIGH_VECTORS 8
1778-#define MT_MEMORY 9
1779+#define MT_MEMORY_RWX 9
1780 #define MT_ROM 10
1781-#define MT_MEMORY_NONCACHED 11
1782+#define MT_MEMORY_NONCACHED_RX 11
1783 #define MT_MEMORY_DTCM 12
1784 #define MT_MEMORY_ITCM 13
1785 #define MT_MEMORY_SO 14
1786 #define MT_MEMORY_DMA_READY 15
1787+#define MT_MEMORY_RW 16
1788+#define MT_MEMORY_RX 17
1789+#define MT_MEMORY_NONCACHED_RW 18
1790
1791 #ifdef CONFIG_MMU
1792 extern void iotable_init(struct map_desc *, int);
1793diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1794index 12f71a1..04e063c 100644
1795--- a/arch/arm/include/asm/outercache.h
1796+++ b/arch/arm/include/asm/outercache.h
1797@@ -35,7 +35,7 @@ struct outer_cache_fns {
1798 #endif
1799 void (*set_debug)(unsigned long);
1800 void (*resume)(void);
1801-};
1802+} __no_const;
1803
1804 #ifdef CONFIG_OUTER_CACHE
1805
1806diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1807index cbdc7a2..32f44fe 100644
1808--- a/arch/arm/include/asm/page.h
1809+++ b/arch/arm/include/asm/page.h
1810@@ -114,7 +114,7 @@ struct cpu_user_fns {
1811 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1812 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1813 unsigned long vaddr, struct vm_area_struct *vma);
1814-};
1815+} __no_const;
1816
1817 #ifdef MULTI_USER
1818 extern struct cpu_user_fns cpu_user;
1819diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1820index 943504f..c37a730 100644
1821--- a/arch/arm/include/asm/pgalloc.h
1822+++ b/arch/arm/include/asm/pgalloc.h
1823@@ -17,6 +17,7 @@
1824 #include <asm/processor.h>
1825 #include <asm/cacheflush.h>
1826 #include <asm/tlbflush.h>
1827+#include <asm/system_info.h>
1828
1829 #define check_pgt_cache() do { } while (0)
1830
1831@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1832 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1833 }
1834
1835+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1836+{
1837+ pud_populate(mm, pud, pmd);
1838+}
1839+
1840 #else /* !CONFIG_ARM_LPAE */
1841
1842 /*
1843@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1844 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1845 #define pmd_free(mm, pmd) do { } while (0)
1846 #define pud_populate(mm,pmd,pte) BUG()
1847+#define pud_populate_kernel(mm,pmd,pte) BUG()
1848
1849 #endif /* CONFIG_ARM_LPAE */
1850
1851@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1852 __free_page(pte);
1853 }
1854
1855+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1856+{
1857+#ifdef CONFIG_ARM_LPAE
1858+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1859+#else
1860+ if (addr & SECTION_SIZE)
1861+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1862+ else
1863+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1864+#endif
1865+ flush_pmd_entry(pmdp);
1866+}
1867+
1868 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1869 pmdval_t prot)
1870 {
1871@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1872 static inline void
1873 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1874 {
1875- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1876+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1877 }
1878 #define pmd_pgtable(pmd) pmd_page(pmd)
1879
1880diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1881index 5cfba15..f415e1a 100644
1882--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1883+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1884@@ -20,12 +20,15 @@
1885 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1886 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1887 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1888+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1889 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1890 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1891 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1892+
1893 /*
1894 * - section
1895 */
1896+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1897 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1898 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1899 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1900@@ -37,6 +40,7 @@
1901 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1902 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1903 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1904+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1905
1906 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1907 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1908@@ -66,6 +70,7 @@
1909 * - extended small page/tiny page
1910 */
1911 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1912+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1913 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1914 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1915 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1916diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1917index f97ee02..cc9fe9e 100644
1918--- a/arch/arm/include/asm/pgtable-2level.h
1919+++ b/arch/arm/include/asm/pgtable-2level.h
1920@@ -126,6 +126,9 @@
1921 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1922 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1923
1924+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1925+#define L_PTE_PXN (_AT(pteval_t, 0))
1926+
1927 /*
1928 * These are the memory types, defined to be compatible with
1929 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1930diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1931index 18f5cef..25b8f43 100644
1932--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1933+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1934@@ -41,6 +41,7 @@
1935 */
1936 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1937 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1938+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1939 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1940 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1941 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1942@@ -71,6 +72,7 @@
1943 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1944 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1945 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1946+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1947 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1948
1949 /*
1950diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1951index 86b8fe3..e25f975 100644
1952--- a/arch/arm/include/asm/pgtable-3level.h
1953+++ b/arch/arm/include/asm/pgtable-3level.h
1954@@ -74,6 +74,7 @@
1955 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1956 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1957 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1958+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1959 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1960 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1961 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1962@@ -82,6 +83,7 @@
1963 /*
1964 * To be used in assembly code with the upper page attributes.
1965 */
1966+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1967 #define L_PTE_XN_HIGH (1 << (54 - 32))
1968 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1969
1970diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1971index 9bcd262..1ff999b 100644
1972--- a/arch/arm/include/asm/pgtable.h
1973+++ b/arch/arm/include/asm/pgtable.h
1974@@ -30,6 +30,9 @@
1975 #include <asm/pgtable-2level.h>
1976 #endif
1977
1978+#define ktla_ktva(addr) (addr)
1979+#define ktva_ktla(addr) (addr)
1980+
1981 /*
1982 * Just any arbitrary offset to the start of the vmalloc VM area: the
1983 * current 8MB value just means that there will be a 8MB "hole" after the
1984@@ -45,6 +48,9 @@
1985 #define LIBRARY_TEXT_START 0x0c000000
1986
1987 #ifndef __ASSEMBLY__
1988+extern pteval_t __supported_pte_mask;
1989+extern pmdval_t __supported_pmd_mask;
1990+
1991 extern void __pte_error(const char *file, int line, pte_t);
1992 extern void __pmd_error(const char *file, int line, pmd_t);
1993 extern void __pgd_error(const char *file, int line, pgd_t);
1994@@ -53,6 +59,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1995 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1996 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1997
1998+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1999+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2000+
2001+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2002+#include <asm/domain.h>
2003+#include <linux/thread_info.h>
2004+#include <linux/preempt.h>
2005+
2006+static inline int test_domain(int domain, int domaintype)
2007+{
2008+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2009+}
2010+#endif
2011+
2012+#ifdef CONFIG_PAX_KERNEXEC
2013+static inline unsigned long pax_open_kernel(void) {
2014+#ifdef CONFIG_ARM_LPAE
2015+ /* TODO */
2016+#else
2017+ preempt_disable();
2018+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2019+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2020+#endif
2021+ return 0;
2022+}
2023+
2024+static inline unsigned long pax_close_kernel(void) {
2025+#ifdef CONFIG_ARM_LPAE
2026+ /* TODO */
2027+#else
2028+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2029+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2030+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2031+ preempt_enable_no_resched();
2032+#endif
2033+ return 0;
2034+}
2035+#else
2036+static inline unsigned long pax_open_kernel(void) { return 0; }
2037+static inline unsigned long pax_close_kernel(void) { return 0; }
2038+#endif
2039+
2040 /*
2041 * This is the lowest virtual address we can permit any user space
2042 * mapping to be mapped at. This is particularly important for
2043@@ -72,8 +120,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2044 /*
2045 * The pgprot_* and protection_map entries will be fixed up in runtime
2046 * to include the cachable and bufferable bits based on memory policy,
2047- * as well as any architecture dependent bits like global/ASID and SMP
2048- * shared mapping bits.
2049+ * as well as any architecture dependent bits like global/ASID, PXN,
2050+ * and SMP shared mapping bits.
2051 */
2052 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2053
2054@@ -257,7 +305,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2055 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2056 {
2057 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2058- L_PTE_NONE | L_PTE_VALID;
2059+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2060 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2061 return pte;
2062 }
2063diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2064index f3628fb..a0672dd 100644
2065--- a/arch/arm/include/asm/proc-fns.h
2066+++ b/arch/arm/include/asm/proc-fns.h
2067@@ -75,7 +75,7 @@ extern struct processor {
2068 unsigned int suspend_size;
2069 void (*do_suspend)(void *);
2070 void (*do_resume)(void *);
2071-} processor;
2072+} __do_const processor;
2073
2074 #ifndef MULTI_CPU
2075 extern void cpu_proc_init(void);
2076diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2077index ce0dbe7..c085b6f 100644
2078--- a/arch/arm/include/asm/psci.h
2079+++ b/arch/arm/include/asm/psci.h
2080@@ -29,7 +29,7 @@ struct psci_operations {
2081 int (*cpu_off)(struct psci_power_state state);
2082 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2083 int (*migrate)(unsigned long cpuid);
2084-};
2085+} __no_const;
2086
2087 extern struct psci_operations psci_ops;
2088
2089diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2090index d3a22be..3a69ad5 100644
2091--- a/arch/arm/include/asm/smp.h
2092+++ b/arch/arm/include/asm/smp.h
2093@@ -107,7 +107,7 @@ struct smp_operations {
2094 int (*cpu_disable)(unsigned int cpu);
2095 #endif
2096 #endif
2097-};
2098+} __no_const;
2099
2100 /*
2101 * set platform specific SMP operations
2102diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2103index f00b569..aa5bb41 100644
2104--- a/arch/arm/include/asm/thread_info.h
2105+++ b/arch/arm/include/asm/thread_info.h
2106@@ -77,9 +77,9 @@ struct thread_info {
2107 .flags = 0, \
2108 .preempt_count = INIT_PREEMPT_COUNT, \
2109 .addr_limit = KERNEL_DS, \
2110- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2111- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2112- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2113+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2114+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2115+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2116 .restart_block = { \
2117 .fn = do_no_restart_syscall, \
2118 }, \
2119@@ -152,7 +152,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2120 #define TIF_SYSCALL_AUDIT 9
2121 #define TIF_SYSCALL_TRACEPOINT 10
2122 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2123-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2124+/* within 8 bits of TIF_SYSCALL_TRACE
2125+ * to meet flexible second operand requirements
2126+ */
2127+#define TIF_GRSEC_SETXID 12
2128+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2129 #define TIF_USING_IWMMXT 17
2130 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2131 #define TIF_RESTORE_SIGMASK 20
2132@@ -165,10 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2133 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2134 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2135 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2136+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2137
2138 /* Checks for any syscall work in entry-common.S */
2139 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2140- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2141+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2142
2143 /*
2144 * Change these and you break ASM code in entry-common.S
2145diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2146index 7e1f760..de33b13 100644
2147--- a/arch/arm/include/asm/uaccess.h
2148+++ b/arch/arm/include/asm/uaccess.h
2149@@ -18,6 +18,7 @@
2150 #include <asm/domain.h>
2151 #include <asm/unified.h>
2152 #include <asm/compiler.h>
2153+#include <asm/pgtable.h>
2154
2155 #define VERIFY_READ 0
2156 #define VERIFY_WRITE 1
2157@@ -63,11 +64,38 @@ extern int __put_user_bad(void);
2158 static inline void set_fs(mm_segment_t fs)
2159 {
2160 current_thread_info()->addr_limit = fs;
2161- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2162+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2163 }
2164
2165 #define segment_eq(a,b) ((a) == (b))
2166
2167+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2168+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2169+
2170+static inline void pax_open_userland(void)
2171+{
2172+
2173+#ifdef CONFIG_PAX_MEMORY_UDEREF
2174+ if (segment_eq(get_fs(), USER_DS)) {
2175+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2176+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2177+ }
2178+#endif
2179+
2180+}
2181+
2182+static inline void pax_close_userland(void)
2183+{
2184+
2185+#ifdef CONFIG_PAX_MEMORY_UDEREF
2186+ if (segment_eq(get_fs(), USER_DS)) {
2187+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2188+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2189+ }
2190+#endif
2191+
2192+}
2193+
2194 #define __addr_ok(addr) ({ \
2195 unsigned long flag; \
2196 __asm__("cmp %2, %0; movlo %0, #0" \
2197@@ -143,8 +171,12 @@ extern int __get_user_4(void *);
2198
2199 #define get_user(x,p) \
2200 ({ \
2201+ int __e; \
2202 might_fault(); \
2203- __get_user_check(x,p); \
2204+ pax_open_userland(); \
2205+ __e = __get_user_check(x,p); \
2206+ pax_close_userland(); \
2207+ __e; \
2208 })
2209
2210 extern int __put_user_1(void *, unsigned int);
2211@@ -188,8 +220,12 @@ extern int __put_user_8(void *, unsigned long long);
2212
2213 #define put_user(x,p) \
2214 ({ \
2215+ int __e; \
2216 might_fault(); \
2217- __put_user_check(x,p); \
2218+ pax_open_userland(); \
2219+ __e = __put_user_check(x,p); \
2220+ pax_close_userland(); \
2221+ __e; \
2222 })
2223
2224 #else /* CONFIG_MMU */
2225@@ -230,13 +266,17 @@ static inline void set_fs(mm_segment_t fs)
2226 #define __get_user(x,ptr) \
2227 ({ \
2228 long __gu_err = 0; \
2229+ pax_open_userland(); \
2230 __get_user_err((x),(ptr),__gu_err); \
2231+ pax_close_userland(); \
2232 __gu_err; \
2233 })
2234
2235 #define __get_user_error(x,ptr,err) \
2236 ({ \
2237+ pax_open_userland(); \
2238 __get_user_err((x),(ptr),err); \
2239+ pax_close_userland(); \
2240 (void) 0; \
2241 })
2242
2243@@ -312,13 +352,17 @@ do { \
2244 #define __put_user(x,ptr) \
2245 ({ \
2246 long __pu_err = 0; \
2247+ pax_open_userland(); \
2248 __put_user_err((x),(ptr),__pu_err); \
2249+ pax_close_userland(); \
2250 __pu_err; \
2251 })
2252
2253 #define __put_user_error(x,ptr,err) \
2254 ({ \
2255+ pax_open_userland(); \
2256 __put_user_err((x),(ptr),err); \
2257+ pax_close_userland(); \
2258 (void) 0; \
2259 })
2260
2261@@ -418,11 +462,44 @@ do { \
2262
2263
2264 #ifdef CONFIG_MMU
2265-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2266-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2267+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2268+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2269+
2270+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2271+{
2272+ unsigned long ret;
2273+
2274+ check_object_size(to, n, false);
2275+ pax_open_userland();
2276+ ret = ___copy_from_user(to, from, n);
2277+ pax_close_userland();
2278+ return ret;
2279+}
2280+
2281+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2282+{
2283+ unsigned long ret;
2284+
2285+ check_object_size(from, n, true);
2286+ pax_open_userland();
2287+ ret = ___copy_to_user(to, from, n);
2288+ pax_close_userland();
2289+ return ret;
2290+}
2291+
2292 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2293-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2294+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2295 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2296+
2297+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2298+{
2299+ unsigned long ret;
2300+ pax_open_userland();
2301+ ret = ___clear_user(addr, n);
2302+ pax_close_userland();
2303+ return ret;
2304+}
2305+
2306 #else
2307 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2308 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2309@@ -431,6 +508,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2310
2311 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2312 {
2313+ if ((long)n < 0)
2314+ return n;
2315+
2316 if (access_ok(VERIFY_READ, from, n))
2317 n = __copy_from_user(to, from, n);
2318 else /* security hole - plug it */
2319@@ -440,6 +520,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2320
2321 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2322 {
2323+ if ((long)n < 0)
2324+ return n;
2325+
2326 if (access_ok(VERIFY_WRITE, to, n))
2327 n = __copy_to_user(to, from, n);
2328 return n;
2329diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2330index 96ee092..37f1844 100644
2331--- a/arch/arm/include/uapi/asm/ptrace.h
2332+++ b/arch/arm/include/uapi/asm/ptrace.h
2333@@ -73,7 +73,7 @@
2334 * ARMv7 groups of PSR bits
2335 */
2336 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2337-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2338+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2339 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2340 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2341
2342diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2343index 60d3b73..e5a0f22 100644
2344--- a/arch/arm/kernel/armksyms.c
2345+++ b/arch/arm/kernel/armksyms.c
2346@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2347
2348 /* networking */
2349 EXPORT_SYMBOL(csum_partial);
2350-EXPORT_SYMBOL(csum_partial_copy_from_user);
2351+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2352 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2353 EXPORT_SYMBOL(__csum_ipv6_magic);
2354
2355@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2356 #ifdef CONFIG_MMU
2357 EXPORT_SYMBOL(copy_page);
2358
2359-EXPORT_SYMBOL(__copy_from_user);
2360-EXPORT_SYMBOL(__copy_to_user);
2361-EXPORT_SYMBOL(__clear_user);
2362+EXPORT_SYMBOL(___copy_from_user);
2363+EXPORT_SYMBOL(___copy_to_user);
2364+EXPORT_SYMBOL(___clear_user);
2365
2366 EXPORT_SYMBOL(__get_user_1);
2367 EXPORT_SYMBOL(__get_user_2);
2368diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2369index d43c7e5..257c050 100644
2370--- a/arch/arm/kernel/entry-armv.S
2371+++ b/arch/arm/kernel/entry-armv.S
2372@@ -47,6 +47,87 @@
2373 9997:
2374 .endm
2375
2376+ .macro pax_enter_kernel
2377+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2378+ @ make aligned space for saved DACR
2379+ sub sp, sp, #8
2380+ @ save regs
2381+ stmdb sp!, {r1, r2}
2382+ @ read DACR from cpu_domain into r1
2383+ mov r2, sp
2384+ @ assume 8K pages, since we have to split the immediate in two
2385+ bic r2, r2, #(0x1fc0)
2386+ bic r2, r2, #(0x3f)
2387+ ldr r1, [r2, #TI_CPU_DOMAIN]
2388+ @ store old DACR on stack
2389+ str r1, [sp, #8]
2390+#ifdef CONFIG_PAX_KERNEXEC
2391+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2392+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2393+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2394+#endif
2395+#ifdef CONFIG_PAX_MEMORY_UDEREF
2396+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2397+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2398+#endif
2399+ @ write r1 to current_thread_info()->cpu_domain
2400+ str r1, [r2, #TI_CPU_DOMAIN]
2401+ @ write r1 to DACR
2402+ mcr p15, 0, r1, c3, c0, 0
2403+ @ instruction sync
2404+ instr_sync
2405+ @ restore regs
2406+ ldmia sp!, {r1, r2}
2407+#endif
2408+ .endm
2409+
2410+ .macro pax_open_userland
2411+#ifdef CONFIG_PAX_MEMORY_UDEREF
2412+ @ save regs
2413+ stmdb sp!, {r0, r1}
2414+ @ read DACR from cpu_domain into r1
2415+ mov r0, sp
2416+ @ assume 8K pages, since we have to split the immediate in two
2417+ bic r0, r0, #(0x1fc0)
2418+ bic r0, r0, #(0x3f)
2419+ ldr r1, [r0, #TI_CPU_DOMAIN]
2420+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2421+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2422+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2423+ @ write r1 to current_thread_info()->cpu_domain
2424+ str r1, [r0, #TI_CPU_DOMAIN]
2425+ @ write r1 to DACR
2426+ mcr p15, 0, r1, c3, c0, 0
2427+ @ instruction sync
2428+ instr_sync
2429+ @ restore regs
2430+ ldmia sp!, {r0, r1}
2431+#endif
2432+ .endm
2433+
2434+ .macro pax_close_userland
2435+#ifdef CONFIG_PAX_MEMORY_UDEREF
2436+ @ save regs
2437+ stmdb sp!, {r0, r1}
2438+ @ read DACR from cpu_domain into r1
2439+ mov r0, sp
2440+ @ assume 8K pages, since we have to split the immediate in two
2441+ bic r0, r0, #(0x1fc0)
2442+ bic r0, r0, #(0x3f)
2443+ ldr r1, [r0, #TI_CPU_DOMAIN]
2444+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2445+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2446+ @ write r1 to current_thread_info()->cpu_domain
2447+ str r1, [r0, #TI_CPU_DOMAIN]
2448+ @ write r1 to DACR
2449+ mcr p15, 0, r1, c3, c0, 0
2450+ @ instruction sync
2451+ instr_sync
2452+ @ restore regs
2453+ ldmia sp!, {r0, r1}
2454+#endif
2455+ .endm
2456+
2457 .macro pabt_helper
2458 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2459 #ifdef MULTI_PABORT
2460@@ -89,11 +170,15 @@
2461 * Invalid mode handlers
2462 */
2463 .macro inv_entry, reason
2464+
2465+ pax_enter_kernel
2466+
2467 sub sp, sp, #S_FRAME_SIZE
2468 ARM( stmib sp, {r1 - lr} )
2469 THUMB( stmia sp, {r0 - r12} )
2470 THUMB( str sp, [sp, #S_SP] )
2471 THUMB( str lr, [sp, #S_LR] )
2472+
2473 mov r1, #\reason
2474 .endm
2475
2476@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2477 .macro svc_entry, stack_hole=0
2478 UNWIND(.fnstart )
2479 UNWIND(.save {r0 - pc} )
2480+
2481+ pax_enter_kernel
2482+
2483 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2484+
2485 #ifdef CONFIG_THUMB2_KERNEL
2486 SPFIX( str r0, [sp] ) @ temporarily saved
2487 SPFIX( mov r0, sp )
2488@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2489 ldmia r0, {r3 - r5}
2490 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2491 mov r6, #-1 @ "" "" "" ""
2492+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2493+ @ offset sp by 8 as done in pax_enter_kernel
2494+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2495+#else
2496 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2497+#endif
2498 SPFIX( addeq r2, r2, #4 )
2499 str r3, [sp, #-4]! @ save the "real" r0 copied
2500 @ from the exception stack
2501@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2502 .macro usr_entry
2503 UNWIND(.fnstart )
2504 UNWIND(.cantunwind ) @ don't unwind the user space
2505+
2506+ pax_enter_kernel_user
2507+
2508 sub sp, sp, #S_FRAME_SIZE
2509 ARM( stmib sp, {r1 - r12} )
2510 THUMB( stmia sp, {r0 - r12} )
2511@@ -357,7 +454,8 @@ ENDPROC(__pabt_svc)
2512 .endm
2513
2514 .macro kuser_cmpxchg_check
2515-#if !defined(CONFIG_CPU_32v6K) && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
2516+#if !defined(CONFIG_CPU_32v6K) && defined(CONFIG_KUSER_HELPERS) && \
2517+ !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
2518 #ifndef CONFIG_MMU
2519 #warning "NPTL on non MMU needs fixing"
2520 #else
2521@@ -414,7 +512,9 @@ __und_usr:
2522 tst r3, #PSR_T_BIT @ Thumb mode?
2523 bne __und_usr_thumb
2524 sub r4, r2, #4 @ ARM instr at LR - 4
2525+ pax_open_userland
2526 1: ldrt r0, [r4]
2527+ pax_close_userland
2528 #ifdef CONFIG_CPU_ENDIAN_BE8
2529 rev r0, r0 @ little endian instruction
2530 #endif
2531@@ -449,10 +549,14 @@ __und_usr_thumb:
2532 */
2533 .arch armv6t2
2534 #endif
2535+ pax_open_userland
2536 2: ldrht r5, [r4]
2537+ pax_close_userland
2538 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2539 blo __und_usr_fault_16 @ 16bit undefined instruction
2540+ pax_open_userland
2541 3: ldrht r0, [r2]
2542+ pax_close_userland
2543 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2544 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2545 orr r0, r0, r5, lsl #16
2546@@ -481,7 +585,8 @@ ENDPROC(__und_usr)
2547 */
2548 .pushsection .fixup, "ax"
2549 .align 2
2550-4: mov pc, r9
2551+4: pax_close_userland
2552+ mov pc, r9
2553 .popsection
2554 .pushsection __ex_table,"a"
2555 .long 1b, 4b
2556@@ -690,7 +795,7 @@ ENTRY(__switch_to)
2557 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2558 THUMB( str sp, [ip], #4 )
2559 THUMB( str lr, [ip], #4 )
2560-#ifdef CONFIG_CPU_USE_DOMAINS
2561+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2562 ldr r6, [r2, #TI_CPU_DOMAIN]
2563 #endif
2564 set_tls r3, r4, r5
2565@@ -699,7 +804,7 @@ ENTRY(__switch_to)
2566 ldr r8, =__stack_chk_guard
2567 ldr r7, [r7, #TSK_STACK_CANARY]
2568 #endif
2569-#ifdef CONFIG_CPU_USE_DOMAINS
2570+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2571 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2572 #endif
2573 mov r5, r0
2574diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2575index bc5bc0a..d0998ca 100644
2576--- a/arch/arm/kernel/entry-common.S
2577+++ b/arch/arm/kernel/entry-common.S
2578@@ -10,18 +10,46 @@
2579
2580 #include <asm/unistd.h>
2581 #include <asm/ftrace.h>
2582+#include <asm/domain.h>
2583 #include <asm/unwind.h>
2584
2585+#include "entry-header.S"
2586+
2587 #ifdef CONFIG_NEED_RET_TO_USER
2588 #include <mach/entry-macro.S>
2589 #else
2590 .macro arch_ret_to_user, tmp1, tmp2
2591+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2592+ @ save regs
2593+ stmdb sp!, {r1, r2}
2594+ @ read DACR from cpu_domain into r1
2595+ mov r2, sp
2596+ @ assume 8K pages, since we have to split the immediate in two
2597+ bic r2, r2, #(0x1fc0)
2598+ bic r2, r2, #(0x3f)
2599+ ldr r1, [r2, #TI_CPU_DOMAIN]
2600+#ifdef CONFIG_PAX_KERNEXEC
2601+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2602+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2603+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2604+#endif
2605+#ifdef CONFIG_PAX_MEMORY_UDEREF
2606+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2607+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2608+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2609+#endif
2610+ @ write r1 to current_thread_info()->cpu_domain
2611+ str r1, [r2, #TI_CPU_DOMAIN]
2612+ @ write r1 to DACR
2613+ mcr p15, 0, r1, c3, c0, 0
2614+ @ instruction sync
2615+ instr_sync
2616+ @ restore regs
2617+ ldmia sp!, {r1, r2}
2618+#endif
2619 .endm
2620 #endif
2621
2622-#include "entry-header.S"
2623-
2624-
2625 .align 5
2626 /*
2627 * This is the fast syscall return path. We do as little as
2628@@ -350,6 +378,7 @@ ENDPROC(ftrace_stub)
2629
2630 .align 5
2631 ENTRY(vector_swi)
2632+
2633 sub sp, sp, #S_FRAME_SIZE
2634 stmia sp, {r0 - r12} @ Calling r0 - r12
2635 ARM( add r8, sp, #S_PC )
2636@@ -399,6 +428,12 @@ ENTRY(vector_swi)
2637 ldr scno, [lr, #-4] @ get SWI instruction
2638 #endif
2639
2640+ /*
2641+ * do this here to avoid a performance hit of wrapping the code above
2642+ * that directly dereferences userland to parse the SWI instruction
2643+ */
2644+ pax_enter_kernel_user
2645+
2646 #ifdef CONFIG_ALIGNMENT_TRAP
2647 ldr ip, __cr_alignment
2648 ldr ip, [ip]
2649diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2650index 160f337..db67ee4 100644
2651--- a/arch/arm/kernel/entry-header.S
2652+++ b/arch/arm/kernel/entry-header.S
2653@@ -73,6 +73,60 @@
2654 msr cpsr_c, \rtemp @ switch back to the SVC mode
2655 .endm
2656
2657+ .macro pax_enter_kernel_user
2658+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2659+ @ save regs
2660+ stmdb sp!, {r0, r1}
2661+ @ read DACR from cpu_domain into r1
2662+ mov r0, sp
2663+ @ assume 8K pages, since we have to split the immediate in two
2664+ bic r0, r0, #(0x1fc0)
2665+ bic r0, r0, #(0x3f)
2666+ ldr r1, [r0, #TI_CPU_DOMAIN]
2667+#ifdef CONFIG_PAX_MEMORY_UDEREF
2668+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2669+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2670+#endif
2671+#ifdef CONFIG_PAX_KERNEXEC
2672+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2673+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2674+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2675+#endif
2676+ @ write r1 to current_thread_info()->cpu_domain
2677+ str r1, [r0, #TI_CPU_DOMAIN]
2678+ @ write r1 to DACR
2679+ mcr p15, 0, r1, c3, c0, 0
2680+ @ instruction sync
2681+ instr_sync
2682+ @ restore regs
2683+ ldmia sp!, {r0, r1}
2684+#endif
2685+ .endm
2686+
2687+ .macro pax_exit_kernel
2688+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2689+ @ save regs
2690+ stmdb sp!, {r0, r1}
2691+ @ read old DACR from stack into r1
2692+ ldr r1, [sp, #(8 + S_SP)]
2693+ sub r1, r1, #8
2694+ ldr r1, [r1]
2695+
2696+ @ write r1 to current_thread_info()->cpu_domain
2697+ mov r0, sp
2698+ @ assume 8K pages, since we have to split the immediate in two
2699+ bic r0, r0, #(0x1fc0)
2700+ bic r0, r0, #(0x3f)
2701+ str r1, [r0, #TI_CPU_DOMAIN]
2702+ @ write r1 to DACR
2703+ mcr p15, 0, r1, c3, c0, 0
2704+ @ instruction sync
2705+ instr_sync
2706+ @ restore regs
2707+ ldmia sp!, {r0, r1}
2708+#endif
2709+ .endm
2710+
2711 #ifndef CONFIG_THUMB2_KERNEL
2712 .macro svc_exit, rpsr, irq = 0
2713 .if \irq != 0
2714@@ -92,6 +146,9 @@
2715 blne trace_hardirqs_off
2716 #endif
2717 .endif
2718+
2719+ pax_exit_kernel
2720+
2721 msr spsr_cxsf, \rpsr
2722 #if defined(CONFIG_CPU_V6)
2723 ldr r0, [sp]
2724@@ -155,6 +212,9 @@
2725 blne trace_hardirqs_off
2726 #endif
2727 .endif
2728+
2729+ pax_exit_kernel
2730+
2731 ldr lr, [sp, #S_SP] @ top of the stack
2732 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2733 clrex @ clear the exclusive monitor
2734diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2735index 25442f4..d4948fc 100644
2736--- a/arch/arm/kernel/fiq.c
2737+++ b/arch/arm/kernel/fiq.c
2738@@ -84,17 +84,16 @@ int show_fiq_list(struct seq_file *p, int prec)
2739
2740 void set_fiq_handler(void *start, unsigned int length)
2741 {
2742-#if defined(CONFIG_CPU_USE_DOMAINS)
2743- void *base = (void *)0xffff0000;
2744-#else
2745 void *base = vectors_page;
2746-#endif
2747 unsigned offset = FIQ_OFFSET;
2748
2749+ pax_open_kernel();
2750 memcpy(base + offset, start, length);
2751+ pax_close_kernel();
2752+
2753+ if (!cache_is_vipt_nonaliasing())
2754+ flush_icache_range(base + offset, offset + length);
2755 flush_icache_range(0xffff0000 + offset, 0xffff0000 + offset + length);
2756- if (!vectors_high())
2757- flush_icache_range(offset, offset + length);
2758 }
2759
2760 int claim_fiq(struct fiq_handler *f)
2761diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2762index 8bac553..caee108 100644
2763--- a/arch/arm/kernel/head.S
2764+++ b/arch/arm/kernel/head.S
2765@@ -52,7 +52,9 @@
2766 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2767
2768 .macro pgtbl, rd, phys
2769- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2770+ mov \rd, #TEXT_OFFSET
2771+ sub \rd, #PG_DIR_SIZE
2772+ add \rd, \rd, \phys
2773 .endm
2774
2775 /*
2776@@ -434,7 +436,7 @@ __enable_mmu:
2777 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2778 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2779 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2780- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2781+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2782 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2783 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2784 #endif
2785diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2786index 1fd749e..47adb08 100644
2787--- a/arch/arm/kernel/hw_breakpoint.c
2788+++ b/arch/arm/kernel/hw_breakpoint.c
2789@@ -1029,7 +1029,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2790 return NOTIFY_OK;
2791 }
2792
2793-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2794+static struct notifier_block dbg_reset_nb = {
2795 .notifier_call = dbg_reset_notify,
2796 };
2797
2798diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2799index 1e9be5d..03edbc2 100644
2800--- a/arch/arm/kernel/module.c
2801+++ b/arch/arm/kernel/module.c
2802@@ -37,12 +37,37 @@
2803 #endif
2804
2805 #ifdef CONFIG_MMU
2806-void *module_alloc(unsigned long size)
2807+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2808 {
2809+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2810+ return NULL;
2811 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2812- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2813+ GFP_KERNEL, prot, -1,
2814 __builtin_return_address(0));
2815 }
2816+
2817+void *module_alloc(unsigned long size)
2818+{
2819+
2820+#ifdef CONFIG_PAX_KERNEXEC
2821+ return __module_alloc(size, PAGE_KERNEL);
2822+#else
2823+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2824+#endif
2825+
2826+}
2827+
2828+#ifdef CONFIG_PAX_KERNEXEC
2829+void module_free_exec(struct module *mod, void *module_region)
2830+{
2831+ module_free(mod, module_region);
2832+}
2833+
2834+void *module_alloc_exec(unsigned long size)
2835+{
2836+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2837+}
2838+#endif
2839 #endif
2840
2841 int
2842diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2843index 07314af..c46655c 100644
2844--- a/arch/arm/kernel/patch.c
2845+++ b/arch/arm/kernel/patch.c
2846@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2847 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2848 int size;
2849
2850+ pax_open_kernel();
2851 if (thumb2 && __opcode_is_thumb16(insn)) {
2852 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2853 size = sizeof(u16);
2854@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2855 *(u32 *)addr = insn;
2856 size = sizeof(u32);
2857 }
2858+ pax_close_kernel();
2859
2860 flush_icache_range((uintptr_t)(addr),
2861 (uintptr_t)(addr) + size);
2862diff --git a/arch/arm/kernel/perf_event.c b/arch/arm/kernel/perf_event.c
2863index e19edc6..e186ee1 100644
2864--- a/arch/arm/kernel/perf_event.c
2865+++ b/arch/arm/kernel/perf_event.c
2866@@ -56,7 +56,7 @@ armpmu_map_hw_event(const unsigned (*event_map)[PERF_COUNT_HW_MAX], u64 config)
2867 int mapping;
2868
2869 if (config >= PERF_COUNT_HW_MAX)
2870- return -ENOENT;
2871+ return -EINVAL;
2872
2873 mapping = (*event_map)[config];
2874 return mapping == HW_OP_UNSUPPORTED ? -ENOENT : mapping;
2875diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2876index 1f2740e..b36e225 100644
2877--- a/arch/arm/kernel/perf_event_cpu.c
2878+++ b/arch/arm/kernel/perf_event_cpu.c
2879@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2880 return NOTIFY_OK;
2881 }
2882
2883-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2884+static struct notifier_block cpu_pmu_hotplug_notifier = {
2885 .notifier_call = cpu_pmu_notify,
2886 };
2887
2888diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2889index 5bc2615..dcd439f 100644
2890--- a/arch/arm/kernel/process.c
2891+++ b/arch/arm/kernel/process.c
2892@@ -223,6 +223,7 @@ void machine_power_off(void)
2893
2894 if (pm_power_off)
2895 pm_power_off();
2896+ BUG();
2897 }
2898
2899 /*
2900@@ -236,7 +237,7 @@ void machine_power_off(void)
2901 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2902 * to use. Implementing such co-ordination would be essentially impossible.
2903 */
2904-void machine_restart(char *cmd)
2905+__noreturn void machine_restart(char *cmd)
2906 {
2907 smp_send_stop();
2908
2909@@ -258,8 +259,8 @@ void __show_regs(struct pt_regs *regs)
2910
2911 show_regs_print_info(KERN_DEFAULT);
2912
2913- print_symbol("PC is at %s\n", instruction_pointer(regs));
2914- print_symbol("LR is at %s\n", regs->ARM_lr);
2915+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2916+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2917 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2918 "sp : %08lx ip : %08lx fp : %08lx\n",
2919 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2920@@ -426,12 +427,6 @@ unsigned long get_wchan(struct task_struct *p)
2921 return 0;
2922 }
2923
2924-unsigned long arch_randomize_brk(struct mm_struct *mm)
2925-{
2926- unsigned long range_end = mm->brk + 0x02000000;
2927- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2928-}
2929-
2930 #ifdef CONFIG_MMU
2931 #ifdef CONFIG_KUSER_HELPERS
2932 /*
2933@@ -447,7 +442,7 @@ static struct vm_area_struct gate_vma = {
2934
2935 static int __init gate_vma_init(void)
2936 {
2937- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2938+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2939 return 0;
2940 }
2941 arch_initcall(gate_vma_init);
2942@@ -466,48 +461,23 @@ int in_gate_area_no_mm(unsigned long addr)
2943 {
2944 return in_gate_area(NULL, addr);
2945 }
2946-#define is_gate_vma(vma) ((vma) = &gate_vma)
2947+#define is_gate_vma(vma) ((vma) == &gate_vma)
2948 #else
2949 #define is_gate_vma(vma) 0
2950 #endif
2951
2952 const char *arch_vma_name(struct vm_area_struct *vma)
2953 {
2954- return is_gate_vma(vma) ? "[vectors]" :
2955- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2956- "[sigpage]" : NULL;
2957+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2958 }
2959
2960-static struct page *signal_page;
2961-extern struct page *get_signal_page(void);
2962-
2963 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2964 {
2965 struct mm_struct *mm = current->mm;
2966- unsigned long addr;
2967- int ret;
2968-
2969- if (!signal_page)
2970- signal_page = get_signal_page();
2971- if (!signal_page)
2972- return -ENOMEM;
2973
2974 down_write(&mm->mmap_sem);
2975- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2976- if (IS_ERR_VALUE(addr)) {
2977- ret = addr;
2978- goto up_fail;
2979- }
2980-
2981- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2982- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2983- &signal_page);
2984-
2985- if (ret == 0)
2986- mm->context.sigpage = addr;
2987-
2988- up_fail:
2989+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2990 up_write(&mm->mmap_sem);
2991- return ret;
2992+ return 0;
2993 }
2994 #endif
2995diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2996index 3653164..d83e55d 100644
2997--- a/arch/arm/kernel/psci.c
2998+++ b/arch/arm/kernel/psci.c
2999@@ -24,7 +24,7 @@
3000 #include <asm/opcodes-virt.h>
3001 #include <asm/psci.h>
3002
3003-struct psci_operations psci_ops;
3004+struct psci_operations psci_ops __read_only;
3005
3006 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3007
3008diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3009index 03deeff..741ce88 100644
3010--- a/arch/arm/kernel/ptrace.c
3011+++ b/arch/arm/kernel/ptrace.c
3012@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
3013 return current_thread_info()->syscall;
3014 }
3015
3016+#ifdef CONFIG_GRKERNSEC_SETXID
3017+extern void gr_delayed_cred_worker(void);
3018+#endif
3019+
3020 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3021 {
3022 current_thread_info()->syscall = scno;
3023
3024+#ifdef CONFIG_GRKERNSEC_SETXID
3025+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3026+ gr_delayed_cred_worker();
3027+#endif
3028+
3029 /* Do the secure computing check first; failures should be fast. */
3030 if (secure_computing(scno) == -1)
3031 return -1;
3032diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3033index b4b1d39..efdc9be 100644
3034--- a/arch/arm/kernel/setup.c
3035+++ b/arch/arm/kernel/setup.c
3036@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
3037 unsigned int elf_hwcap __read_mostly;
3038 EXPORT_SYMBOL(elf_hwcap);
3039
3040+pteval_t __supported_pte_mask __read_only;
3041+pmdval_t __supported_pmd_mask __read_only;
3042
3043 #ifdef MULTI_CPU
3044-struct processor processor __read_mostly;
3045+struct processor processor;
3046 #endif
3047 #ifdef MULTI_TLB
3048-struct cpu_tlb_fns cpu_tlb __read_mostly;
3049+struct cpu_tlb_fns cpu_tlb __read_only;
3050 #endif
3051 #ifdef MULTI_USER
3052-struct cpu_user_fns cpu_user __read_mostly;
3053+struct cpu_user_fns cpu_user __read_only;
3054 #endif
3055 #ifdef MULTI_CACHE
3056-struct cpu_cache_fns cpu_cache __read_mostly;
3057+struct cpu_cache_fns cpu_cache __read_only;
3058 #endif
3059 #ifdef CONFIG_OUTER_CACHE
3060-struct outer_cache_fns outer_cache __read_mostly;
3061+struct outer_cache_fns outer_cache __read_only;
3062 EXPORT_SYMBOL(outer_cache);
3063 #endif
3064
3065@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
3066 asm("mrc p15, 0, %0, c0, c1, 4"
3067 : "=r" (mmfr0));
3068 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3069- (mmfr0 & 0x000000f0) >= 0x00000030)
3070+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3071 cpu_arch = CPU_ARCH_ARMv7;
3072- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3073+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3074+ __supported_pte_mask |= L_PTE_PXN;
3075+ __supported_pmd_mask |= PMD_PXNTABLE;
3076+ }
3077+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3078 (mmfr0 & 0x000000f0) == 0x00000020)
3079 cpu_arch = CPU_ARCH_ARMv6;
3080 else
3081@@ -479,7 +485,7 @@ static void __init setup_processor(void)
3082 __cpu_architecture = __get_cpu_architecture();
3083
3084 #ifdef MULTI_CPU
3085- processor = *list->proc;
3086+ memcpy((void *)&processor, list->proc, sizeof processor);
3087 #endif
3088 #ifdef MULTI_TLB
3089 cpu_tlb = *list->tlb;
3090diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3091index 5a42c12..a2bb7c6 100644
3092--- a/arch/arm/kernel/signal.c
3093+++ b/arch/arm/kernel/signal.c
3094@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3095 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3096 };
3097
3098-static unsigned long signal_return_offset;
3099-
3100 #ifdef CONFIG_CRUNCH
3101 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3102 {
3103@@ -406,8 +404,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3104 * except when the MPU has protected the vectors
3105 * page from PL0
3106 */
3107- retcode = mm->context.sigpage + signal_return_offset +
3108- (idx << 2) + thumb;
3109+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3110 } else
3111 #endif
3112 {
3113@@ -611,33 +608,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3114 } while (thread_flags & _TIF_WORK_MASK);
3115 return 0;
3116 }
3117-
3118-struct page *get_signal_page(void)
3119-{
3120- unsigned long ptr;
3121- unsigned offset;
3122- struct page *page;
3123- void *addr;
3124-
3125- page = alloc_pages(GFP_KERNEL, 0);
3126-
3127- if (!page)
3128- return NULL;
3129-
3130- addr = page_address(page);
3131-
3132- /* Give the signal return code some randomness */
3133- offset = 0x200 + (get_random_int() & 0x7fc);
3134- signal_return_offset = offset;
3135-
3136- /*
3137- * Copy signal return handlers into the vector page, and
3138- * set sigreturn to be a pointer to these.
3139- */
3140- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3141-
3142- ptr = (unsigned long)addr + offset;
3143- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3144-
3145- return page;
3146-}
3147diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3148index 5919eb4..b5d6dfe 100644
3149--- a/arch/arm/kernel/smp.c
3150+++ b/arch/arm/kernel/smp.c
3151@@ -70,7 +70,7 @@ enum ipi_msg_type {
3152
3153 static DECLARE_COMPLETION(cpu_running);
3154
3155-static struct smp_operations smp_ops;
3156+static struct smp_operations smp_ops __read_only;
3157
3158 void __init smp_set_ops(struct smp_operations *ops)
3159 {
3160diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3161index 6b9567e..b8af2d6 100644
3162--- a/arch/arm/kernel/traps.c
3163+++ b/arch/arm/kernel/traps.c
3164@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3165 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3166 {
3167 #ifdef CONFIG_KALLSYMS
3168- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3169+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3170 #else
3171 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3172 #endif
3173@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3174 static int die_owner = -1;
3175 static unsigned int die_nest_count;
3176
3177+extern void gr_handle_kernel_exploit(void);
3178+
3179 static unsigned long oops_begin(void)
3180 {
3181 int cpu;
3182@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3183 panic("Fatal exception in interrupt");
3184 if (panic_on_oops)
3185 panic("Fatal exception");
3186+
3187+ gr_handle_kernel_exploit();
3188+
3189 if (signr)
3190 do_exit(signr);
3191 }
3192@@ -592,7 +597,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3193 * The user helper at 0xffff0fe0 must be used instead.
3194 * (see entry-armv.S for details)
3195 */
3196+ pax_open_kernel();
3197 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3198+ pax_close_kernel();
3199 }
3200 return 0;
3201
3202@@ -848,5 +855,9 @@ void __init early_trap_init(void *vectors_base)
3203 kuser_init(vectors_base);
3204
3205 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3206- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3207+
3208+#ifndef CONFIG_PAX_MEMORY_UDEREF
3209+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3210+#endif
3211+
3212 }
3213diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3214index 33f2ea3..0b91824 100644
3215--- a/arch/arm/kernel/vmlinux.lds.S
3216+++ b/arch/arm/kernel/vmlinux.lds.S
3217@@ -8,7 +8,11 @@
3218 #include <asm/thread_info.h>
3219 #include <asm/memory.h>
3220 #include <asm/page.h>
3221-
3222+
3223+#ifdef CONFIG_PAX_KERNEXEC
3224+#include <asm/pgtable.h>
3225+#endif
3226+
3227 #define PROC_INFO \
3228 . = ALIGN(4); \
3229 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3230@@ -94,6 +98,11 @@ SECTIONS
3231 _text = .;
3232 HEAD_TEXT
3233 }
3234+
3235+#ifdef CONFIG_PAX_KERNEXEC
3236+ . = ALIGN(1<<SECTION_SHIFT);
3237+#endif
3238+
3239 .text : { /* Real text segment */
3240 _stext = .; /* Text and read-only data */
3241 __exception_text_start = .;
3242@@ -116,6 +125,8 @@ SECTIONS
3243 ARM_CPU_KEEP(PROC_INFO)
3244 }
3245
3246+ _etext = .; /* End of text section */
3247+
3248 RO_DATA(PAGE_SIZE)
3249
3250 . = ALIGN(4);
3251@@ -146,7 +157,9 @@ SECTIONS
3252
3253 NOTES
3254
3255- _etext = .; /* End of text and rodata section */
3256+#ifdef CONFIG_PAX_KERNEXEC
3257+ . = ALIGN(1<<SECTION_SHIFT);
3258+#endif
3259
3260 #ifndef CONFIG_XIP_KERNEL
3261 . = ALIGN(PAGE_SIZE);
3262@@ -224,6 +237,11 @@ SECTIONS
3263 . = PAGE_OFFSET + TEXT_OFFSET;
3264 #else
3265 __init_end = .;
3266+
3267+#ifdef CONFIG_PAX_KERNEXEC
3268+ . = ALIGN(1<<SECTION_SHIFT);
3269+#endif
3270+
3271 . = ALIGN(THREAD_SIZE);
3272 __data_loc = .;
3273 #endif
3274diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3275index ef1703b..46b77f3 100644
3276--- a/arch/arm/kvm/arm.c
3277+++ b/arch/arm/kvm/arm.c
3278@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3279 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3280
3281 /* The VMID used in the VTTBR */
3282-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3283+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3284 static u8 kvm_next_vmid;
3285 static DEFINE_SPINLOCK(kvm_vmid_lock);
3286
3287@@ -392,7 +392,7 @@ void force_vm_exit(const cpumask_t *mask)
3288 */
3289 static bool need_new_vmid_gen(struct kvm *kvm)
3290 {
3291- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3292+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3293 }
3294
3295 /**
3296@@ -425,7 +425,7 @@ static void update_vttbr(struct kvm *kvm)
3297
3298 /* First user of a new VMID generation? */
3299 if (unlikely(kvm_next_vmid == 0)) {
3300- atomic64_inc(&kvm_vmid_gen);
3301+ atomic64_inc_unchecked(&kvm_vmid_gen);
3302 kvm_next_vmid = 1;
3303
3304 /*
3305@@ -442,7 +442,7 @@ static void update_vttbr(struct kvm *kvm)
3306 kvm_call_hyp(__kvm_flush_vm_context);
3307 }
3308
3309- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3310+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3311 kvm->arch.vmid = kvm_next_vmid;
3312 kvm_next_vmid++;
3313
3314diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3315index 14a0d98..7771a7d 100644
3316--- a/arch/arm/lib/clear_user.S
3317+++ b/arch/arm/lib/clear_user.S
3318@@ -12,14 +12,14 @@
3319
3320 .text
3321
3322-/* Prototype: int __clear_user(void *addr, size_t sz)
3323+/* Prototype: int ___clear_user(void *addr, size_t sz)
3324 * Purpose : clear some user memory
3325 * Params : addr - user memory address to clear
3326 * : sz - number of bytes to clear
3327 * Returns : number of bytes NOT cleared
3328 */
3329 ENTRY(__clear_user_std)
3330-WEAK(__clear_user)
3331+WEAK(___clear_user)
3332 stmfd sp!, {r1, lr}
3333 mov r2, #0
3334 cmp r1, #4
3335@@ -44,7 +44,7 @@ WEAK(__clear_user)
3336 USER( strnebt r2, [r0])
3337 mov r0, #0
3338 ldmfd sp!, {r1, pc}
3339-ENDPROC(__clear_user)
3340+ENDPROC(___clear_user)
3341 ENDPROC(__clear_user_std)
3342
3343 .pushsection .fixup,"ax"
3344diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3345index 66a477a..bee61d3 100644
3346--- a/arch/arm/lib/copy_from_user.S
3347+++ b/arch/arm/lib/copy_from_user.S
3348@@ -16,7 +16,7 @@
3349 /*
3350 * Prototype:
3351 *
3352- * size_t __copy_from_user(void *to, const void *from, size_t n)
3353+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3354 *
3355 * Purpose:
3356 *
3357@@ -84,11 +84,11 @@
3358
3359 .text
3360
3361-ENTRY(__copy_from_user)
3362+ENTRY(___copy_from_user)
3363
3364 #include "copy_template.S"
3365
3366-ENDPROC(__copy_from_user)
3367+ENDPROC(___copy_from_user)
3368
3369 .pushsection .fixup,"ax"
3370 .align 0
3371diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3372index 6ee2f67..d1cce76 100644
3373--- a/arch/arm/lib/copy_page.S
3374+++ b/arch/arm/lib/copy_page.S
3375@@ -10,6 +10,7 @@
3376 * ASM optimised string functions
3377 */
3378 #include <linux/linkage.h>
3379+#include <linux/const.h>
3380 #include <asm/assembler.h>
3381 #include <asm/asm-offsets.h>
3382 #include <asm/cache.h>
3383diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3384index d066df6..df28194 100644
3385--- a/arch/arm/lib/copy_to_user.S
3386+++ b/arch/arm/lib/copy_to_user.S
3387@@ -16,7 +16,7 @@
3388 /*
3389 * Prototype:
3390 *
3391- * size_t __copy_to_user(void *to, const void *from, size_t n)
3392+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3393 *
3394 * Purpose:
3395 *
3396@@ -88,11 +88,11 @@
3397 .text
3398
3399 ENTRY(__copy_to_user_std)
3400-WEAK(__copy_to_user)
3401+WEAK(___copy_to_user)
3402
3403 #include "copy_template.S"
3404
3405-ENDPROC(__copy_to_user)
3406+ENDPROC(___copy_to_user)
3407 ENDPROC(__copy_to_user_std)
3408
3409 .pushsection .fixup,"ax"
3410diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3411index 7d08b43..f7ca7ea 100644
3412--- a/arch/arm/lib/csumpartialcopyuser.S
3413+++ b/arch/arm/lib/csumpartialcopyuser.S
3414@@ -57,8 +57,8 @@
3415 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3416 */
3417
3418-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3419-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3420+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3421+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3422
3423 #include "csumpartialcopygeneric.S"
3424
3425diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3426index 64dbfa5..84a3fd9 100644
3427--- a/arch/arm/lib/delay.c
3428+++ b/arch/arm/lib/delay.c
3429@@ -28,7 +28,7 @@
3430 /*
3431 * Default to the loop-based delay implementation.
3432 */
3433-struct arm_delay_ops arm_delay_ops = {
3434+struct arm_delay_ops arm_delay_ops __read_only = {
3435 .delay = __loop_delay,
3436 .const_udelay = __loop_const_udelay,
3437 .udelay = __loop_udelay,
3438diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3439index 025f742..8432b08 100644
3440--- a/arch/arm/lib/uaccess_with_memcpy.c
3441+++ b/arch/arm/lib/uaccess_with_memcpy.c
3442@@ -104,7 +104,7 @@ out:
3443 }
3444
3445 unsigned long
3446-__copy_to_user(void __user *to, const void *from, unsigned long n)
3447+___copy_to_user(void __user *to, const void *from, unsigned long n)
3448 {
3449 /*
3450 * This test is stubbed out of the main function above to keep
3451diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3452index f389228..592ef66 100644
3453--- a/arch/arm/mach-kirkwood/common.c
3454+++ b/arch/arm/mach-kirkwood/common.c
3455@@ -149,7 +149,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3456 clk_gate_ops.disable(hw);
3457 }
3458
3459-static struct clk_ops clk_gate_fn_ops;
3460+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3461+{
3462+ return clk_gate_ops.is_enabled(hw);
3463+}
3464+
3465+static struct clk_ops clk_gate_fn_ops = {
3466+ .enable = clk_gate_fn_enable,
3467+ .disable = clk_gate_fn_disable,
3468+ .is_enabled = clk_gate_fn_is_enabled,
3469+};
3470
3471 static struct clk __init *clk_register_gate_fn(struct device *dev,
3472 const char *name,
3473@@ -183,14 +192,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3474 gate_fn->fn_en = fn_en;
3475 gate_fn->fn_dis = fn_dis;
3476
3477- /* ops is the gate ops, but with our enable/disable functions */
3478- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3479- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3480- clk_gate_fn_ops = clk_gate_ops;
3481- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3482- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3483- }
3484-
3485 clk = clk_register(dev, &gate_fn->gate.hw);
3486
3487 if (IS_ERR(clk))
3488diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3489index f6eeb87..cc90868 100644
3490--- a/arch/arm/mach-omap2/board-n8x0.c
3491+++ b/arch/arm/mach-omap2/board-n8x0.c
3492@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3493 }
3494 #endif
3495
3496-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3497+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3498 .late_init = n8x0_menelaus_late_init,
3499 };
3500
3501diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3502index 6c4da12..d9ca72d 100644
3503--- a/arch/arm/mach-omap2/gpmc.c
3504+++ b/arch/arm/mach-omap2/gpmc.c
3505@@ -147,7 +147,6 @@ struct omap3_gpmc_regs {
3506 };
3507
3508 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3509-static struct irq_chip gpmc_irq_chip;
3510 static unsigned gpmc_irq_start;
3511
3512 static struct resource gpmc_mem_root;
3513@@ -711,6 +710,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3514
3515 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3516
3517+static struct irq_chip gpmc_irq_chip = {
3518+ .name = "gpmc",
3519+ .irq_startup = gpmc_irq_noop_ret,
3520+ .irq_enable = gpmc_irq_enable,
3521+ .irq_disable = gpmc_irq_disable,
3522+ .irq_shutdown = gpmc_irq_noop,
3523+ .irq_ack = gpmc_irq_noop,
3524+ .irq_mask = gpmc_irq_noop,
3525+ .irq_unmask = gpmc_irq_noop,
3526+
3527+};
3528+
3529 static int gpmc_setup_irq(void)
3530 {
3531 int i;
3532@@ -725,15 +736,6 @@ static int gpmc_setup_irq(void)
3533 return gpmc_irq_start;
3534 }
3535
3536- gpmc_irq_chip.name = "gpmc";
3537- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3538- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3539- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3540- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3541- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3542- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3543- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3544-
3545 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3546 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3547
3548diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3549index f8bb3b9..831e7b8 100644
3550--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3551+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3552@@ -339,7 +339,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3553 return NOTIFY_OK;
3554 }
3555
3556-static struct notifier_block __refdata irq_hotplug_notifier = {
3557+static struct notifier_block irq_hotplug_notifier = {
3558 .notifier_call = irq_cpu_hotplug_notify,
3559 };
3560
3561diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3562index e6d2307..d057195 100644
3563--- a/arch/arm/mach-omap2/omap_device.c
3564+++ b/arch/arm/mach-omap2/omap_device.c
3565@@ -499,7 +499,7 @@ void omap_device_delete(struct omap_device *od)
3566 struct platform_device __init *omap_device_build(const char *pdev_name,
3567 int pdev_id,
3568 struct omap_hwmod *oh,
3569- void *pdata, int pdata_len)
3570+ const void *pdata, int pdata_len)
3571 {
3572 struct omap_hwmod *ohs[] = { oh };
3573
3574@@ -527,7 +527,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3575 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3576 int pdev_id,
3577 struct omap_hwmod **ohs,
3578- int oh_cnt, void *pdata,
3579+ int oh_cnt, const void *pdata,
3580 int pdata_len)
3581 {
3582 int ret = -ENOMEM;
3583diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3584index 044c31d..2ee0861 100644
3585--- a/arch/arm/mach-omap2/omap_device.h
3586+++ b/arch/arm/mach-omap2/omap_device.h
3587@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3588 /* Core code interface */
3589
3590 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3591- struct omap_hwmod *oh, void *pdata,
3592+ struct omap_hwmod *oh, const void *pdata,
3593 int pdata_len);
3594
3595 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3596 struct omap_hwmod **oh, int oh_cnt,
3597- void *pdata, int pdata_len);
3598+ const void *pdata, int pdata_len);
3599
3600 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3601 struct omap_hwmod **ohs, int oh_cnt);
3602diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3603index 7341eff..fd75e34 100644
3604--- a/arch/arm/mach-omap2/omap_hwmod.c
3605+++ b/arch/arm/mach-omap2/omap_hwmod.c
3606@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3607 int (*init_clkdm)(struct omap_hwmod *oh);
3608 void (*update_context_lost)(struct omap_hwmod *oh);
3609 int (*get_context_lost)(struct omap_hwmod *oh);
3610-};
3611+} __no_const;
3612
3613 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3614-static struct omap_hwmod_soc_ops soc_ops;
3615+static struct omap_hwmod_soc_ops soc_ops __read_only;
3616
3617 /* omap_hwmod_list contains all registered struct omap_hwmods */
3618 static LIST_HEAD(omap_hwmod_list);
3619diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3620index d15c7bb..b2d1f0c 100644
3621--- a/arch/arm/mach-omap2/wd_timer.c
3622+++ b/arch/arm/mach-omap2/wd_timer.c
3623@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3624 struct omap_hwmod *oh;
3625 char *oh_name = "wd_timer2";
3626 char *dev_name = "omap_wdt";
3627- struct omap_wd_timer_platform_data pdata;
3628+ static struct omap_wd_timer_platform_data pdata = {
3629+ .read_reset_sources = prm_read_reset_sources
3630+ };
3631
3632 if (!cpu_class_is_omap2() || of_have_populated_dt())
3633 return 0;
3634@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3635 return -EINVAL;
3636 }
3637
3638- pdata.read_reset_sources = prm_read_reset_sources;
3639-
3640 pdev = omap_device_build(dev_name, id, oh, &pdata,
3641 sizeof(struct omap_wd_timer_platform_data));
3642 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3643diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3644index 0cdba8d..297993e 100644
3645--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3646+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3647@@ -181,7 +181,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3648 bool entered_lp2 = false;
3649
3650 if (tegra_pending_sgi())
3651- ACCESS_ONCE(abort_flag) = true;
3652+ ACCESS_ONCE_RW(abort_flag) = true;
3653
3654 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3655
3656diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3657index cad3ca86..1d79e0f 100644
3658--- a/arch/arm/mach-ux500/setup.h
3659+++ b/arch/arm/mach-ux500/setup.h
3660@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3661 .type = MT_DEVICE, \
3662 }
3663
3664-#define __MEM_DEV_DESC(x, sz) { \
3665- .virtual = IO_ADDRESS(x), \
3666- .pfn = __phys_to_pfn(x), \
3667- .length = sz, \
3668- .type = MT_MEMORY, \
3669-}
3670-
3671 extern struct smp_operations ux500_smp_ops;
3672 extern void ux500_cpu_die(unsigned int cpu);
3673
3674diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3675index 08c9fe9..191320c 100644
3676--- a/arch/arm/mm/Kconfig
3677+++ b/arch/arm/mm/Kconfig
3678@@ -436,7 +436,7 @@ config CPU_32v5
3679
3680 config CPU_32v6
3681 bool
3682- select CPU_USE_DOMAINS if CPU_V6 && MMU
3683+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3684 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3685
3686 config CPU_32v6K
3687@@ -585,6 +585,7 @@ config CPU_CP15_MPU
3688
3689 config CPU_USE_DOMAINS
3690 bool
3691+ depends on !ARM_LPAE && !PAX_KERNEXEC
3692 help
3693 This option enables or disables the use of domain switching
3694 via the set_fs() function.
3695@@ -780,6 +781,7 @@ config NEED_KUSER_HELPERS
3696 config KUSER_HELPERS
3697 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3698 default y
3699+ depends on !(CPU_V6 || CPU_V6K || CPU_V7)
3700 help
3701 Warning: disabling this option may break user programs.
3702
3703@@ -792,7 +794,7 @@ config KUSER_HELPERS
3704 See Documentation/arm/kernel_user_helpers.txt for details.
3705
3706 However, the fixed address nature of these helpers can be used
3707- by ROP (return orientated programming) authors when creating
3708+ by ROP (Return Oriented Programming) authors when creating
3709 exploits.
3710
3711 If all of the binaries and libraries which run on your platform
3712diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3713index 6f4585b..7b6f52b 100644
3714--- a/arch/arm/mm/alignment.c
3715+++ b/arch/arm/mm/alignment.c
3716@@ -211,10 +211,12 @@ union offset_union {
3717 #define __get16_unaligned_check(ins,val,addr) \
3718 do { \
3719 unsigned int err = 0, v, a = addr; \
3720+ pax_open_userland(); \
3721 __get8_unaligned_check(ins,v,a,err); \
3722 val = v << ((BE) ? 8 : 0); \
3723 __get8_unaligned_check(ins,v,a,err); \
3724 val |= v << ((BE) ? 0 : 8); \
3725+ pax_close_userland(); \
3726 if (err) \
3727 goto fault; \
3728 } while (0)
3729@@ -228,6 +230,7 @@ union offset_union {
3730 #define __get32_unaligned_check(ins,val,addr) \
3731 do { \
3732 unsigned int err = 0, v, a = addr; \
3733+ pax_open_userland(); \
3734 __get8_unaligned_check(ins,v,a,err); \
3735 val = v << ((BE) ? 24 : 0); \
3736 __get8_unaligned_check(ins,v,a,err); \
3737@@ -236,6 +239,7 @@ union offset_union {
3738 val |= v << ((BE) ? 8 : 16); \
3739 __get8_unaligned_check(ins,v,a,err); \
3740 val |= v << ((BE) ? 0 : 24); \
3741+ pax_close_userland(); \
3742 if (err) \
3743 goto fault; \
3744 } while (0)
3745@@ -249,6 +253,7 @@ union offset_union {
3746 #define __put16_unaligned_check(ins,val,addr) \
3747 do { \
3748 unsigned int err = 0, v = val, a = addr; \
3749+ pax_open_userland(); \
3750 __asm__( FIRST_BYTE_16 \
3751 ARM( "1: "ins" %1, [%2], #1\n" ) \
3752 THUMB( "1: "ins" %1, [%2]\n" ) \
3753@@ -268,6 +273,7 @@ union offset_union {
3754 " .popsection\n" \
3755 : "=r" (err), "=&r" (v), "=&r" (a) \
3756 : "0" (err), "1" (v), "2" (a)); \
3757+ pax_close_userland(); \
3758 if (err) \
3759 goto fault; \
3760 } while (0)
3761@@ -281,6 +287,7 @@ union offset_union {
3762 #define __put32_unaligned_check(ins,val,addr) \
3763 do { \
3764 unsigned int err = 0, v = val, a = addr; \
3765+ pax_open_userland(); \
3766 __asm__( FIRST_BYTE_32 \
3767 ARM( "1: "ins" %1, [%2], #1\n" ) \
3768 THUMB( "1: "ins" %1, [%2]\n" ) \
3769@@ -310,6 +317,7 @@ union offset_union {
3770 " .popsection\n" \
3771 : "=r" (err), "=&r" (v), "=&r" (a) \
3772 : "0" (err), "1" (v), "2" (a)); \
3773+ pax_close_userland(); \
3774 if (err) \
3775 goto fault; \
3776 } while (0)
3777diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3778index eeab06e..2638dc2 100644
3779--- a/arch/arm/mm/context.c
3780+++ b/arch/arm/mm/context.c
3781@@ -42,7 +42,7 @@
3782 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3783
3784 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3785-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3786+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3787 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3788
3789 static DEFINE_PER_CPU(atomic64_t, active_asids);
3790@@ -188,7 +188,7 @@ static int is_reserved_asid(u64 asid)
3791 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3792 {
3793 u64 asid = atomic64_read(&mm->context.id);
3794- u64 generation = atomic64_read(&asid_generation);
3795+ u64 generation = atomic64_read_unchecked(&asid_generation);
3796
3797 if (asid != 0 && is_reserved_asid(asid)) {
3798 /*
3799@@ -206,7 +206,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3800 */
3801 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3802 if (asid == NUM_USER_ASIDS) {
3803- generation = atomic64_add_return(ASID_FIRST_VERSION,
3804+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3805 &asid_generation);
3806 flush_context(cpu);
3807 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3808@@ -235,14 +235,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3809 cpu_set_reserved_ttbr0();
3810
3811 asid = atomic64_read(&mm->context.id);
3812- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3813+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3814 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3815 goto switch_mm_fastpath;
3816
3817 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3818 /* Check that our ASID belongs to the current generation. */
3819 asid = atomic64_read(&mm->context.id);
3820- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3821+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3822 asid = new_context(mm, cpu);
3823 atomic64_set(&mm->context.id, asid);
3824 }
3825diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3826index 5dbf13f..a2d1876 100644
3827--- a/arch/arm/mm/fault.c
3828+++ b/arch/arm/mm/fault.c
3829@@ -25,6 +25,7 @@
3830 #include <asm/system_misc.h>
3831 #include <asm/system_info.h>
3832 #include <asm/tlbflush.h>
3833+#include <asm/sections.h>
3834
3835 #include "fault.h"
3836
3837@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3838 if (fixup_exception(regs))
3839 return;
3840
3841+#ifdef CONFIG_PAX_KERNEXEC
3842+ if ((fsr & FSR_WRITE) &&
3843+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3844+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3845+ {
3846+ if (current->signal->curr_ip)
3847+ 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),
3848+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3849+ else
3850+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3851+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3852+ }
3853+#endif
3854+
3855 /*
3856 * No handler, we'll have to terminate things with extreme prejudice.
3857 */
3858@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3859 }
3860 #endif
3861
3862+#ifdef CONFIG_PAX_PAGEEXEC
3863+ if (fsr & FSR_LNX_PF) {
3864+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3865+ do_group_exit(SIGKILL);
3866+ }
3867+#endif
3868+
3869 tsk->thread.address = addr;
3870 tsk->thread.error_code = fsr;
3871 tsk->thread.trap_no = 14;
3872@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3873 }
3874 #endif /* CONFIG_MMU */
3875
3876+#ifdef CONFIG_PAX_PAGEEXEC
3877+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3878+{
3879+ long i;
3880+
3881+ printk(KERN_ERR "PAX: bytes at PC: ");
3882+ for (i = 0; i < 20; i++) {
3883+ unsigned char c;
3884+ if (get_user(c, (__force unsigned char __user *)pc+i))
3885+ printk(KERN_CONT "?? ");
3886+ else
3887+ printk(KERN_CONT "%02x ", c);
3888+ }
3889+ printk("\n");
3890+
3891+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3892+ for (i = -1; i < 20; i++) {
3893+ unsigned long c;
3894+ if (get_user(c, (__force unsigned long __user *)sp+i))
3895+ printk(KERN_CONT "???????? ");
3896+ else
3897+ printk(KERN_CONT "%08lx ", c);
3898+ }
3899+ printk("\n");
3900+}
3901+#endif
3902+
3903 /*
3904 * First Level Translation Fault Handler
3905 *
3906@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3907 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3908 struct siginfo info;
3909
3910+#ifdef CONFIG_PAX_MEMORY_UDEREF
3911+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3912+ if (current->signal->curr_ip)
3913+ 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),
3914+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3915+ else
3916+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3917+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3918+ goto die;
3919+ }
3920+#endif
3921+
3922 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3923 return;
3924
3925+die:
3926 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3927 inf->name, fsr, addr);
3928
3929@@ -569,15 +631,68 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3930 ifsr_info[nr].name = name;
3931 }
3932
3933+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3934+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3935+
3936 asmlinkage void __exception
3937 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3938 {
3939 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3940 struct siginfo info;
3941+ unsigned long pc = instruction_pointer(regs);
3942+
3943+ if (user_mode(regs)) {
3944+ unsigned long sigpage = current->mm->context.sigpage;
3945+
3946+ if (sigpage <= pc && pc < sigpage + 7*4) {
3947+ if (pc < sigpage + 3*4)
3948+ sys_sigreturn(regs);
3949+ else
3950+ sys_rt_sigreturn(regs);
3951+ return;
3952+ }
3953+ if (pc == 0xffff0fe0UL) {
3954+ /*
3955+ * PaX: __kuser_get_tls emulation
3956+ */
3957+ regs->ARM_r0 = current_thread_info()->tp_value;
3958+ regs->ARM_pc = regs->ARM_lr;
3959+ return;
3960+ }
3961+ }
3962+
3963+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3964+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3965+ if (current->signal->curr_ip)
3966+ 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),
3967+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3968+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3969+ else
3970+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3971+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3972+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3973+ goto die;
3974+ }
3975+#endif
3976+
3977+#ifdef CONFIG_PAX_REFCOUNT
3978+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3979+ unsigned int bkpt;
3980+
3981+ if (!probe_kernel_address((unsigned int *)pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
3982+ current->thread.error_code = ifsr;
3983+ current->thread.trap_no = 0;
3984+ pax_report_refcount_overflow(regs);
3985+ fixup_exception(regs);
3986+ return;
3987+ }
3988+ }
3989+#endif
3990
3991 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3992 return;
3993
3994+die:
3995 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3996 inf->name, ifsr, addr);
3997
3998diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3999index cf08bdf..772656c 100644
4000--- a/arch/arm/mm/fault.h
4001+++ b/arch/arm/mm/fault.h
4002@@ -3,6 +3,7 @@
4003
4004 /*
4005 * Fault status register encodings. We steal bit 31 for our own purposes.
4006+ * Set when the FSR value is from an instruction fault.
4007 */
4008 #define FSR_LNX_PF (1 << 31)
4009 #define FSR_WRITE (1 << 11)
4010@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4011 }
4012 #endif
4013
4014+/* valid for LPAE and !LPAE */
4015+static inline int is_xn_fault(unsigned int fsr)
4016+{
4017+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4018+}
4019+
4020+static inline int is_domain_fault(unsigned int fsr)
4021+{
4022+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4023+}
4024+
4025 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4026 unsigned long search_exception_table(unsigned long addr);
4027
4028diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4029index 0ecc43f..190b956 100644
4030--- a/arch/arm/mm/init.c
4031+++ b/arch/arm/mm/init.c
4032@@ -30,6 +30,8 @@
4033 #include <asm/setup.h>
4034 #include <asm/tlb.h>
4035 #include <asm/fixmap.h>
4036+#include <asm/system_info.h>
4037+#include <asm/cp15.h>
4038
4039 #include <asm/mach/arch.h>
4040 #include <asm/mach/map.h>
4041@@ -726,7 +728,46 @@ void free_initmem(void)
4042 {
4043 #ifdef CONFIG_HAVE_TCM
4044 extern char __tcm_start, __tcm_end;
4045+#endif
4046
4047+#ifdef CONFIG_PAX_KERNEXEC
4048+ unsigned long addr;
4049+ pgd_t *pgd;
4050+ pud_t *pud;
4051+ pmd_t *pmd;
4052+ int cpu_arch = cpu_architecture();
4053+ unsigned int cr = get_cr();
4054+
4055+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4056+ /* make pages tables, etc before .text NX */
4057+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4058+ pgd = pgd_offset_k(addr);
4059+ pud = pud_offset(pgd, addr);
4060+ pmd = pmd_offset(pud, addr);
4061+ __section_update(pmd, addr, PMD_SECT_XN);
4062+ }
4063+ /* make init NX */
4064+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4065+ pgd = pgd_offset_k(addr);
4066+ pud = pud_offset(pgd, addr);
4067+ pmd = pmd_offset(pud, addr);
4068+ __section_update(pmd, addr, PMD_SECT_XN);
4069+ }
4070+ /* make kernel code/rodata RX */
4071+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4072+ pgd = pgd_offset_k(addr);
4073+ pud = pud_offset(pgd, addr);
4074+ pmd = pmd_offset(pud, addr);
4075+#ifdef CONFIG_ARM_LPAE
4076+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4077+#else
4078+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4079+#endif
4080+ }
4081+ }
4082+#endif
4083+
4084+#ifdef CONFIG_HAVE_TCM
4085 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4086 free_reserved_area(&__tcm_start, &__tcm_end, 0, "TCM link");
4087 #endif
4088diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4089index 04d9006..c547d85 100644
4090--- a/arch/arm/mm/ioremap.c
4091+++ b/arch/arm/mm/ioremap.c
4092@@ -392,9 +392,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
4093 unsigned int mtype;
4094
4095 if (cached)
4096- mtype = MT_MEMORY;
4097+ mtype = MT_MEMORY_RX;
4098 else
4099- mtype = MT_MEMORY_NONCACHED;
4100+ mtype = MT_MEMORY_NONCACHED_RX;
4101
4102 return __arm_ioremap_caller(phys_addr, size, mtype,
4103 __builtin_return_address(0));
4104diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4105index 10062ce..8695745 100644
4106--- a/arch/arm/mm/mmap.c
4107+++ b/arch/arm/mm/mmap.c
4108@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4109 struct vm_area_struct *vma;
4110 int do_align = 0;
4111 int aliasing = cache_is_vipt_aliasing();
4112+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4113 struct vm_unmapped_area_info info;
4114
4115 /*
4116@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4117 if (len > TASK_SIZE)
4118 return -ENOMEM;
4119
4120+#ifdef CONFIG_PAX_RANDMMAP
4121+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4122+#endif
4123+
4124 if (addr) {
4125 if (do_align)
4126 addr = COLOUR_ALIGN(addr, pgoff);
4127@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4128 addr = PAGE_ALIGN(addr);
4129
4130 vma = find_vma(mm, addr);
4131- if (TASK_SIZE - len >= addr &&
4132- (!vma || addr + len <= vma->vm_start))
4133+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4134 return addr;
4135 }
4136
4137@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4138 info.high_limit = TASK_SIZE;
4139 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4140 info.align_offset = pgoff << PAGE_SHIFT;
4141+ info.threadstack_offset = offset;
4142 return vm_unmapped_area(&info);
4143 }
4144
4145@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4146 unsigned long addr = addr0;
4147 int do_align = 0;
4148 int aliasing = cache_is_vipt_aliasing();
4149+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4150 struct vm_unmapped_area_info info;
4151
4152 /*
4153@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4154 return addr;
4155 }
4156
4157+#ifdef CONFIG_PAX_RANDMMAP
4158+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4159+#endif
4160+
4161 /* requesting a specific address */
4162 if (addr) {
4163 if (do_align)
4164@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4165 else
4166 addr = PAGE_ALIGN(addr);
4167 vma = find_vma(mm, addr);
4168- if (TASK_SIZE - len >= addr &&
4169- (!vma || addr + len <= vma->vm_start))
4170+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4171 return addr;
4172 }
4173
4174@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4175 info.high_limit = mm->mmap_base;
4176 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4177 info.align_offset = pgoff << PAGE_SHIFT;
4178+ info.threadstack_offset = offset;
4179 addr = vm_unmapped_area(&info);
4180
4181 /*
4182@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4183 {
4184 unsigned long random_factor = 0UL;
4185
4186+#ifdef CONFIG_PAX_RANDMMAP
4187+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4188+#endif
4189+
4190 /* 8 bits of randomness in 20 address space bits */
4191 if ((current->flags & PF_RANDOMIZE) &&
4192 !(current->personality & ADDR_NO_RANDOMIZE))
4193@@ -180,10 +194,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4194
4195 if (mmap_is_legacy()) {
4196 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4197+
4198+#ifdef CONFIG_PAX_RANDMMAP
4199+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4200+ mm->mmap_base += mm->delta_mmap;
4201+#endif
4202+
4203 mm->get_unmapped_area = arch_get_unmapped_area;
4204 mm->unmap_area = arch_unmap_area;
4205 } else {
4206 mm->mmap_base = mmap_base(random_factor);
4207+
4208+#ifdef CONFIG_PAX_RANDMMAP
4209+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4210+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4211+#endif
4212+
4213 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4214 mm->unmap_area = arch_unmap_area_topdown;
4215 }
4216diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4217index daf336f..4e6392c 100644
4218--- a/arch/arm/mm/mmu.c
4219+++ b/arch/arm/mm/mmu.c
4220@@ -36,6 +36,22 @@
4221 #include "mm.h"
4222 #include "tcm.h"
4223
4224+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4225+void modify_domain(unsigned int dom, unsigned int type)
4226+{
4227+ struct thread_info *thread = current_thread_info();
4228+ unsigned int domain = thread->cpu_domain;
4229+ /*
4230+ * DOMAIN_MANAGER might be defined to some other value,
4231+ * use the arch-defined constant
4232+ */
4233+ domain &= ~domain_val(dom, 3);
4234+ thread->cpu_domain = domain | domain_val(dom, type);
4235+ set_domain(thread->cpu_domain);
4236+}
4237+EXPORT_SYMBOL(modify_domain);
4238+#endif
4239+
4240 /*
4241 * empty_zero_page is a special page that is used for
4242 * zero-initialized data and COW.
4243@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4244
4245 #endif /* ifdef CONFIG_CPU_CP15 / else */
4246
4247-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4248+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4249 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4250
4251-static struct mem_type mem_types[] = {
4252+#ifdef CONFIG_PAX_KERNEXEC
4253+#define L_PTE_KERNEXEC L_PTE_RDONLY
4254+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4255+#else
4256+#define L_PTE_KERNEXEC L_PTE_DIRTY
4257+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4258+#endif
4259+
4260+static struct mem_type mem_types[] __read_only = {
4261 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4262 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4263 L_PTE_SHARED,
4264@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4265 [MT_UNCACHED] = {
4266 .prot_pte = PROT_PTE_DEVICE,
4267 .prot_l1 = PMD_TYPE_TABLE,
4268- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4269+ .prot_sect = PROT_SECT_DEVICE,
4270 .domain = DOMAIN_IO,
4271 },
4272 [MT_CACHECLEAN] = {
4273- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4274+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4275 .domain = DOMAIN_KERNEL,
4276 },
4277 #ifndef CONFIG_ARM_LPAE
4278 [MT_MINICLEAN] = {
4279- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4280+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4281 .domain = DOMAIN_KERNEL,
4282 },
4283 #endif
4284@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4285 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4286 L_PTE_RDONLY,
4287 .prot_l1 = PMD_TYPE_TABLE,
4288- .domain = DOMAIN_USER,
4289+ .domain = DOMAIN_VECTORS,
4290 },
4291 [MT_HIGH_VECTORS] = {
4292 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4293 L_PTE_USER | L_PTE_RDONLY,
4294 .prot_l1 = PMD_TYPE_TABLE,
4295- .domain = DOMAIN_USER,
4296+ .domain = DOMAIN_VECTORS,
4297 },
4298- [MT_MEMORY] = {
4299+ [MT_MEMORY_RWX] = {
4300 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4301 .prot_l1 = PMD_TYPE_TABLE,
4302 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4303 .domain = DOMAIN_KERNEL,
4304 },
4305+ [MT_MEMORY_RW] = {
4306+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4307+ .prot_l1 = PMD_TYPE_TABLE,
4308+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4309+ .domain = DOMAIN_KERNEL,
4310+ },
4311+ [MT_MEMORY_RX] = {
4312+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4313+ .prot_l1 = PMD_TYPE_TABLE,
4314+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4315+ .domain = DOMAIN_KERNEL,
4316+ },
4317 [MT_ROM] = {
4318- .prot_sect = PMD_TYPE_SECT,
4319+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4320 .domain = DOMAIN_KERNEL,
4321 },
4322- [MT_MEMORY_NONCACHED] = {
4323+ [MT_MEMORY_NONCACHED_RW] = {
4324 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4325 L_PTE_MT_BUFFERABLE,
4326 .prot_l1 = PMD_TYPE_TABLE,
4327 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4328 .domain = DOMAIN_KERNEL,
4329 },
4330+ [MT_MEMORY_NONCACHED_RX] = {
4331+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4332+ L_PTE_MT_BUFFERABLE,
4333+ .prot_l1 = PMD_TYPE_TABLE,
4334+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4335+ .domain = DOMAIN_KERNEL,
4336+ },
4337 [MT_MEMORY_DTCM] = {
4338- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4339- L_PTE_XN,
4340+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4341 .prot_l1 = PMD_TYPE_TABLE,
4342- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4343+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4344 .domain = DOMAIN_KERNEL,
4345 },
4346 [MT_MEMORY_ITCM] = {
4347@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4348 },
4349 [MT_MEMORY_SO] = {
4350 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4351- L_PTE_MT_UNCACHED | L_PTE_XN,
4352+ L_PTE_MT_UNCACHED,
4353 .prot_l1 = PMD_TYPE_TABLE,
4354 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4355- PMD_SECT_UNCACHED | PMD_SECT_XN,
4356+ PMD_SECT_UNCACHED,
4357 .domain = DOMAIN_KERNEL,
4358 },
4359 [MT_MEMORY_DMA_READY] = {
4360@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4361 * to prevent speculative instruction fetches.
4362 */
4363 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4364+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4365 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4366+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4367 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4368+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4369 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4370+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4371+
4372+ /* Mark other regions on ARMv6+ as execute-never */
4373+
4374+#ifdef CONFIG_PAX_KERNEXEC
4375+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4376+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4377+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4378+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4379+#ifndef CONFIG_ARM_LPAE
4380+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4381+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4382+#endif
4383+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4384+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4385+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4386+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4387+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4388+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4389+#endif
4390+
4391+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4392+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4393 }
4394 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4395 /*
4396@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4397 * from SVC mode and no access from userspace.
4398 */
4399 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4400+#ifdef CONFIG_PAX_KERNEXEC
4401+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4402+#endif
4403 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4404 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4405 #endif
4406@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4407 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4408 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4409 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4410- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4411- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4412+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4413+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4414+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4415+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4416+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4417+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4418 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4419- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4420- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4421+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4422+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4423+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4424+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4425 }
4426 }
4427
4428@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4429 if (cpu_arch >= CPU_ARCH_ARMv6) {
4430 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4431 /* Non-cacheable Normal is XCB = 001 */
4432- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4433+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4434+ PMD_SECT_BUFFERED;
4435+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4436 PMD_SECT_BUFFERED;
4437 } else {
4438 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4439- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4440+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4441+ PMD_SECT_TEX(1);
4442+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4443 PMD_SECT_TEX(1);
4444 }
4445 } else {
4446- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4447+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4448+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4449 }
4450
4451 #ifdef CONFIG_ARM_LPAE
4452@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4453 vecs_pgprot |= PTE_EXT_AF;
4454 #endif
4455
4456+ user_pgprot |= __supported_pte_mask;
4457+
4458 for (i = 0; i < 16; i++) {
4459 pteval_t v = pgprot_val(protection_map[i]);
4460 protection_map[i] = __pgprot(v | user_pgprot);
4461@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4462
4463 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4464 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4465- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4466- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4467+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4468+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4469+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4470+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4471+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4472+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4473 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4474- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4475+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4476+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4477 mem_types[MT_ROM].prot_sect |= cp->pmd;
4478
4479 switch (cp->pmd) {
4480@@ -1166,18 +1255,15 @@ void __init arm_mm_memblock_reserve(void)
4481 * called function. This means you can't use any function or debugging
4482 * method which may touch any device, otherwise the kernel _will_ crash.
4483 */
4484+
4485+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4486+
4487 static void __init devicemaps_init(struct machine_desc *mdesc)
4488 {
4489 struct map_desc map;
4490 unsigned long addr;
4491- void *vectors;
4492
4493- /*
4494- * Allocate the vector page early.
4495- */
4496- vectors = early_alloc(PAGE_SIZE * 2);
4497-
4498- early_trap_init(vectors);
4499+ early_trap_init(&vectors);
4500
4501 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4502 pmd_clear(pmd_off_k(addr));
4503@@ -1217,7 +1303,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4504 * location (0xffff0000). If we aren't using high-vectors, also
4505 * create a mapping at the low-vectors virtual address.
4506 */
4507- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4508+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4509 map.virtual = 0xffff0000;
4510 map.length = PAGE_SIZE;
4511 #ifdef CONFIG_KUSER_HELPERS
4512@@ -1287,8 +1373,39 @@ static void __init map_lowmem(void)
4513 map.pfn = __phys_to_pfn(start);
4514 map.virtual = __phys_to_virt(start);
4515 map.length = end - start;
4516- map.type = MT_MEMORY;
4517
4518+#ifdef CONFIG_PAX_KERNEXEC
4519+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4520+ struct map_desc kernel;
4521+ struct map_desc initmap;
4522+
4523+ /* when freeing initmem we will make this RW */
4524+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4525+ initmap.virtual = (unsigned long)__init_begin;
4526+ initmap.length = _sdata - __init_begin;
4527+ initmap.type = MT_MEMORY_RWX;
4528+ create_mapping(&initmap);
4529+
4530+ /* when freeing initmem we will make this RX */
4531+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4532+ kernel.virtual = (unsigned long)_stext;
4533+ kernel.length = __init_begin - _stext;
4534+ kernel.type = MT_MEMORY_RWX;
4535+ create_mapping(&kernel);
4536+
4537+ if (map.virtual < (unsigned long)_stext) {
4538+ map.length = (unsigned long)_stext - map.virtual;
4539+ map.type = MT_MEMORY_RWX;
4540+ create_mapping(&map);
4541+ }
4542+
4543+ map.pfn = __phys_to_pfn(__pa(_sdata));
4544+ map.virtual = (unsigned long)_sdata;
4545+ map.length = end - __pa(_sdata);
4546+ }
4547+#endif
4548+
4549+ map.type = MT_MEMORY_RW;
4550 create_mapping(&map);
4551 }
4552 }
4553diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4554index a5bc92d..0bb4730 100644
4555--- a/arch/arm/plat-omap/sram.c
4556+++ b/arch/arm/plat-omap/sram.c
4557@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4558 * Looks like we need to preserve some bootloader code at the
4559 * beginning of SRAM for jumping to flash for reboot to work...
4560 */
4561+ pax_open_kernel();
4562 memset_io(omap_sram_base + omap_sram_skip, 0,
4563 omap_sram_size - omap_sram_skip);
4564+ pax_close_kernel();
4565 }
4566diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4567index ce6d763..cfea917 100644
4568--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4569+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4570@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4571 int (*started)(unsigned ch);
4572 int (*flush)(unsigned ch);
4573 int (*stop)(unsigned ch);
4574-};
4575+} __no_const;
4576
4577 extern void *samsung_dmadev_get_ops(void);
4578 extern void *s3c_dma_get_ops(void);
4579diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4580index f4726dc..39ed646 100644
4581--- a/arch/arm64/kernel/debug-monitors.c
4582+++ b/arch/arm64/kernel/debug-monitors.c
4583@@ -149,7 +149,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4584 return NOTIFY_OK;
4585 }
4586
4587-static struct notifier_block __cpuinitdata os_lock_nb = {
4588+static struct notifier_block os_lock_nb = {
4589 .notifier_call = os_lock_notify,
4590 };
4591
4592diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4593index 5ab825c..96aaec8 100644
4594--- a/arch/arm64/kernel/hw_breakpoint.c
4595+++ b/arch/arm64/kernel/hw_breakpoint.c
4596@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4597 return NOTIFY_OK;
4598 }
4599
4600-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4601+static struct notifier_block hw_breakpoint_reset_nb = {
4602 .notifier_call = hw_breakpoint_reset_notify,
4603 };
4604
4605diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4606index c3a58a1..78fbf54 100644
4607--- a/arch/avr32/include/asm/cache.h
4608+++ b/arch/avr32/include/asm/cache.h
4609@@ -1,8 +1,10 @@
4610 #ifndef __ASM_AVR32_CACHE_H
4611 #define __ASM_AVR32_CACHE_H
4612
4613+#include <linux/const.h>
4614+
4615 #define L1_CACHE_SHIFT 5
4616-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4617+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4618
4619 /*
4620 * Memory returned by kmalloc() may be used for DMA, so we must make
4621diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4622index d232888..87c8df1 100644
4623--- a/arch/avr32/include/asm/elf.h
4624+++ b/arch/avr32/include/asm/elf.h
4625@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4626 the loader. We need to make sure that it is out of the way of the program
4627 that it will "exec", and that there is sufficient room for the brk. */
4628
4629-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4630+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4631
4632+#ifdef CONFIG_PAX_ASLR
4633+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4634+
4635+#define PAX_DELTA_MMAP_LEN 15
4636+#define PAX_DELTA_STACK_LEN 15
4637+#endif
4638
4639 /* This yields a mask that user programs can use to figure out what
4640 instruction set this CPU supports. This could be done in user space,
4641diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4642index 479330b..53717a8 100644
4643--- a/arch/avr32/include/asm/kmap_types.h
4644+++ b/arch/avr32/include/asm/kmap_types.h
4645@@ -2,9 +2,9 @@
4646 #define __ASM_AVR32_KMAP_TYPES_H
4647
4648 #ifdef CONFIG_DEBUG_HIGHMEM
4649-# define KM_TYPE_NR 29
4650+# define KM_TYPE_NR 30
4651 #else
4652-# define KM_TYPE_NR 14
4653+# define KM_TYPE_NR 15
4654 #endif
4655
4656 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4657diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4658index b2f2d2d..d1c85cb 100644
4659--- a/arch/avr32/mm/fault.c
4660+++ b/arch/avr32/mm/fault.c
4661@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4662
4663 int exception_trace = 1;
4664
4665+#ifdef CONFIG_PAX_PAGEEXEC
4666+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4667+{
4668+ unsigned long i;
4669+
4670+ printk(KERN_ERR "PAX: bytes at PC: ");
4671+ for (i = 0; i < 20; i++) {
4672+ unsigned char c;
4673+ if (get_user(c, (unsigned char *)pc+i))
4674+ printk(KERN_CONT "???????? ");
4675+ else
4676+ printk(KERN_CONT "%02x ", c);
4677+ }
4678+ printk("\n");
4679+}
4680+#endif
4681+
4682 /*
4683 * This routine handles page faults. It determines the address and the
4684 * problem, and then passes it off to one of the appropriate routines.
4685@@ -174,6 +191,16 @@ bad_area:
4686 up_read(&mm->mmap_sem);
4687
4688 if (user_mode(regs)) {
4689+
4690+#ifdef CONFIG_PAX_PAGEEXEC
4691+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4692+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4693+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4694+ do_group_exit(SIGKILL);
4695+ }
4696+ }
4697+#endif
4698+
4699 if (exception_trace && printk_ratelimit())
4700 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4701 "sp %08lx ecr %lu\n",
4702diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4703index 568885a..f8008df 100644
4704--- a/arch/blackfin/include/asm/cache.h
4705+++ b/arch/blackfin/include/asm/cache.h
4706@@ -7,6 +7,7 @@
4707 #ifndef __ARCH_BLACKFIN_CACHE_H
4708 #define __ARCH_BLACKFIN_CACHE_H
4709
4710+#include <linux/const.h>
4711 #include <linux/linkage.h> /* for asmlinkage */
4712
4713 /*
4714@@ -14,7 +15,7 @@
4715 * Blackfin loads 32 bytes for cache
4716 */
4717 #define L1_CACHE_SHIFT 5
4718-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4719+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4720 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4721
4722 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4723diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4724index aea2718..3639a60 100644
4725--- a/arch/cris/include/arch-v10/arch/cache.h
4726+++ b/arch/cris/include/arch-v10/arch/cache.h
4727@@ -1,8 +1,9 @@
4728 #ifndef _ASM_ARCH_CACHE_H
4729 #define _ASM_ARCH_CACHE_H
4730
4731+#include <linux/const.h>
4732 /* Etrax 100LX have 32-byte cache-lines. */
4733-#define L1_CACHE_BYTES 32
4734 #define L1_CACHE_SHIFT 5
4735+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4736
4737 #endif /* _ASM_ARCH_CACHE_H */
4738diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4739index 7caf25d..ee65ac5 100644
4740--- a/arch/cris/include/arch-v32/arch/cache.h
4741+++ b/arch/cris/include/arch-v32/arch/cache.h
4742@@ -1,11 +1,12 @@
4743 #ifndef _ASM_CRIS_ARCH_CACHE_H
4744 #define _ASM_CRIS_ARCH_CACHE_H
4745
4746+#include <linux/const.h>
4747 #include <arch/hwregs/dma.h>
4748
4749 /* A cache-line is 32 bytes. */
4750-#define L1_CACHE_BYTES 32
4751 #define L1_CACHE_SHIFT 5
4752+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4753
4754 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4755
4756diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4757index b86329d..6709906 100644
4758--- a/arch/frv/include/asm/atomic.h
4759+++ b/arch/frv/include/asm/atomic.h
4760@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4761 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4762 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4763
4764+#define atomic64_read_unchecked(v) atomic64_read(v)
4765+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4766+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4767+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4768+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4769+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4770+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4771+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4772+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4773+
4774 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4775 {
4776 int c, old;
4777diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4778index 2797163..c2a401d 100644
4779--- a/arch/frv/include/asm/cache.h
4780+++ b/arch/frv/include/asm/cache.h
4781@@ -12,10 +12,11 @@
4782 #ifndef __ASM_CACHE_H
4783 #define __ASM_CACHE_H
4784
4785+#include <linux/const.h>
4786
4787 /* bytes per L1 cache line */
4788 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4789-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4790+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4791
4792 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4793 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4794diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4795index 43901f2..0d8b865 100644
4796--- a/arch/frv/include/asm/kmap_types.h
4797+++ b/arch/frv/include/asm/kmap_types.h
4798@@ -2,6 +2,6 @@
4799 #ifndef _ASM_KMAP_TYPES_H
4800 #define _ASM_KMAP_TYPES_H
4801
4802-#define KM_TYPE_NR 17
4803+#define KM_TYPE_NR 18
4804
4805 #endif
4806diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4807index 836f147..4cf23f5 100644
4808--- a/arch/frv/mm/elf-fdpic.c
4809+++ b/arch/frv/mm/elf-fdpic.c
4810@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4811 {
4812 struct vm_area_struct *vma;
4813 struct vm_unmapped_area_info info;
4814+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4815
4816 if (len > TASK_SIZE)
4817 return -ENOMEM;
4818@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4819 if (addr) {
4820 addr = PAGE_ALIGN(addr);
4821 vma = find_vma(current->mm, addr);
4822- if (TASK_SIZE - len >= addr &&
4823- (!vma || addr + len <= vma->vm_start))
4824+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4825 goto success;
4826 }
4827
4828@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4829 info.high_limit = (current->mm->start_stack - 0x00200000);
4830 info.align_mask = 0;
4831 info.align_offset = 0;
4832+ info.threadstack_offset = offset;
4833 addr = vm_unmapped_area(&info);
4834 if (!(addr & ~PAGE_MASK))
4835 goto success;
4836diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4837index f4ca594..adc72fd6 100644
4838--- a/arch/hexagon/include/asm/cache.h
4839+++ b/arch/hexagon/include/asm/cache.h
4840@@ -21,9 +21,11 @@
4841 #ifndef __ASM_CACHE_H
4842 #define __ASM_CACHE_H
4843
4844+#include <linux/const.h>
4845+
4846 /* Bytes per L1 cache line */
4847-#define L1_CACHE_SHIFT (5)
4848-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4849+#define L1_CACHE_SHIFT 5
4850+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4851
4852 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4853 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4854diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4855index 6e6fe18..a6ae668 100644
4856--- a/arch/ia64/include/asm/atomic.h
4857+++ b/arch/ia64/include/asm/atomic.h
4858@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4859 #define atomic64_inc(v) atomic64_add(1, (v))
4860 #define atomic64_dec(v) atomic64_sub(1, (v))
4861
4862+#define atomic64_read_unchecked(v) atomic64_read(v)
4863+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4864+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4865+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4866+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4867+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4868+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4869+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4870+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4871+
4872 /* Atomic operations are already serializing */
4873 #define smp_mb__before_atomic_dec() barrier()
4874 #define smp_mb__after_atomic_dec() barrier()
4875diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4876index 988254a..e1ee885 100644
4877--- a/arch/ia64/include/asm/cache.h
4878+++ b/arch/ia64/include/asm/cache.h
4879@@ -1,6 +1,7 @@
4880 #ifndef _ASM_IA64_CACHE_H
4881 #define _ASM_IA64_CACHE_H
4882
4883+#include <linux/const.h>
4884
4885 /*
4886 * Copyright (C) 1998-2000 Hewlett-Packard Co
4887@@ -9,7 +10,7 @@
4888
4889 /* Bytes per L1 (data) cache line. */
4890 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4891-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4892+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4893
4894 #ifdef CONFIG_SMP
4895 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4896diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4897index 5a83c5c..4d7f553 100644
4898--- a/arch/ia64/include/asm/elf.h
4899+++ b/arch/ia64/include/asm/elf.h
4900@@ -42,6 +42,13 @@
4901 */
4902 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4903
4904+#ifdef CONFIG_PAX_ASLR
4905+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4906+
4907+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4908+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4909+#endif
4910+
4911 #define PT_IA_64_UNWIND 0x70000001
4912
4913 /* IA-64 relocations: */
4914diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4915index 96a8d92..617a1cf 100644
4916--- a/arch/ia64/include/asm/pgalloc.h
4917+++ b/arch/ia64/include/asm/pgalloc.h
4918@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4919 pgd_val(*pgd_entry) = __pa(pud);
4920 }
4921
4922+static inline void
4923+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4924+{
4925+ pgd_populate(mm, pgd_entry, pud);
4926+}
4927+
4928 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4929 {
4930 return quicklist_alloc(0, GFP_KERNEL, NULL);
4931@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4932 pud_val(*pud_entry) = __pa(pmd);
4933 }
4934
4935+static inline void
4936+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4937+{
4938+ pud_populate(mm, pud_entry, pmd);
4939+}
4940+
4941 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4942 {
4943 return quicklist_alloc(0, GFP_KERNEL, NULL);
4944diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4945index 815810c..d60bd4c 100644
4946--- a/arch/ia64/include/asm/pgtable.h
4947+++ b/arch/ia64/include/asm/pgtable.h
4948@@ -12,7 +12,7 @@
4949 * David Mosberger-Tang <davidm@hpl.hp.com>
4950 */
4951
4952-
4953+#include <linux/const.h>
4954 #include <asm/mman.h>
4955 #include <asm/page.h>
4956 #include <asm/processor.h>
4957@@ -142,6 +142,17 @@
4958 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4959 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4960 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4961+
4962+#ifdef CONFIG_PAX_PAGEEXEC
4963+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4964+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4965+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4966+#else
4967+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4968+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4969+# define PAGE_COPY_NOEXEC PAGE_COPY
4970+#endif
4971+
4972 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4973 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4974 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4975diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4976index 54ff557..70c88b7 100644
4977--- a/arch/ia64/include/asm/spinlock.h
4978+++ b/arch/ia64/include/asm/spinlock.h
4979@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4980 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4981
4982 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4983- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4984+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4985 }
4986
4987 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4988diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4989index 449c8c0..18965fb 100644
4990--- a/arch/ia64/include/asm/uaccess.h
4991+++ b/arch/ia64/include/asm/uaccess.h
4992@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4993 static inline unsigned long
4994 __copy_to_user (void __user *to, const void *from, unsigned long count)
4995 {
4996+ if (count > INT_MAX)
4997+ return count;
4998+
4999+ if (!__builtin_constant_p(count))
5000+ check_object_size(from, count, true);
5001+
5002 return __copy_user(to, (__force void __user *) from, count);
5003 }
5004
5005 static inline unsigned long
5006 __copy_from_user (void *to, const void __user *from, unsigned long count)
5007 {
5008+ if (count > INT_MAX)
5009+ return count;
5010+
5011+ if (!__builtin_constant_p(count))
5012+ check_object_size(to, count, false);
5013+
5014 return __copy_user((__force void __user *) to, from, count);
5015 }
5016
5017@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5018 ({ \
5019 void __user *__cu_to = (to); \
5020 const void *__cu_from = (from); \
5021- long __cu_len = (n); \
5022+ unsigned long __cu_len = (n); \
5023 \
5024- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5025+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5026+ if (!__builtin_constant_p(n)) \
5027+ check_object_size(__cu_from, __cu_len, true); \
5028 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5029+ } \
5030 __cu_len; \
5031 })
5032
5033@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5034 ({ \
5035 void *__cu_to = (to); \
5036 const void __user *__cu_from = (from); \
5037- long __cu_len = (n); \
5038+ unsigned long __cu_len = (n); \
5039 \
5040 __chk_user_ptr(__cu_from); \
5041- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5042+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5043+ if (!__builtin_constant_p(n)) \
5044+ check_object_size(__cu_to, __cu_len, false); \
5045 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5046+ } \
5047 __cu_len; \
5048 })
5049
5050diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
5051index 2d67317..07d8bfa 100644
5052--- a/arch/ia64/kernel/err_inject.c
5053+++ b/arch/ia64/kernel/err_inject.c
5054@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
5055 return NOTIFY_OK;
5056 }
5057
5058-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
5059+static struct notifier_block err_inject_cpu_notifier =
5060 {
5061 .notifier_call = err_inject_cpu_callback,
5062 };
5063diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
5064index d7396db..b33e873 100644
5065--- a/arch/ia64/kernel/mca.c
5066+++ b/arch/ia64/kernel/mca.c
5067@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
5068 return NOTIFY_OK;
5069 }
5070
5071-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
5072+static struct notifier_block mca_cpu_notifier = {
5073 .notifier_call = mca_cpu_callback
5074 };
5075
5076diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5077index 24603be..948052d 100644
5078--- a/arch/ia64/kernel/module.c
5079+++ b/arch/ia64/kernel/module.c
5080@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5081 void
5082 module_free (struct module *mod, void *module_region)
5083 {
5084- if (mod && mod->arch.init_unw_table &&
5085- module_region == mod->module_init) {
5086+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5087 unw_remove_unwind_table(mod->arch.init_unw_table);
5088 mod->arch.init_unw_table = NULL;
5089 }
5090@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5091 }
5092
5093 static inline int
5094+in_init_rx (const struct module *mod, uint64_t addr)
5095+{
5096+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5097+}
5098+
5099+static inline int
5100+in_init_rw (const struct module *mod, uint64_t addr)
5101+{
5102+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5103+}
5104+
5105+static inline int
5106 in_init (const struct module *mod, uint64_t addr)
5107 {
5108- return addr - (uint64_t) mod->module_init < mod->init_size;
5109+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5110+}
5111+
5112+static inline int
5113+in_core_rx (const struct module *mod, uint64_t addr)
5114+{
5115+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5116+}
5117+
5118+static inline int
5119+in_core_rw (const struct module *mod, uint64_t addr)
5120+{
5121+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5122 }
5123
5124 static inline int
5125 in_core (const struct module *mod, uint64_t addr)
5126 {
5127- return addr - (uint64_t) mod->module_core < mod->core_size;
5128+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5129 }
5130
5131 static inline int
5132@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5133 break;
5134
5135 case RV_BDREL:
5136- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5137+ if (in_init_rx(mod, val))
5138+ val -= (uint64_t) mod->module_init_rx;
5139+ else if (in_init_rw(mod, val))
5140+ val -= (uint64_t) mod->module_init_rw;
5141+ else if (in_core_rx(mod, val))
5142+ val -= (uint64_t) mod->module_core_rx;
5143+ else if (in_core_rw(mod, val))
5144+ val -= (uint64_t) mod->module_core_rw;
5145 break;
5146
5147 case RV_LTV:
5148@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5149 * addresses have been selected...
5150 */
5151 uint64_t gp;
5152- if (mod->core_size > MAX_LTOFF)
5153+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5154 /*
5155 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5156 * at the end of the module.
5157 */
5158- gp = mod->core_size - MAX_LTOFF / 2;
5159+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5160 else
5161- gp = mod->core_size / 2;
5162- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5163+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5164+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5165 mod->arch.gp = gp;
5166 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5167 }
5168diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5169index 2b3c2d7..a318d84 100644
5170--- a/arch/ia64/kernel/palinfo.c
5171+++ b/arch/ia64/kernel/palinfo.c
5172@@ -980,7 +980,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
5173 return NOTIFY_OK;
5174 }
5175
5176-static struct notifier_block __refdata palinfo_cpu_notifier =
5177+static struct notifier_block palinfo_cpu_notifier =
5178 {
5179 .notifier_call = palinfo_cpu_callback,
5180 .priority = 0,
5181diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
5182index 4bc580a..7767f24 100644
5183--- a/arch/ia64/kernel/salinfo.c
5184+++ b/arch/ia64/kernel/salinfo.c
5185@@ -609,7 +609,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
5186 return NOTIFY_OK;
5187 }
5188
5189-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
5190+static struct notifier_block salinfo_cpu_notifier =
5191 {
5192 .notifier_call = salinfo_cpu_callback,
5193 .priority = 0,
5194diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5195index 41e33f8..65180b2 100644
5196--- a/arch/ia64/kernel/sys_ia64.c
5197+++ b/arch/ia64/kernel/sys_ia64.c
5198@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5199 unsigned long align_mask = 0;
5200 struct mm_struct *mm = current->mm;
5201 struct vm_unmapped_area_info info;
5202+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5203
5204 if (len > RGN_MAP_LIMIT)
5205 return -ENOMEM;
5206@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5207 if (REGION_NUMBER(addr) == RGN_HPAGE)
5208 addr = 0;
5209 #endif
5210+
5211+#ifdef CONFIG_PAX_RANDMMAP
5212+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5213+ addr = mm->free_area_cache;
5214+ else
5215+#endif
5216+
5217 if (!addr)
5218 addr = TASK_UNMAPPED_BASE;
5219
5220@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5221 info.high_limit = TASK_SIZE;
5222 info.align_mask = align_mask;
5223 info.align_offset = 0;
5224+ info.threadstack_offset = offset;
5225 return vm_unmapped_area(&info);
5226 }
5227
5228diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
5229index dc00b2c..cce53c2 100644
5230--- a/arch/ia64/kernel/topology.c
5231+++ b/arch/ia64/kernel/topology.c
5232@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
5233 return NOTIFY_OK;
5234 }
5235
5236-static struct notifier_block __cpuinitdata cache_cpu_notifier =
5237+static struct notifier_block cache_cpu_notifier =
5238 {
5239 .notifier_call = cache_cpu_callback
5240 };
5241diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5242index 0ccb28f..8992469 100644
5243--- a/arch/ia64/kernel/vmlinux.lds.S
5244+++ b/arch/ia64/kernel/vmlinux.lds.S
5245@@ -198,7 +198,7 @@ SECTIONS {
5246 /* Per-cpu data: */
5247 . = ALIGN(PERCPU_PAGE_SIZE);
5248 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5249- __phys_per_cpu_start = __per_cpu_load;
5250+ __phys_per_cpu_start = per_cpu_load;
5251 /*
5252 * ensure percpu data fits
5253 * into percpu page size
5254diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5255index 6cf0341..d352594 100644
5256--- a/arch/ia64/mm/fault.c
5257+++ b/arch/ia64/mm/fault.c
5258@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5259 return pte_present(pte);
5260 }
5261
5262+#ifdef CONFIG_PAX_PAGEEXEC
5263+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5264+{
5265+ unsigned long i;
5266+
5267+ printk(KERN_ERR "PAX: bytes at PC: ");
5268+ for (i = 0; i < 8; i++) {
5269+ unsigned int c;
5270+ if (get_user(c, (unsigned int *)pc+i))
5271+ printk(KERN_CONT "???????? ");
5272+ else
5273+ printk(KERN_CONT "%08x ", c);
5274+ }
5275+ printk("\n");
5276+}
5277+#endif
5278+
5279 # define VM_READ_BIT 0
5280 # define VM_WRITE_BIT 1
5281 # define VM_EXEC_BIT 2
5282@@ -149,8 +166,21 @@ retry:
5283 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5284 goto bad_area;
5285
5286- if ((vma->vm_flags & mask) != mask)
5287+ if ((vma->vm_flags & mask) != mask) {
5288+
5289+#ifdef CONFIG_PAX_PAGEEXEC
5290+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5291+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5292+ goto bad_area;
5293+
5294+ up_read(&mm->mmap_sem);
5295+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5296+ do_group_exit(SIGKILL);
5297+ }
5298+#endif
5299+
5300 goto bad_area;
5301+ }
5302
5303 /*
5304 * If for any reason at all we couldn't handle the fault, make
5305diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5306index 76069c1..c2aa816 100644
5307--- a/arch/ia64/mm/hugetlbpage.c
5308+++ b/arch/ia64/mm/hugetlbpage.c
5309@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5310 unsigned long pgoff, unsigned long flags)
5311 {
5312 struct vm_unmapped_area_info info;
5313+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5314
5315 if (len > RGN_MAP_LIMIT)
5316 return -ENOMEM;
5317@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5318 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5319 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5320 info.align_offset = 0;
5321+ info.threadstack_offset = offset;
5322 return vm_unmapped_area(&info);
5323 }
5324
5325diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5326index d1fe4b4..2628f37 100644
5327--- a/arch/ia64/mm/init.c
5328+++ b/arch/ia64/mm/init.c
5329@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5330 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5331 vma->vm_end = vma->vm_start + PAGE_SIZE;
5332 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5333+
5334+#ifdef CONFIG_PAX_PAGEEXEC
5335+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5336+ vma->vm_flags &= ~VM_EXEC;
5337+
5338+#ifdef CONFIG_PAX_MPROTECT
5339+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5340+ vma->vm_flags &= ~VM_MAYEXEC;
5341+#endif
5342+
5343+ }
5344+#endif
5345+
5346 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5347 down_write(&current->mm->mmap_sem);
5348 if (insert_vm_struct(current->mm, vma)) {
5349diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5350index 40b3ee9..8c2c112 100644
5351--- a/arch/m32r/include/asm/cache.h
5352+++ b/arch/m32r/include/asm/cache.h
5353@@ -1,8 +1,10 @@
5354 #ifndef _ASM_M32R_CACHE_H
5355 #define _ASM_M32R_CACHE_H
5356
5357+#include <linux/const.h>
5358+
5359 /* L1 cache line size */
5360 #define L1_CACHE_SHIFT 4
5361-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5362+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5363
5364 #endif /* _ASM_M32R_CACHE_H */
5365diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5366index 82abd15..d95ae5d 100644
5367--- a/arch/m32r/lib/usercopy.c
5368+++ b/arch/m32r/lib/usercopy.c
5369@@ -14,6 +14,9 @@
5370 unsigned long
5371 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5372 {
5373+ if ((long)n < 0)
5374+ return n;
5375+
5376 prefetch(from);
5377 if (access_ok(VERIFY_WRITE, to, n))
5378 __copy_user(to,from,n);
5379@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5380 unsigned long
5381 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5382 {
5383+ if ((long)n < 0)
5384+ return n;
5385+
5386 prefetchw(to);
5387 if (access_ok(VERIFY_READ, from, n))
5388 __copy_user_zeroing(to,from,n);
5389diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5390index 0395c51..5f26031 100644
5391--- a/arch/m68k/include/asm/cache.h
5392+++ b/arch/m68k/include/asm/cache.h
5393@@ -4,9 +4,11 @@
5394 #ifndef __ARCH_M68K_CACHE_H
5395 #define __ARCH_M68K_CACHE_H
5396
5397+#include <linux/const.h>
5398+
5399 /* bytes per L1 cache line */
5400 #define L1_CACHE_SHIFT 4
5401-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5402+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5403
5404 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5405
5406diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5407index 3c52fa6..11b2ad8 100644
5408--- a/arch/metag/mm/hugetlbpage.c
5409+++ b/arch/metag/mm/hugetlbpage.c
5410@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5411 info.high_limit = TASK_SIZE;
5412 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5413 info.align_offset = 0;
5414+ info.threadstack_offset = 0;
5415 return vm_unmapped_area(&info);
5416 }
5417
5418diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5419index 4efe96a..60e8699 100644
5420--- a/arch/microblaze/include/asm/cache.h
5421+++ b/arch/microblaze/include/asm/cache.h
5422@@ -13,11 +13,12 @@
5423 #ifndef _ASM_MICROBLAZE_CACHE_H
5424 #define _ASM_MICROBLAZE_CACHE_H
5425
5426+#include <linux/const.h>
5427 #include <asm/registers.h>
5428
5429 #define L1_CACHE_SHIFT 5
5430 /* word-granular cache in microblaze */
5431-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5432+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5433
5434 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5435
5436diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5437index 08b6079..8b554d2 100644
5438--- a/arch/mips/include/asm/atomic.h
5439+++ b/arch/mips/include/asm/atomic.h
5440@@ -21,15 +21,39 @@
5441 #include <asm/cmpxchg.h>
5442 #include <asm/war.h>
5443
5444+#ifdef CONFIG_GENERIC_ATOMIC64
5445+#include <asm-generic/atomic64.h>
5446+#endif
5447+
5448 #define ATOMIC_INIT(i) { (i) }
5449
5450+#ifdef CONFIG_64BIT
5451+#define _ASM_EXTABLE(from, to) \
5452+" .section __ex_table,\"a\"\n" \
5453+" .dword " #from ", " #to"\n" \
5454+" .previous\n"
5455+#else
5456+#define _ASM_EXTABLE(from, to) \
5457+" .section __ex_table,\"a\"\n" \
5458+" .word " #from ", " #to"\n" \
5459+" .previous\n"
5460+#endif
5461+
5462 /*
5463 * atomic_read - read atomic variable
5464 * @v: pointer of type atomic_t
5465 *
5466 * Atomically reads the value of @v.
5467 */
5468-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5469+static inline int atomic_read(const atomic_t *v)
5470+{
5471+ return (*(volatile const int *) &v->counter);
5472+}
5473+
5474+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5475+{
5476+ return (*(volatile const int *) &v->counter);
5477+}
5478
5479 /*
5480 * atomic_set - set atomic variable
5481@@ -38,7 +62,15 @@
5482 *
5483 * Atomically sets the value of @v to @i.
5484 */
5485-#define atomic_set(v, i) ((v)->counter = (i))
5486+static inline void atomic_set(atomic_t *v, int i)
5487+{
5488+ v->counter = i;
5489+}
5490+
5491+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5492+{
5493+ v->counter = i;
5494+}
5495
5496 /*
5497 * atomic_add - add integer to atomic variable
5498@@ -47,7 +79,67 @@
5499 *
5500 * Atomically adds @i to @v.
5501 */
5502-static __inline__ void atomic_add(int i, atomic_t * v)
5503+static __inline__ void atomic_add(int i, atomic_t *v)
5504+{
5505+ int temp;
5506+
5507+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5508+ __asm__ __volatile__(
5509+ " .set mips3 \n"
5510+ "1: ll %0, %1 # atomic_add \n"
5511+#ifdef CONFIG_PAX_REFCOUNT
5512+ /* Exception on overflow. */
5513+ "2: add %0, %2 \n"
5514+#else
5515+ " addu %0, %2 \n"
5516+#endif
5517+ " sc %0, %1 \n"
5518+ " beqzl %0, 1b \n"
5519+#ifdef CONFIG_PAX_REFCOUNT
5520+ "3: \n"
5521+ _ASM_EXTABLE(2b, 3b)
5522+#endif
5523+ " .set mips0 \n"
5524+ : "=&r" (temp), "+m" (v->counter)
5525+ : "Ir" (i));
5526+ } else if (kernel_uses_llsc) {
5527+ __asm__ __volatile__(
5528+ " .set mips3 \n"
5529+ "1: ll %0, %1 # atomic_add \n"
5530+#ifdef CONFIG_PAX_REFCOUNT
5531+ /* Exception on overflow. */
5532+ "2: add %0, %2 \n"
5533+#else
5534+ " addu %0, %2 \n"
5535+#endif
5536+ " sc %0, %1 \n"
5537+ " beqz %0, 1b \n"
5538+#ifdef CONFIG_PAX_REFCOUNT
5539+ "3: \n"
5540+ _ASM_EXTABLE(2b, 3b)
5541+#endif
5542+ " .set mips0 \n"
5543+ : "=&r" (temp), "+m" (v->counter)
5544+ : "Ir" (i));
5545+ } else {
5546+ unsigned long flags;
5547+
5548+ raw_local_irq_save(flags);
5549+ __asm__ __volatile__(
5550+#ifdef CONFIG_PAX_REFCOUNT
5551+ /* Exception on overflow. */
5552+ "1: add %0, %1 \n"
5553+ "2: \n"
5554+ _ASM_EXTABLE(1b, 2b)
5555+#else
5556+ " addu %0, %1 \n"
5557+#endif
5558+ : "+r" (v->counter) : "Ir" (i));
5559+ raw_local_irq_restore(flags);
5560+ }
5561+}
5562+
5563+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5564 {
5565 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5566 int temp;
5567@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5568 *
5569 * Atomically subtracts @i from @v.
5570 */
5571-static __inline__ void atomic_sub(int i, atomic_t * v)
5572+static __inline__ void atomic_sub(int i, atomic_t *v)
5573+{
5574+ int temp;
5575+
5576+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5577+ __asm__ __volatile__(
5578+ " .set mips3 \n"
5579+ "1: ll %0, %1 # atomic64_sub \n"
5580+#ifdef CONFIG_PAX_REFCOUNT
5581+ /* Exception on overflow. */
5582+ "2: sub %0, %2 \n"
5583+#else
5584+ " subu %0, %2 \n"
5585+#endif
5586+ " sc %0, %1 \n"
5587+ " beqzl %0, 1b \n"
5588+#ifdef CONFIG_PAX_REFCOUNT
5589+ "3: \n"
5590+ _ASM_EXTABLE(2b, 3b)
5591+#endif
5592+ " .set mips0 \n"
5593+ : "=&r" (temp), "+m" (v->counter)
5594+ : "Ir" (i));
5595+ } else if (kernel_uses_llsc) {
5596+ __asm__ __volatile__(
5597+ " .set mips3 \n"
5598+ "1: ll %0, %1 # atomic64_sub \n"
5599+#ifdef CONFIG_PAX_REFCOUNT
5600+ /* Exception on overflow. */
5601+ "2: sub %0, %2 \n"
5602+#else
5603+ " subu %0, %2 \n"
5604+#endif
5605+ " sc %0, %1 \n"
5606+ " beqz %0, 1b \n"
5607+#ifdef CONFIG_PAX_REFCOUNT
5608+ "3: \n"
5609+ _ASM_EXTABLE(2b, 3b)
5610+#endif
5611+ " .set mips0 \n"
5612+ : "=&r" (temp), "+m" (v->counter)
5613+ : "Ir" (i));
5614+ } else {
5615+ unsigned long flags;
5616+
5617+ raw_local_irq_save(flags);
5618+ __asm__ __volatile__(
5619+#ifdef CONFIG_PAX_REFCOUNT
5620+ /* Exception on overflow. */
5621+ "1: sub %0, %1 \n"
5622+ "2: \n"
5623+ _ASM_EXTABLE(1b, 2b)
5624+#else
5625+ " subu %0, %1 \n"
5626+#endif
5627+ : "+r" (v->counter) : "Ir" (i));
5628+ raw_local_irq_restore(flags);
5629+ }
5630+}
5631+
5632+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5633 {
5634 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5635 int temp;
5636@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5637 /*
5638 * Same as above, but return the result value
5639 */
5640-static __inline__ int atomic_add_return(int i, atomic_t * v)
5641+static __inline__ int atomic_add_return(int i, atomic_t *v)
5642+{
5643+ int result;
5644+ int temp;
5645+
5646+ smp_mb__before_llsc();
5647+
5648+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5649+ __asm__ __volatile__(
5650+ " .set mips3 \n"
5651+ "1: ll %1, %2 # atomic_add_return \n"
5652+#ifdef CONFIG_PAX_REFCOUNT
5653+ "2: add %0, %1, %3 \n"
5654+#else
5655+ " addu %0, %1, %3 \n"
5656+#endif
5657+ " sc %0, %2 \n"
5658+ " beqzl %0, 1b \n"
5659+#ifdef CONFIG_PAX_REFCOUNT
5660+ " b 4f \n"
5661+ " .set noreorder \n"
5662+ "3: b 5f \n"
5663+ " move %0, %1 \n"
5664+ " .set reorder \n"
5665+ _ASM_EXTABLE(2b, 3b)
5666+#endif
5667+ "4: addu %0, %1, %3 \n"
5668+#ifdef CONFIG_PAX_REFCOUNT
5669+ "5: \n"
5670+#endif
5671+ " .set mips0 \n"
5672+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5673+ : "Ir" (i));
5674+ } else if (kernel_uses_llsc) {
5675+ __asm__ __volatile__(
5676+ " .set mips3 \n"
5677+ "1: ll %1, %2 # atomic_add_return \n"
5678+#ifdef CONFIG_PAX_REFCOUNT
5679+ "2: add %0, %1, %3 \n"
5680+#else
5681+ " addu %0, %1, %3 \n"
5682+#endif
5683+ " sc %0, %2 \n"
5684+ " bnez %0, 4f \n"
5685+ " b 1b \n"
5686+#ifdef CONFIG_PAX_REFCOUNT
5687+ " .set noreorder \n"
5688+ "3: b 5f \n"
5689+ " move %0, %1 \n"
5690+ " .set reorder \n"
5691+ _ASM_EXTABLE(2b, 3b)
5692+#endif
5693+ "4: addu %0, %1, %3 \n"
5694+#ifdef CONFIG_PAX_REFCOUNT
5695+ "5: \n"
5696+#endif
5697+ " .set mips0 \n"
5698+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5699+ : "Ir" (i));
5700+ } else {
5701+ unsigned long flags;
5702+
5703+ raw_local_irq_save(flags);
5704+ __asm__ __volatile__(
5705+ " lw %0, %1 \n"
5706+#ifdef CONFIG_PAX_REFCOUNT
5707+ /* Exception on overflow. */
5708+ "1: add %0, %2 \n"
5709+#else
5710+ " addu %0, %2 \n"
5711+#endif
5712+ " sw %0, %1 \n"
5713+#ifdef CONFIG_PAX_REFCOUNT
5714+ /* Note: Dest reg is not modified on overflow */
5715+ "2: \n"
5716+ _ASM_EXTABLE(1b, 2b)
5717+#endif
5718+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5719+ raw_local_irq_restore(flags);
5720+ }
5721+
5722+ smp_llsc_mb();
5723+
5724+ return result;
5725+}
5726+
5727+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5728 {
5729 int result;
5730
5731@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5732 return result;
5733 }
5734
5735-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5736+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5737+{
5738+ int result;
5739+ int temp;
5740+
5741+ smp_mb__before_llsc();
5742+
5743+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5744+ __asm__ __volatile__(
5745+ " .set mips3 \n"
5746+ "1: ll %1, %2 # atomic_sub_return \n"
5747+#ifdef CONFIG_PAX_REFCOUNT
5748+ "2: sub %0, %1, %3 \n"
5749+#else
5750+ " subu %0, %1, %3 \n"
5751+#endif
5752+ " sc %0, %2 \n"
5753+ " beqzl %0, 1b \n"
5754+#ifdef CONFIG_PAX_REFCOUNT
5755+ " b 4f \n"
5756+ " .set noreorder \n"
5757+ "3: b 5f \n"
5758+ " move %0, %1 \n"
5759+ " .set reorder \n"
5760+ _ASM_EXTABLE(2b, 3b)
5761+#endif
5762+ "4: subu %0, %1, %3 \n"
5763+#ifdef CONFIG_PAX_REFCOUNT
5764+ "5: \n"
5765+#endif
5766+ " .set mips0 \n"
5767+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5768+ : "Ir" (i), "m" (v->counter)
5769+ : "memory");
5770+ } else if (kernel_uses_llsc) {
5771+ __asm__ __volatile__(
5772+ " .set mips3 \n"
5773+ "1: ll %1, %2 # atomic_sub_return \n"
5774+#ifdef CONFIG_PAX_REFCOUNT
5775+ "2: sub %0, %1, %3 \n"
5776+#else
5777+ " subu %0, %1, %3 \n"
5778+#endif
5779+ " sc %0, %2 \n"
5780+ " bnez %0, 4f \n"
5781+ " b 1b \n"
5782+#ifdef CONFIG_PAX_REFCOUNT
5783+ " .set noreorder \n"
5784+ "3: b 5f \n"
5785+ " move %0, %1 \n"
5786+ " .set reorder \n"
5787+ _ASM_EXTABLE(2b, 3b)
5788+#endif
5789+ "4: subu %0, %1, %3 \n"
5790+#ifdef CONFIG_PAX_REFCOUNT
5791+ "5: \n"
5792+#endif
5793+ " .set mips0 \n"
5794+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5795+ : "Ir" (i));
5796+ } else {
5797+ unsigned long flags;
5798+
5799+ raw_local_irq_save(flags);
5800+ __asm__ __volatile__(
5801+ " lw %0, %1 \n"
5802+#ifdef CONFIG_PAX_REFCOUNT
5803+ /* Exception on overflow. */
5804+ "1: sub %0, %2 \n"
5805+#else
5806+ " subu %0, %2 \n"
5807+#endif
5808+ " sw %0, %1 \n"
5809+#ifdef CONFIG_PAX_REFCOUNT
5810+ /* Note: Dest reg is not modified on overflow */
5811+ "2: \n"
5812+ _ASM_EXTABLE(1b, 2b)
5813+#endif
5814+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5815+ raw_local_irq_restore(flags);
5816+ }
5817+
5818+ smp_llsc_mb();
5819+
5820+ return result;
5821+}
5822+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5823 {
5824 int result;
5825
5826@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5827 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5828 * The function returns the old value of @v minus @i.
5829 */
5830-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5831+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5832 {
5833 int result;
5834
5835@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5836 return result;
5837 }
5838
5839-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5840-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5841+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5842+{
5843+ return cmpxchg(&v->counter, old, new);
5844+}
5845+
5846+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5847+ int new)
5848+{
5849+ return cmpxchg(&(v->counter), old, new);
5850+}
5851+
5852+static inline int atomic_xchg(atomic_t *v, int new)
5853+{
5854+ return xchg(&v->counter, new);
5855+}
5856+
5857+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5858+{
5859+ return xchg(&(v->counter), new);
5860+}
5861
5862 /**
5863 * __atomic_add_unless - add unless the number is a given value
5864@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5865
5866 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5867 #define atomic_inc_return(v) atomic_add_return(1, (v))
5868+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5869+{
5870+ return atomic_add_return_unchecked(1, v);
5871+}
5872
5873 /*
5874 * atomic_sub_and_test - subtract value from variable and test result
5875@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5876 * other cases.
5877 */
5878 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5879+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5880+{
5881+ return atomic_add_return_unchecked(1, v) == 0;
5882+}
5883
5884 /*
5885 * atomic_dec_and_test - decrement by 1 and test
5886@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5887 * Atomically increments @v by 1.
5888 */
5889 #define atomic_inc(v) atomic_add(1, (v))
5890+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5891+{
5892+ atomic_add_unchecked(1, v);
5893+}
5894
5895 /*
5896 * atomic_dec - decrement and test
5897@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5898 * Atomically decrements @v by 1.
5899 */
5900 #define atomic_dec(v) atomic_sub(1, (v))
5901+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5902+{
5903+ atomic_sub_unchecked(1, v);
5904+}
5905
5906 /*
5907 * atomic_add_negative - add and test if negative
5908@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5909 * @v: pointer of type atomic64_t
5910 *
5911 */
5912-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5913+static inline long atomic64_read(const atomic64_t *v)
5914+{
5915+ return (*(volatile const long *) &v->counter);
5916+}
5917+
5918+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5919+{
5920+ return (*(volatile const long *) &v->counter);
5921+}
5922
5923 /*
5924 * atomic64_set - set atomic variable
5925 * @v: pointer of type atomic64_t
5926 * @i: required value
5927 */
5928-#define atomic64_set(v, i) ((v)->counter = (i))
5929+static inline void atomic64_set(atomic64_t *v, long i)
5930+{
5931+ v->counter = i;
5932+}
5933+
5934+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5935+{
5936+ v->counter = i;
5937+}
5938
5939 /*
5940 * atomic64_add - add integer to atomic variable
5941@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5942 *
5943 * Atomically adds @i to @v.
5944 */
5945-static __inline__ void atomic64_add(long i, atomic64_t * v)
5946+static __inline__ void atomic64_add(long i, atomic64_t *v)
5947+{
5948+ long temp;
5949+
5950+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5951+ __asm__ __volatile__(
5952+ " .set mips3 \n"
5953+ "1: lld %0, %1 # atomic64_add \n"
5954+#ifdef CONFIG_PAX_REFCOUNT
5955+ /* Exception on overflow. */
5956+ "2: dadd %0, %2 \n"
5957+#else
5958+ " daddu %0, %2 \n"
5959+#endif
5960+ " scd %0, %1 \n"
5961+ " beqzl %0, 1b \n"
5962+#ifdef CONFIG_PAX_REFCOUNT
5963+ "3: \n"
5964+ _ASM_EXTABLE(2b, 3b)
5965+#endif
5966+ " .set mips0 \n"
5967+ : "=&r" (temp), "+m" (v->counter)
5968+ : "Ir" (i));
5969+ } else if (kernel_uses_llsc) {
5970+ __asm__ __volatile__(
5971+ " .set mips3 \n"
5972+ "1: lld %0, %1 # atomic64_add \n"
5973+#ifdef CONFIG_PAX_REFCOUNT
5974+ /* Exception on overflow. */
5975+ "2: dadd %0, %2 \n"
5976+#else
5977+ " daddu %0, %2 \n"
5978+#endif
5979+ " scd %0, %1 \n"
5980+ " beqz %0, 1b \n"
5981+#ifdef CONFIG_PAX_REFCOUNT
5982+ "3: \n"
5983+ _ASM_EXTABLE(2b, 3b)
5984+#endif
5985+ " .set mips0 \n"
5986+ : "=&r" (temp), "+m" (v->counter)
5987+ : "Ir" (i));
5988+ } else {
5989+ unsigned long flags;
5990+
5991+ raw_local_irq_save(flags);
5992+ __asm__ __volatile__(
5993+#ifdef CONFIG_PAX_REFCOUNT
5994+ /* Exception on overflow. */
5995+ "1: dadd %0, %1 \n"
5996+ "2: \n"
5997+ _ASM_EXTABLE(1b, 2b)
5998+#else
5999+ " daddu %0, %1 \n"
6000+#endif
6001+ : "+r" (v->counter) : "Ir" (i));
6002+ raw_local_irq_restore(flags);
6003+ }
6004+}
6005+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6006 {
6007 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6008 long temp;
6009@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6010 *
6011 * Atomically subtracts @i from @v.
6012 */
6013-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6014+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6015+{
6016+ long temp;
6017+
6018+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6019+ __asm__ __volatile__(
6020+ " .set mips3 \n"
6021+ "1: lld %0, %1 # atomic64_sub \n"
6022+#ifdef CONFIG_PAX_REFCOUNT
6023+ /* Exception on overflow. */
6024+ "2: dsub %0, %2 \n"
6025+#else
6026+ " dsubu %0, %2 \n"
6027+#endif
6028+ " scd %0, %1 \n"
6029+ " beqzl %0, 1b \n"
6030+#ifdef CONFIG_PAX_REFCOUNT
6031+ "3: \n"
6032+ _ASM_EXTABLE(2b, 3b)
6033+#endif
6034+ " .set mips0 \n"
6035+ : "=&r" (temp), "+m" (v->counter)
6036+ : "Ir" (i));
6037+ } else if (kernel_uses_llsc) {
6038+ __asm__ __volatile__(
6039+ " .set mips3 \n"
6040+ "1: lld %0, %1 # atomic64_sub \n"
6041+#ifdef CONFIG_PAX_REFCOUNT
6042+ /* Exception on overflow. */
6043+ "2: dsub %0, %2 \n"
6044+#else
6045+ " dsubu %0, %2 \n"
6046+#endif
6047+ " scd %0, %1 \n"
6048+ " beqz %0, 1b \n"
6049+#ifdef CONFIG_PAX_REFCOUNT
6050+ "3: \n"
6051+ _ASM_EXTABLE(2b, 3b)
6052+#endif
6053+ " .set mips0 \n"
6054+ : "=&r" (temp), "+m" (v->counter)
6055+ : "Ir" (i));
6056+ } else {
6057+ unsigned long flags;
6058+
6059+ raw_local_irq_save(flags);
6060+ __asm__ __volatile__(
6061+#ifdef CONFIG_PAX_REFCOUNT
6062+ /* Exception on overflow. */
6063+ "1: dsub %0, %1 \n"
6064+ "2: \n"
6065+ _ASM_EXTABLE(1b, 2b)
6066+#else
6067+ " dsubu %0, %1 \n"
6068+#endif
6069+ : "+r" (v->counter) : "Ir" (i));
6070+ raw_local_irq_restore(flags);
6071+ }
6072+}
6073+
6074+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6075 {
6076 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6077 long temp;
6078@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6079 /*
6080 * Same as above, but return the result value
6081 */
6082-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6083+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6084+{
6085+ long result;
6086+ long temp;
6087+
6088+ smp_mb__before_llsc();
6089+
6090+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6091+ __asm__ __volatile__(
6092+ " .set mips3 \n"
6093+ "1: lld %1, %2 # atomic64_add_return \n"
6094+#ifdef CONFIG_PAX_REFCOUNT
6095+ "2: dadd %0, %1, %3 \n"
6096+#else
6097+ " daddu %0, %1, %3 \n"
6098+#endif
6099+ " scd %0, %2 \n"
6100+ " beqzl %0, 1b \n"
6101+#ifdef CONFIG_PAX_REFCOUNT
6102+ " b 4f \n"
6103+ " .set noreorder \n"
6104+ "3: b 5f \n"
6105+ " move %0, %1 \n"
6106+ " .set reorder \n"
6107+ _ASM_EXTABLE(2b, 3b)
6108+#endif
6109+ "4: daddu %0, %1, %3 \n"
6110+#ifdef CONFIG_PAX_REFCOUNT
6111+ "5: \n"
6112+#endif
6113+ " .set mips0 \n"
6114+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6115+ : "Ir" (i));
6116+ } else if (kernel_uses_llsc) {
6117+ __asm__ __volatile__(
6118+ " .set mips3 \n"
6119+ "1: lld %1, %2 # atomic64_add_return \n"
6120+#ifdef CONFIG_PAX_REFCOUNT
6121+ "2: dadd %0, %1, %3 \n"
6122+#else
6123+ " daddu %0, %1, %3 \n"
6124+#endif
6125+ " scd %0, %2 \n"
6126+ " bnez %0, 4f \n"
6127+ " b 1b \n"
6128+#ifdef CONFIG_PAX_REFCOUNT
6129+ " .set noreorder \n"
6130+ "3: b 5f \n"
6131+ " move %0, %1 \n"
6132+ " .set reorder \n"
6133+ _ASM_EXTABLE(2b, 3b)
6134+#endif
6135+ "4: daddu %0, %1, %3 \n"
6136+#ifdef CONFIG_PAX_REFCOUNT
6137+ "5: \n"
6138+#endif
6139+ " .set mips0 \n"
6140+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6141+ : "Ir" (i), "m" (v->counter)
6142+ : "memory");
6143+ } else {
6144+ unsigned long flags;
6145+
6146+ raw_local_irq_save(flags);
6147+ __asm__ __volatile__(
6148+ " ld %0, %1 \n"
6149+#ifdef CONFIG_PAX_REFCOUNT
6150+ /* Exception on overflow. */
6151+ "1: dadd %0, %2 \n"
6152+#else
6153+ " daddu %0, %2 \n"
6154+#endif
6155+ " sd %0, %1 \n"
6156+#ifdef CONFIG_PAX_REFCOUNT
6157+ /* Note: Dest reg is not modified on overflow */
6158+ "2: \n"
6159+ _ASM_EXTABLE(1b, 2b)
6160+#endif
6161+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6162+ raw_local_irq_restore(flags);
6163+ }
6164+
6165+ smp_llsc_mb();
6166+
6167+ return result;
6168+}
6169+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6170 {
6171 long result;
6172
6173@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6174 return result;
6175 }
6176
6177-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6178+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6179+{
6180+ long result;
6181+ long temp;
6182+
6183+ smp_mb__before_llsc();
6184+
6185+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6186+ long temp;
6187+
6188+ __asm__ __volatile__(
6189+ " .set mips3 \n"
6190+ "1: lld %1, %2 # atomic64_sub_return \n"
6191+#ifdef CONFIG_PAX_REFCOUNT
6192+ "2: dsub %0, %1, %3 \n"
6193+#else
6194+ " dsubu %0, %1, %3 \n"
6195+#endif
6196+ " scd %0, %2 \n"
6197+ " beqzl %0, 1b \n"
6198+#ifdef CONFIG_PAX_REFCOUNT
6199+ " b 4f \n"
6200+ " .set noreorder \n"
6201+ "3: b 5f \n"
6202+ " move %0, %1 \n"
6203+ " .set reorder \n"
6204+ _ASM_EXTABLE(2b, 3b)
6205+#endif
6206+ "4: dsubu %0, %1, %3 \n"
6207+#ifdef CONFIG_PAX_REFCOUNT
6208+ "5: \n"
6209+#endif
6210+ " .set mips0 \n"
6211+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6212+ : "Ir" (i), "m" (v->counter)
6213+ : "memory");
6214+ } else if (kernel_uses_llsc) {
6215+ __asm__ __volatile__(
6216+ " .set mips3 \n"
6217+ "1: lld %1, %2 # atomic64_sub_return \n"
6218+#ifdef CONFIG_PAX_REFCOUNT
6219+ "2: dsub %0, %1, %3 \n"
6220+#else
6221+ " dsubu %0, %1, %3 \n"
6222+#endif
6223+ " scd %0, %2 \n"
6224+ " bnez %0, 4f \n"
6225+ " b 1b \n"
6226+#ifdef CONFIG_PAX_REFCOUNT
6227+ " .set noreorder \n"
6228+ "3: b 5f \n"
6229+ " move %0, %1 \n"
6230+ " .set reorder \n"
6231+ _ASM_EXTABLE(2b, 3b)
6232+#endif
6233+ "4: dsubu %0, %1, %3 \n"
6234+#ifdef CONFIG_PAX_REFCOUNT
6235+ "5: \n"
6236+#endif
6237+ " .set mips0 \n"
6238+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6239+ : "Ir" (i), "m" (v->counter)
6240+ : "memory");
6241+ } else {
6242+ unsigned long flags;
6243+
6244+ raw_local_irq_save(flags);
6245+ __asm__ __volatile__(
6246+ " ld %0, %1 \n"
6247+#ifdef CONFIG_PAX_REFCOUNT
6248+ /* Exception on overflow. */
6249+ "1: dsub %0, %2 \n"
6250+#else
6251+ " dsubu %0, %2 \n"
6252+#endif
6253+ " sd %0, %1 \n"
6254+#ifdef CONFIG_PAX_REFCOUNT
6255+ /* Note: Dest reg is not modified on overflow */
6256+ "2: \n"
6257+ _ASM_EXTABLE(1b, 2b)
6258+#endif
6259+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6260+ raw_local_irq_restore(flags);
6261+ }
6262+
6263+ smp_llsc_mb();
6264+
6265+ return result;
6266+}
6267+
6268+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6269 {
6270 long result;
6271
6272@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6273 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6274 * The function returns the old value of @v minus @i.
6275 */
6276-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6277+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6278 {
6279 long result;
6280
6281@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6282 return result;
6283 }
6284
6285-#define atomic64_cmpxchg(v, o, n) \
6286- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6287-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6288+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6289+{
6290+ return cmpxchg(&v->counter, old, new);
6291+}
6292+
6293+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6294+ long new)
6295+{
6296+ return cmpxchg(&(v->counter), old, new);
6297+}
6298+
6299+static inline long atomic64_xchg(atomic64_t *v, long new)
6300+{
6301+ return xchg(&v->counter, new);
6302+}
6303+
6304+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6305+{
6306+ return xchg(&(v->counter), new);
6307+}
6308
6309 /**
6310 * atomic64_add_unless - add unless the number is a given value
6311@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6312
6313 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6314 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6315+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6316
6317 /*
6318 * atomic64_sub_and_test - subtract value from variable and test result
6319@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6320 * other cases.
6321 */
6322 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6323+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6324
6325 /*
6326 * atomic64_dec_and_test - decrement by 1 and test
6327@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6328 * Atomically increments @v by 1.
6329 */
6330 #define atomic64_inc(v) atomic64_add(1, (v))
6331+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6332
6333 /*
6334 * atomic64_dec - decrement and test
6335@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6336 * Atomically decrements @v by 1.
6337 */
6338 #define atomic64_dec(v) atomic64_sub(1, (v))
6339+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6340
6341 /*
6342 * atomic64_add_negative - add and test if negative
6343diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6344index b4db69f..8f3b093 100644
6345--- a/arch/mips/include/asm/cache.h
6346+++ b/arch/mips/include/asm/cache.h
6347@@ -9,10 +9,11 @@
6348 #ifndef _ASM_CACHE_H
6349 #define _ASM_CACHE_H
6350
6351+#include <linux/const.h>
6352 #include <kmalloc.h>
6353
6354 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6355-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6356+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6357
6358 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6359 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6360diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6361index cf3ae24..238d22f 100644
6362--- a/arch/mips/include/asm/elf.h
6363+++ b/arch/mips/include/asm/elf.h
6364@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6365 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6366 #endif
6367
6368+#ifdef CONFIG_PAX_ASLR
6369+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6370+
6371+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6372+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6373+#endif
6374+
6375 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6376 struct linux_binprm;
6377 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6378 int uses_interp);
6379
6380-struct mm_struct;
6381-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6382-#define arch_randomize_brk arch_randomize_brk
6383-
6384 #endif /* _ASM_ELF_H */
6385diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6386index c1f6afa..38cc6e9 100644
6387--- a/arch/mips/include/asm/exec.h
6388+++ b/arch/mips/include/asm/exec.h
6389@@ -12,6 +12,6 @@
6390 #ifndef _ASM_EXEC_H
6391 #define _ASM_EXEC_H
6392
6393-extern unsigned long arch_align_stack(unsigned long sp);
6394+#define arch_align_stack(x) ((x) & ~0xfUL)
6395
6396 #endif /* _ASM_EXEC_H */
6397diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6398index d44622c..64990d2 100644
6399--- a/arch/mips/include/asm/local.h
6400+++ b/arch/mips/include/asm/local.h
6401@@ -12,15 +12,25 @@ typedef struct
6402 atomic_long_t a;
6403 } local_t;
6404
6405+typedef struct {
6406+ atomic_long_unchecked_t a;
6407+} local_unchecked_t;
6408+
6409 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6410
6411 #define local_read(l) atomic_long_read(&(l)->a)
6412+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6413 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6414+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6415
6416 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6417+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6418 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6419+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6420 #define local_inc(l) atomic_long_inc(&(l)->a)
6421+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6422 #define local_dec(l) atomic_long_dec(&(l)->a)
6423+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6424
6425 /*
6426 * Same as above, but return the result value
6427@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6428 return result;
6429 }
6430
6431+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6432+{
6433+ unsigned long result;
6434+
6435+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6436+ unsigned long temp;
6437+
6438+ __asm__ __volatile__(
6439+ " .set mips3 \n"
6440+ "1:" __LL "%1, %2 # local_add_return \n"
6441+ " addu %0, %1, %3 \n"
6442+ __SC "%0, %2 \n"
6443+ " beqzl %0, 1b \n"
6444+ " addu %0, %1, %3 \n"
6445+ " .set mips0 \n"
6446+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6447+ : "Ir" (i), "m" (l->a.counter)
6448+ : "memory");
6449+ } else if (kernel_uses_llsc) {
6450+ unsigned long temp;
6451+
6452+ __asm__ __volatile__(
6453+ " .set mips3 \n"
6454+ "1:" __LL "%1, %2 # local_add_return \n"
6455+ " addu %0, %1, %3 \n"
6456+ __SC "%0, %2 \n"
6457+ " beqz %0, 1b \n"
6458+ " addu %0, %1, %3 \n"
6459+ " .set mips0 \n"
6460+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6461+ : "Ir" (i), "m" (l->a.counter)
6462+ : "memory");
6463+ } else {
6464+ unsigned long flags;
6465+
6466+ local_irq_save(flags);
6467+ result = l->a.counter;
6468+ result += i;
6469+ l->a.counter = result;
6470+ local_irq_restore(flags);
6471+ }
6472+
6473+ return result;
6474+}
6475+
6476 static __inline__ long local_sub_return(long i, local_t * l)
6477 {
6478 unsigned long result;
6479@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6480
6481 #define local_cmpxchg(l, o, n) \
6482 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6483+#define local_cmpxchg_unchecked(l, o, n) \
6484+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6485 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6486
6487 /**
6488diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6489index f59552f..3abe9b9 100644
6490--- a/arch/mips/include/asm/page.h
6491+++ b/arch/mips/include/asm/page.h
6492@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6493 #ifdef CONFIG_CPU_MIPS32
6494 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6495 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6496- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6497+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6498 #else
6499 typedef struct { unsigned long long pte; } pte_t;
6500 #define pte_val(x) ((x).pte)
6501diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6502index 881d18b..cea38bc 100644
6503--- a/arch/mips/include/asm/pgalloc.h
6504+++ b/arch/mips/include/asm/pgalloc.h
6505@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6506 {
6507 set_pud(pud, __pud((unsigned long)pmd));
6508 }
6509+
6510+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6511+{
6512+ pud_populate(mm, pud, pmd);
6513+}
6514 #endif
6515
6516 /*
6517diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6518index 895320e..bf63e10 100644
6519--- a/arch/mips/include/asm/thread_info.h
6520+++ b/arch/mips/include/asm/thread_info.h
6521@@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
6522 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6523 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6524 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6525+/* li takes a 32bit immediate */
6526+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6527 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6528
6529 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6530@@ -130,15 +132,18 @@ static inline struct thread_info *current_thread_info(void)
6531 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6532 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6533 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6534+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6535+
6536+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6537
6538 /* work to do in syscall_trace_leave() */
6539-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
6540+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6541
6542 /* work to do on interrupt/exception return */
6543 #define _TIF_WORK_MASK \
6544 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6545 /* work to do on any return to u-space */
6546-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
6547+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6548
6549 #endif /* __KERNEL__ */
6550
6551diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6552index 1188e00..41cf144 100644
6553--- a/arch/mips/kernel/binfmt_elfn32.c
6554+++ b/arch/mips/kernel/binfmt_elfn32.c
6555@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6556 #undef ELF_ET_DYN_BASE
6557 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6558
6559+#ifdef CONFIG_PAX_ASLR
6560+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6561+
6562+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6563+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6564+#endif
6565+
6566 #include <asm/processor.h>
6567 #include <linux/module.h>
6568 #include <linux/elfcore.h>
6569diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6570index 202e581..689ca79 100644
6571--- a/arch/mips/kernel/binfmt_elfo32.c
6572+++ b/arch/mips/kernel/binfmt_elfo32.c
6573@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6574 #undef ELF_ET_DYN_BASE
6575 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6576
6577+#ifdef CONFIG_PAX_ASLR
6578+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6579+
6580+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6581+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6582+#endif
6583+
6584 #include <asm/processor.h>
6585
6586 /*
6587diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6588index d1fea7a..45602ea 100644
6589--- a/arch/mips/kernel/irq.c
6590+++ b/arch/mips/kernel/irq.c
6591@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6592 printk("unexpected IRQ # %d\n", irq);
6593 }
6594
6595-atomic_t irq_err_count;
6596+atomic_unchecked_t irq_err_count;
6597
6598 int arch_show_interrupts(struct seq_file *p, int prec)
6599 {
6600- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6601+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6602 return 0;
6603 }
6604
6605 asmlinkage void spurious_interrupt(void)
6606 {
6607- atomic_inc(&irq_err_count);
6608+ atomic_inc_unchecked(&irq_err_count);
6609 }
6610
6611 void __init init_IRQ(void)
6612diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6613index c6a041d..b3e7318 100644
6614--- a/arch/mips/kernel/process.c
6615+++ b/arch/mips/kernel/process.c
6616@@ -563,15 +563,3 @@ unsigned long get_wchan(struct task_struct *task)
6617 out:
6618 return pc;
6619 }
6620-
6621-/*
6622- * Don't forget that the stack pointer must be aligned on a 8 bytes
6623- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6624- */
6625-unsigned long arch_align_stack(unsigned long sp)
6626-{
6627- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6628- sp -= get_random_int() & ~PAGE_MASK;
6629-
6630- return sp & ALMASK;
6631-}
6632diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6633index 9c6299c..2fb4c22 100644
6634--- a/arch/mips/kernel/ptrace.c
6635+++ b/arch/mips/kernel/ptrace.c
6636@@ -528,6 +528,10 @@ static inline int audit_arch(void)
6637 return arch;
6638 }
6639
6640+#ifdef CONFIG_GRKERNSEC_SETXID
6641+extern void gr_delayed_cred_worker(void);
6642+#endif
6643+
6644 /*
6645 * Notification of system call entry/exit
6646 * - triggered by current->work.syscall_trace
6647@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6648 /* do the secure computing check first */
6649 secure_computing_strict(regs->regs[2]);
6650
6651+#ifdef CONFIG_GRKERNSEC_SETXID
6652+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6653+ gr_delayed_cred_worker();
6654+#endif
6655+
6656 if (!(current->ptrace & PT_PTRACED))
6657 goto out;
6658
6659diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
6660index 9b36424..e7f4154 100644
6661--- a/arch/mips/kernel/scall32-o32.S
6662+++ b/arch/mips/kernel/scall32-o32.S
6663@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
6664
6665 stack_done:
6666 lw t0, TI_FLAGS($28) # syscall tracing enabled?
6667- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
6668+ li t1, _TIF_SYSCALL_WORK
6669 and t0, t1
6670 bnez t0, syscall_trace_entry # -> yes
6671
6672diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
6673index 97a5909..59622f8 100644
6674--- a/arch/mips/kernel/scall64-64.S
6675+++ b/arch/mips/kernel/scall64-64.S
6676@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
6677
6678 sd a3, PT_R26(sp) # save a3 for syscall restarting
6679
6680- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
6681+ li t1, _TIF_SYSCALL_WORK
6682 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
6683 and t0, t1, t0
6684 bnez t0, syscall_trace_entry
6685diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
6686index edcb659..fb2ab09 100644
6687--- a/arch/mips/kernel/scall64-n32.S
6688+++ b/arch/mips/kernel/scall64-n32.S
6689@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
6690
6691 sd a3, PT_R26(sp) # save a3 for syscall restarting
6692
6693- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
6694+ li t1, _TIF_SYSCALL_WORK
6695 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
6696 and t0, t1, t0
6697 bnez t0, n32_syscall_trace_entry
6698diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
6699index 74f485d..47d2c38 100644
6700--- a/arch/mips/kernel/scall64-o32.S
6701+++ b/arch/mips/kernel/scall64-o32.S
6702@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
6703 PTR 4b, bad_stack
6704 .previous
6705
6706- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
6707+ li t1, _TIF_SYSCALL_WORK
6708 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
6709 and t0, t1, t0
6710 bnez t0, trace_a_syscall
6711diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6712index 1ff43d5..96fec68 100644
6713--- a/arch/mips/kernel/sync-r4k.c
6714+++ b/arch/mips/kernel/sync-r4k.c
6715@@ -21,8 +21,8 @@
6716 #include <asm/mipsregs.h>
6717
6718 static atomic_t __cpuinitdata count_start_flag = ATOMIC_INIT(0);
6719-static atomic_t __cpuinitdata count_count_start = ATOMIC_INIT(0);
6720-static atomic_t __cpuinitdata count_count_stop = ATOMIC_INIT(0);
6721+static atomic_unchecked_t __cpuinitdata count_count_start = ATOMIC_INIT(0);
6722+static atomic_unchecked_t __cpuinitdata count_count_stop = ATOMIC_INIT(0);
6723 static atomic_t __cpuinitdata count_reference = ATOMIC_INIT(0);
6724
6725 #define COUNTON 100
6726@@ -69,13 +69,13 @@ void __cpuinit synchronise_count_master(int cpu)
6727
6728 for (i = 0; i < NR_LOOPS; i++) {
6729 /* slaves loop on '!= 2' */
6730- while (atomic_read(&count_count_start) != 1)
6731+ while (atomic_read_unchecked(&count_count_start) != 1)
6732 mb();
6733- atomic_set(&count_count_stop, 0);
6734+ atomic_set_unchecked(&count_count_stop, 0);
6735 smp_wmb();
6736
6737 /* this lets the slaves write their count register */
6738- atomic_inc(&count_count_start);
6739+ atomic_inc_unchecked(&count_count_start);
6740
6741 /*
6742 * Everyone initialises count in the last loop:
6743@@ -86,11 +86,11 @@ void __cpuinit synchronise_count_master(int cpu)
6744 /*
6745 * Wait for all slaves to leave the synchronization point:
6746 */
6747- while (atomic_read(&count_count_stop) != 1)
6748+ while (atomic_read_unchecked(&count_count_stop) != 1)
6749 mb();
6750- atomic_set(&count_count_start, 0);
6751+ atomic_set_unchecked(&count_count_start, 0);
6752 smp_wmb();
6753- atomic_inc(&count_count_stop);
6754+ atomic_inc_unchecked(&count_count_stop);
6755 }
6756 /* Arrange for an interrupt in a short while */
6757 write_c0_compare(read_c0_count() + COUNTON);
6758@@ -131,8 +131,8 @@ void __cpuinit synchronise_count_slave(int cpu)
6759 initcount = atomic_read(&count_reference);
6760
6761 for (i = 0; i < NR_LOOPS; i++) {
6762- atomic_inc(&count_count_start);
6763- while (atomic_read(&count_count_start) != 2)
6764+ atomic_inc_unchecked(&count_count_start);
6765+ while (atomic_read_unchecked(&count_count_start) != 2)
6766 mb();
6767
6768 /*
6769@@ -141,8 +141,8 @@ void __cpuinit synchronise_count_slave(int cpu)
6770 if (i == NR_LOOPS-1)
6771 write_c0_count(initcount);
6772
6773- atomic_inc(&count_count_stop);
6774- while (atomic_read(&count_count_stop) != 2)
6775+ atomic_inc_unchecked(&count_count_stop);
6776+ while (atomic_read_unchecked(&count_count_stop) != 2)
6777 mb();
6778 }
6779 /* Arrange for an interrupt in a short while */
6780diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6781index a75ae40..0d0f56a 100644
6782--- a/arch/mips/kernel/traps.c
6783+++ b/arch/mips/kernel/traps.c
6784@@ -675,7 +675,17 @@ asmlinkage void do_ov(struct pt_regs *regs)
6785 {
6786 siginfo_t info;
6787
6788- die_if_kernel("Integer overflow", regs);
6789+ if (unlikely(!user_mode(regs))) {
6790+
6791+#ifdef CONFIG_PAX_REFCOUNT
6792+ if (fixup_exception(regs)) {
6793+ pax_report_refcount_overflow(regs);
6794+ return;
6795+ }
6796+#endif
6797+
6798+ die("Integer overflow", regs);
6799+ }
6800
6801 info.si_code = FPE_INTOVF;
6802 info.si_signo = SIGFPE;
6803diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6804index 0fead53..eeb00a6 100644
6805--- a/arch/mips/mm/fault.c
6806+++ b/arch/mips/mm/fault.c
6807@@ -27,6 +27,23 @@
6808 #include <asm/highmem.h> /* For VMALLOC_END */
6809 #include <linux/kdebug.h>
6810
6811+#ifdef CONFIG_PAX_PAGEEXEC
6812+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6813+{
6814+ unsigned long i;
6815+
6816+ printk(KERN_ERR "PAX: bytes at PC: ");
6817+ for (i = 0; i < 5; i++) {
6818+ unsigned int c;
6819+ if (get_user(c, (unsigned int *)pc+i))
6820+ printk(KERN_CONT "???????? ");
6821+ else
6822+ printk(KERN_CONT "%08x ", c);
6823+ }
6824+ printk("\n");
6825+}
6826+#endif
6827+
6828 /*
6829 * This routine handles page faults. It determines the address,
6830 * and the problem, and then passes it off to one of the appropriate
6831@@ -196,6 +213,14 @@ bad_area:
6832 bad_area_nosemaphore:
6833 /* User mode accesses just cause a SIGSEGV */
6834 if (user_mode(regs)) {
6835+
6836+#ifdef CONFIG_PAX_PAGEEXEC
6837+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6838+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6839+ do_group_exit(SIGKILL);
6840+ }
6841+#endif
6842+
6843 tsk->thread.cp0_badvaddr = address;
6844 tsk->thread.error_code = write;
6845 #if 0
6846diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6847index 7e5fe27..9656513 100644
6848--- a/arch/mips/mm/mmap.c
6849+++ b/arch/mips/mm/mmap.c
6850@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6851 struct vm_area_struct *vma;
6852 unsigned long addr = addr0;
6853 int do_color_align;
6854+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6855 struct vm_unmapped_area_info info;
6856
6857 if (unlikely(len > TASK_SIZE))
6858@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6859 do_color_align = 1;
6860
6861 /* requesting a specific address */
6862+
6863+#ifdef CONFIG_PAX_RANDMMAP
6864+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6865+#endif
6866+
6867 if (addr) {
6868 if (do_color_align)
6869 addr = COLOUR_ALIGN(addr, pgoff);
6870@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6871 addr = PAGE_ALIGN(addr);
6872
6873 vma = find_vma(mm, addr);
6874- if (TASK_SIZE - len >= addr &&
6875- (!vma || addr + len <= vma->vm_start))
6876+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6877 return addr;
6878 }
6879
6880 info.length = len;
6881 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6882 info.align_offset = pgoff << PAGE_SHIFT;
6883+ info.threadstack_offset = offset;
6884
6885 if (dir == DOWN) {
6886 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6887@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6888 {
6889 unsigned long random_factor = 0UL;
6890
6891+#ifdef CONFIG_PAX_RANDMMAP
6892+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6893+#endif
6894+
6895 if (current->flags & PF_RANDOMIZE) {
6896 random_factor = get_random_int();
6897 random_factor = random_factor << PAGE_SHIFT;
6898@@ -157,42 +167,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6899
6900 if (mmap_is_legacy()) {
6901 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6902+
6903+#ifdef CONFIG_PAX_RANDMMAP
6904+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6905+ mm->mmap_base += mm->delta_mmap;
6906+#endif
6907+
6908 mm->get_unmapped_area = arch_get_unmapped_area;
6909 mm->unmap_area = arch_unmap_area;
6910 } else {
6911 mm->mmap_base = mmap_base(random_factor);
6912+
6913+#ifdef CONFIG_PAX_RANDMMAP
6914+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6915+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6916+#endif
6917+
6918 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6919 mm->unmap_area = arch_unmap_area_topdown;
6920 }
6921 }
6922
6923-static inline unsigned long brk_rnd(void)
6924-{
6925- unsigned long rnd = get_random_int();
6926-
6927- rnd = rnd << PAGE_SHIFT;
6928- /* 8MB for 32bit, 256MB for 64bit */
6929- if (TASK_IS_32BIT_ADDR)
6930- rnd = rnd & 0x7ffffful;
6931- else
6932- rnd = rnd & 0xffffffful;
6933-
6934- return rnd;
6935-}
6936-
6937-unsigned long arch_randomize_brk(struct mm_struct *mm)
6938-{
6939- unsigned long base = mm->brk;
6940- unsigned long ret;
6941-
6942- ret = PAGE_ALIGN(base + brk_rnd());
6943-
6944- if (ret < mm->brk)
6945- return mm->brk;
6946-
6947- return ret;
6948-}
6949-
6950 int __virt_addr_valid(const volatile void *kaddr)
6951 {
6952 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6953diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6954index a2358b4..7cead4f 100644
6955--- a/arch/mips/sgi-ip27/ip27-nmi.c
6956+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6957@@ -187,9 +187,9 @@ void
6958 cont_nmi_dump(void)
6959 {
6960 #ifndef REAL_NMI_SIGNAL
6961- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6962+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6963
6964- atomic_inc(&nmied_cpus);
6965+ atomic_inc_unchecked(&nmied_cpus);
6966 #endif
6967 /*
6968 * Only allow 1 cpu to proceed
6969@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6970 udelay(10000);
6971 }
6972 #else
6973- while (atomic_read(&nmied_cpus) != num_online_cpus());
6974+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6975 #endif
6976
6977 /*
6978diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6979index 967d144..db12197 100644
6980--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6981+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6982@@ -11,12 +11,14 @@
6983 #ifndef _ASM_PROC_CACHE_H
6984 #define _ASM_PROC_CACHE_H
6985
6986+#include <linux/const.h>
6987+
6988 /* L1 cache */
6989
6990 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6991 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6992-#define L1_CACHE_BYTES 16 /* bytes per entry */
6993 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6994+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6995 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6996
6997 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6998diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6999index bcb5df2..84fabd2 100644
7000--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7001+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7002@@ -16,13 +16,15 @@
7003 #ifndef _ASM_PROC_CACHE_H
7004 #define _ASM_PROC_CACHE_H
7005
7006+#include <linux/const.h>
7007+
7008 /*
7009 * L1 cache
7010 */
7011 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7012 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7013-#define L1_CACHE_BYTES 32 /* bytes per entry */
7014 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7015+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7016 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7017
7018 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7019diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7020index 4ce7a01..449202a 100644
7021--- a/arch/openrisc/include/asm/cache.h
7022+++ b/arch/openrisc/include/asm/cache.h
7023@@ -19,11 +19,13 @@
7024 #ifndef __ASM_OPENRISC_CACHE_H
7025 #define __ASM_OPENRISC_CACHE_H
7026
7027+#include <linux/const.h>
7028+
7029 /* FIXME: How can we replace these with values from the CPU...
7030 * they shouldn't be hard-coded!
7031 */
7032
7033-#define L1_CACHE_BYTES 16
7034 #define L1_CACHE_SHIFT 4
7035+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7036
7037 #endif /* __ASM_OPENRISC_CACHE_H */
7038diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7039index 472886c..00e7df9 100644
7040--- a/arch/parisc/include/asm/atomic.h
7041+++ b/arch/parisc/include/asm/atomic.h
7042@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7043 return dec;
7044 }
7045
7046+#define atomic64_read_unchecked(v) atomic64_read(v)
7047+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7048+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7049+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7050+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7051+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7052+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7053+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7054+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7055+
7056 #endif /* !CONFIG_64BIT */
7057
7058
7059diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7060index 47f11c7..3420df2 100644
7061--- a/arch/parisc/include/asm/cache.h
7062+++ b/arch/parisc/include/asm/cache.h
7063@@ -5,6 +5,7 @@
7064 #ifndef __ARCH_PARISC_CACHE_H
7065 #define __ARCH_PARISC_CACHE_H
7066
7067+#include <linux/const.h>
7068
7069 /*
7070 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7071@@ -15,13 +16,13 @@
7072 * just ruin performance.
7073 */
7074 #ifdef CONFIG_PA20
7075-#define L1_CACHE_BYTES 64
7076 #define L1_CACHE_SHIFT 6
7077 #else
7078-#define L1_CACHE_BYTES 32
7079 #define L1_CACHE_SHIFT 5
7080 #endif
7081
7082+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7083+
7084 #ifndef __ASSEMBLY__
7085
7086 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7087diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7088index ad2b503..bdf1651 100644
7089--- a/arch/parisc/include/asm/elf.h
7090+++ b/arch/parisc/include/asm/elf.h
7091@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7092
7093 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7094
7095+#ifdef CONFIG_PAX_ASLR
7096+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7097+
7098+#define PAX_DELTA_MMAP_LEN 16
7099+#define PAX_DELTA_STACK_LEN 16
7100+#endif
7101+
7102 /* This yields a mask that user programs can use to figure out what
7103 instruction set this CPU supports. This could be done in user space,
7104 but it's not easy, and we've already done it here. */
7105diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7106index fc987a1..6e068ef 100644
7107--- a/arch/parisc/include/asm/pgalloc.h
7108+++ b/arch/parisc/include/asm/pgalloc.h
7109@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7110 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7111 }
7112
7113+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7114+{
7115+ pgd_populate(mm, pgd, pmd);
7116+}
7117+
7118 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7119 {
7120 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7121@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7122 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7123 #define pmd_free(mm, x) do { } while (0)
7124 #define pgd_populate(mm, pmd, pte) BUG()
7125+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7126
7127 #endif
7128
7129diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7130index 1e40d7f..a3eb445 100644
7131--- a/arch/parisc/include/asm/pgtable.h
7132+++ b/arch/parisc/include/asm/pgtable.h
7133@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7134 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7135 #define PAGE_COPY PAGE_EXECREAD
7136 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7137+
7138+#ifdef CONFIG_PAX_PAGEEXEC
7139+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7140+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7141+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7142+#else
7143+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7144+# define PAGE_COPY_NOEXEC PAGE_COPY
7145+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7146+#endif
7147+
7148 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7149 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7150 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7151diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7152index e0a8235..ce2f1e1 100644
7153--- a/arch/parisc/include/asm/uaccess.h
7154+++ b/arch/parisc/include/asm/uaccess.h
7155@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7156 const void __user *from,
7157 unsigned long n)
7158 {
7159- int sz = __compiletime_object_size(to);
7160+ size_t sz = __compiletime_object_size(to);
7161 int ret = -EFAULT;
7162
7163- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7164+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7165 ret = __copy_from_user(to, from, n);
7166 else
7167 copy_from_user_overflow();
7168diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7169index 2a625fb..9908930 100644
7170--- a/arch/parisc/kernel/module.c
7171+++ b/arch/parisc/kernel/module.c
7172@@ -98,16 +98,38 @@
7173
7174 /* three functions to determine where in the module core
7175 * or init pieces the location is */
7176+static inline int in_init_rx(struct module *me, void *loc)
7177+{
7178+ return (loc >= me->module_init_rx &&
7179+ loc < (me->module_init_rx + me->init_size_rx));
7180+}
7181+
7182+static inline int in_init_rw(struct module *me, void *loc)
7183+{
7184+ return (loc >= me->module_init_rw &&
7185+ loc < (me->module_init_rw + me->init_size_rw));
7186+}
7187+
7188 static inline int in_init(struct module *me, void *loc)
7189 {
7190- return (loc >= me->module_init &&
7191- loc <= (me->module_init + me->init_size));
7192+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7193+}
7194+
7195+static inline int in_core_rx(struct module *me, void *loc)
7196+{
7197+ return (loc >= me->module_core_rx &&
7198+ loc < (me->module_core_rx + me->core_size_rx));
7199+}
7200+
7201+static inline int in_core_rw(struct module *me, void *loc)
7202+{
7203+ return (loc >= me->module_core_rw &&
7204+ loc < (me->module_core_rw + me->core_size_rw));
7205 }
7206
7207 static inline int in_core(struct module *me, void *loc)
7208 {
7209- return (loc >= me->module_core &&
7210- loc <= (me->module_core + me->core_size));
7211+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7212 }
7213
7214 static inline int in_local(struct module *me, void *loc)
7215@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7216 }
7217
7218 /* align things a bit */
7219- me->core_size = ALIGN(me->core_size, 16);
7220- me->arch.got_offset = me->core_size;
7221- me->core_size += gots * sizeof(struct got_entry);
7222+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7223+ me->arch.got_offset = me->core_size_rw;
7224+ me->core_size_rw += gots * sizeof(struct got_entry);
7225
7226- me->core_size = ALIGN(me->core_size, 16);
7227- me->arch.fdesc_offset = me->core_size;
7228- me->core_size += fdescs * sizeof(Elf_Fdesc);
7229+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7230+ me->arch.fdesc_offset = me->core_size_rw;
7231+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7232
7233 me->arch.got_max = gots;
7234 me->arch.fdesc_max = fdescs;
7235@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7236
7237 BUG_ON(value == 0);
7238
7239- got = me->module_core + me->arch.got_offset;
7240+ got = me->module_core_rw + me->arch.got_offset;
7241 for (i = 0; got[i].addr; i++)
7242 if (got[i].addr == value)
7243 goto out;
7244@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7245 #ifdef CONFIG_64BIT
7246 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7247 {
7248- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7249+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7250
7251 if (!value) {
7252 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7253@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7254
7255 /* Create new one */
7256 fdesc->addr = value;
7257- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7258+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7259 return (Elf_Addr)fdesc;
7260 }
7261 #endif /* CONFIG_64BIT */
7262@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7263
7264 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7265 end = table + sechdrs[me->arch.unwind_section].sh_size;
7266- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7267+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7268
7269 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7270 me->arch.unwind_section, table, end, gp);
7271diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7272index 5dfd248..64914ac 100644
7273--- a/arch/parisc/kernel/sys_parisc.c
7274+++ b/arch/parisc/kernel/sys_parisc.c
7275@@ -33,9 +33,11 @@
7276 #include <linux/utsname.h>
7277 #include <linux/personality.h>
7278
7279-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7280+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7281+ unsigned long flags)
7282 {
7283 struct vm_unmapped_area_info info;
7284+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7285
7286 info.flags = 0;
7287 info.length = len;
7288@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7289 info.high_limit = TASK_SIZE;
7290 info.align_mask = 0;
7291 info.align_offset = 0;
7292+ info.threadstack_offset = offset;
7293 return vm_unmapped_area(&info);
7294 }
7295
7296@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
7297 return (unsigned long) mapping >> 8;
7298 }
7299
7300-static unsigned long get_shared_area(struct address_space *mapping,
7301- unsigned long addr, unsigned long len, unsigned long pgoff)
7302+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
7303+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
7304 {
7305 struct vm_unmapped_area_info info;
7306+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7307
7308 info.flags = 0;
7309 info.length = len;
7310@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
7311 info.high_limit = TASK_SIZE;
7312 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7313 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
7314+ info.threadstack_offset = offset;
7315 return vm_unmapped_area(&info);
7316 }
7317
7318@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7319 return -EINVAL;
7320 return addr;
7321 }
7322- if (!addr)
7323+ if (!addr) {
7324 addr = TASK_UNMAPPED_BASE;
7325
7326+#ifdef CONFIG_PAX_RANDMMAP
7327+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7328+ addr += current->mm->delta_mmap;
7329+#endif
7330+
7331+ }
7332+
7333 if (filp) {
7334- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
7335+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
7336 } else if(flags & MAP_SHARED) {
7337- addr = get_shared_area(NULL, addr, len, pgoff);
7338+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
7339 } else {
7340- addr = get_unshared_area(addr, len);
7341+ addr = get_unshared_area(filp, addr, len, flags);
7342 }
7343 return addr;
7344 }
7345diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7346index 04e47c6..7a8faf6 100644
7347--- a/arch/parisc/kernel/traps.c
7348+++ b/arch/parisc/kernel/traps.c
7349@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7350
7351 down_read(&current->mm->mmap_sem);
7352 vma = find_vma(current->mm,regs->iaoq[0]);
7353- if (vma && (regs->iaoq[0] >= vma->vm_start)
7354- && (vma->vm_flags & VM_EXEC)) {
7355-
7356+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7357 fault_address = regs->iaoq[0];
7358 fault_space = regs->iasq[0];
7359
7360diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7361index f247a34..dc0f219 100644
7362--- a/arch/parisc/mm/fault.c
7363+++ b/arch/parisc/mm/fault.c
7364@@ -15,6 +15,7 @@
7365 #include <linux/sched.h>
7366 #include <linux/interrupt.h>
7367 #include <linux/module.h>
7368+#include <linux/unistd.h>
7369
7370 #include <asm/uaccess.h>
7371 #include <asm/traps.h>
7372@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7373 static unsigned long
7374 parisc_acctyp(unsigned long code, unsigned int inst)
7375 {
7376- if (code == 6 || code == 16)
7377+ if (code == 6 || code == 7 || code == 16)
7378 return VM_EXEC;
7379
7380 switch (inst & 0xf0000000) {
7381@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7382 }
7383 #endif
7384
7385+#ifdef CONFIG_PAX_PAGEEXEC
7386+/*
7387+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7388+ *
7389+ * returns 1 when task should be killed
7390+ * 2 when rt_sigreturn trampoline was detected
7391+ * 3 when unpatched PLT trampoline was detected
7392+ */
7393+static int pax_handle_fetch_fault(struct pt_regs *regs)
7394+{
7395+
7396+#ifdef CONFIG_PAX_EMUPLT
7397+ int err;
7398+
7399+ do { /* PaX: unpatched PLT emulation */
7400+ unsigned int bl, depwi;
7401+
7402+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7403+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7404+
7405+ if (err)
7406+ break;
7407+
7408+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7409+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7410+
7411+ err = get_user(ldw, (unsigned int *)addr);
7412+ err |= get_user(bv, (unsigned int *)(addr+4));
7413+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7414+
7415+ if (err)
7416+ break;
7417+
7418+ if (ldw == 0x0E801096U &&
7419+ bv == 0xEAC0C000U &&
7420+ ldw2 == 0x0E881095U)
7421+ {
7422+ unsigned int resolver, map;
7423+
7424+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7425+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7426+ if (err)
7427+ break;
7428+
7429+ regs->gr[20] = instruction_pointer(regs)+8;
7430+ regs->gr[21] = map;
7431+ regs->gr[22] = resolver;
7432+ regs->iaoq[0] = resolver | 3UL;
7433+ regs->iaoq[1] = regs->iaoq[0] + 4;
7434+ return 3;
7435+ }
7436+ }
7437+ } while (0);
7438+#endif
7439+
7440+#ifdef CONFIG_PAX_EMUTRAMP
7441+
7442+#ifndef CONFIG_PAX_EMUSIGRT
7443+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7444+ return 1;
7445+#endif
7446+
7447+ do { /* PaX: rt_sigreturn emulation */
7448+ unsigned int ldi1, ldi2, bel, nop;
7449+
7450+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7451+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7452+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7453+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7454+
7455+ if (err)
7456+ break;
7457+
7458+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7459+ ldi2 == 0x3414015AU &&
7460+ bel == 0xE4008200U &&
7461+ nop == 0x08000240U)
7462+ {
7463+ regs->gr[25] = (ldi1 & 2) >> 1;
7464+ regs->gr[20] = __NR_rt_sigreturn;
7465+ regs->gr[31] = regs->iaoq[1] + 16;
7466+ regs->sr[0] = regs->iasq[1];
7467+ regs->iaoq[0] = 0x100UL;
7468+ regs->iaoq[1] = regs->iaoq[0] + 4;
7469+ regs->iasq[0] = regs->sr[2];
7470+ regs->iasq[1] = regs->sr[2];
7471+ return 2;
7472+ }
7473+ } while (0);
7474+#endif
7475+
7476+ return 1;
7477+}
7478+
7479+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7480+{
7481+ unsigned long i;
7482+
7483+ printk(KERN_ERR "PAX: bytes at PC: ");
7484+ for (i = 0; i < 5; i++) {
7485+ unsigned int c;
7486+ if (get_user(c, (unsigned int *)pc+i))
7487+ printk(KERN_CONT "???????? ");
7488+ else
7489+ printk(KERN_CONT "%08x ", c);
7490+ }
7491+ printk("\n");
7492+}
7493+#endif
7494+
7495 int fixup_exception(struct pt_regs *regs)
7496 {
7497 const struct exception_table_entry *fix;
7498@@ -194,8 +305,33 @@ good_area:
7499
7500 acc_type = parisc_acctyp(code,regs->iir);
7501
7502- if ((vma->vm_flags & acc_type) != acc_type)
7503+ if ((vma->vm_flags & acc_type) != acc_type) {
7504+
7505+#ifdef CONFIG_PAX_PAGEEXEC
7506+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7507+ (address & ~3UL) == instruction_pointer(regs))
7508+ {
7509+ up_read(&mm->mmap_sem);
7510+ switch (pax_handle_fetch_fault(regs)) {
7511+
7512+#ifdef CONFIG_PAX_EMUPLT
7513+ case 3:
7514+ return;
7515+#endif
7516+
7517+#ifdef CONFIG_PAX_EMUTRAMP
7518+ case 2:
7519+ return;
7520+#endif
7521+
7522+ }
7523+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7524+ do_group_exit(SIGKILL);
7525+ }
7526+#endif
7527+
7528 goto bad_area;
7529+ }
7530
7531 /*
7532 * If for any reason at all we couldn't handle the fault, make
7533diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7534index e3b1d41..8e81edf 100644
7535--- a/arch/powerpc/include/asm/atomic.h
7536+++ b/arch/powerpc/include/asm/atomic.h
7537@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7538 return t1;
7539 }
7540
7541+#define atomic64_read_unchecked(v) atomic64_read(v)
7542+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7543+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7544+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7545+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7546+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7547+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7548+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7549+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7550+
7551 #endif /* __powerpc64__ */
7552
7553 #endif /* __KERNEL__ */
7554diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7555index 9e495c9..b6878e5 100644
7556--- a/arch/powerpc/include/asm/cache.h
7557+++ b/arch/powerpc/include/asm/cache.h
7558@@ -3,6 +3,7 @@
7559
7560 #ifdef __KERNEL__
7561
7562+#include <linux/const.h>
7563
7564 /* bytes per L1 cache line */
7565 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7566@@ -22,7 +23,7 @@
7567 #define L1_CACHE_SHIFT 7
7568 #endif
7569
7570-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7571+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7572
7573 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7574
7575diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7576index cc0655a..13eac2e 100644
7577--- a/arch/powerpc/include/asm/elf.h
7578+++ b/arch/powerpc/include/asm/elf.h
7579@@ -28,8 +28,19 @@
7580 the loader. We need to make sure that it is out of the way of the program
7581 that it will "exec", and that there is sufficient room for the brk. */
7582
7583-extern unsigned long randomize_et_dyn(unsigned long base);
7584-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7585+#define ELF_ET_DYN_BASE (0x20000000)
7586+
7587+#ifdef CONFIG_PAX_ASLR
7588+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7589+
7590+#ifdef __powerpc64__
7591+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7592+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7593+#else
7594+#define PAX_DELTA_MMAP_LEN 15
7595+#define PAX_DELTA_STACK_LEN 15
7596+#endif
7597+#endif
7598
7599 /*
7600 * Our registers are always unsigned longs, whether we're a 32 bit
7601@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7602 (0x7ff >> (PAGE_SHIFT - 12)) : \
7603 (0x3ffff >> (PAGE_SHIFT - 12)))
7604
7605-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7606-#define arch_randomize_brk arch_randomize_brk
7607-
7608-
7609 #ifdef CONFIG_SPU_BASE
7610 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7611 #define NT_SPU 1
7612diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7613index 8196e9c..d83a9f3 100644
7614--- a/arch/powerpc/include/asm/exec.h
7615+++ b/arch/powerpc/include/asm/exec.h
7616@@ -4,6 +4,6 @@
7617 #ifndef _ASM_POWERPC_EXEC_H
7618 #define _ASM_POWERPC_EXEC_H
7619
7620-extern unsigned long arch_align_stack(unsigned long sp);
7621+#define arch_align_stack(x) ((x) & ~0xfUL)
7622
7623 #endif /* _ASM_POWERPC_EXEC_H */
7624diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7625index 5acabbd..7ea14fa 100644
7626--- a/arch/powerpc/include/asm/kmap_types.h
7627+++ b/arch/powerpc/include/asm/kmap_types.h
7628@@ -10,7 +10,7 @@
7629 * 2 of the License, or (at your option) any later version.
7630 */
7631
7632-#define KM_TYPE_NR 16
7633+#define KM_TYPE_NR 17
7634
7635 #endif /* __KERNEL__ */
7636 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7637diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7638index 8565c25..2865190 100644
7639--- a/arch/powerpc/include/asm/mman.h
7640+++ b/arch/powerpc/include/asm/mman.h
7641@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7642 }
7643 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7644
7645-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7646+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7647 {
7648 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7649 }
7650diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7651index b9f4262..dcf04f7 100644
7652--- a/arch/powerpc/include/asm/page.h
7653+++ b/arch/powerpc/include/asm/page.h
7654@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7655 * and needs to be executable. This means the whole heap ends
7656 * up being executable.
7657 */
7658-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7659- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7660+#define VM_DATA_DEFAULT_FLAGS32 \
7661+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7662+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7663
7664 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7665 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7666@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7667 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7668 #endif
7669
7670+#define ktla_ktva(addr) (addr)
7671+#define ktva_ktla(addr) (addr)
7672+
7673 #ifndef CONFIG_PPC_BOOK3S_64
7674 /*
7675 * Use the top bit of the higher-level page table entries to indicate whether
7676diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7677index 88693ce..ac6f9ab 100644
7678--- a/arch/powerpc/include/asm/page_64.h
7679+++ b/arch/powerpc/include/asm/page_64.h
7680@@ -153,15 +153,18 @@ do { \
7681 * stack by default, so in the absence of a PT_GNU_STACK program header
7682 * we turn execute permission off.
7683 */
7684-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7685- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7686+#define VM_STACK_DEFAULT_FLAGS32 \
7687+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7688+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7689
7690 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7691 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7692
7693+#ifndef CONFIG_PAX_PAGEEXEC
7694 #define VM_STACK_DEFAULT_FLAGS \
7695 (is_32bit_task() ? \
7696 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7697+#endif
7698
7699 #include <asm-generic/getorder.h>
7700
7701diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7702index b66ae72..4a378cd 100644
7703--- a/arch/powerpc/include/asm/pgalloc-64.h
7704+++ b/arch/powerpc/include/asm/pgalloc-64.h
7705@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7706 #ifndef CONFIG_PPC_64K_PAGES
7707
7708 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7709+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7710
7711 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7712 {
7713@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7714 pud_set(pud, (unsigned long)pmd);
7715 }
7716
7717+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7718+{
7719+ pud_populate(mm, pud, pmd);
7720+}
7721+
7722 #define pmd_populate(mm, pmd, pte_page) \
7723 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7724 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7725@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
7726 #endif
7727
7728 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7729+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7730
7731 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7732 pte_t *pte)
7733diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7734index 7aeb955..19f748e 100644
7735--- a/arch/powerpc/include/asm/pgtable.h
7736+++ b/arch/powerpc/include/asm/pgtable.h
7737@@ -2,6 +2,7 @@
7738 #define _ASM_POWERPC_PGTABLE_H
7739 #ifdef __KERNEL__
7740
7741+#include <linux/const.h>
7742 #ifndef __ASSEMBLY__
7743 #include <asm/processor.h> /* For TASK_SIZE */
7744 #include <asm/mmu.h>
7745diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7746index 4aad413..85d86bf 100644
7747--- a/arch/powerpc/include/asm/pte-hash32.h
7748+++ b/arch/powerpc/include/asm/pte-hash32.h
7749@@ -21,6 +21,7 @@
7750 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7751 #define _PAGE_USER 0x004 /* usermode access allowed */
7752 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7753+#define _PAGE_EXEC _PAGE_GUARDED
7754 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7755 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7756 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7757diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7758index e1fb161..2290d1d 100644
7759--- a/arch/powerpc/include/asm/reg.h
7760+++ b/arch/powerpc/include/asm/reg.h
7761@@ -234,6 +234,7 @@
7762 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7763 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7764 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7765+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7766 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7767 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7768 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7769diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7770index 48cfc85..891382f 100644
7771--- a/arch/powerpc/include/asm/smp.h
7772+++ b/arch/powerpc/include/asm/smp.h
7773@@ -50,7 +50,7 @@ struct smp_ops_t {
7774 int (*cpu_disable)(void);
7775 void (*cpu_die)(unsigned int nr);
7776 int (*cpu_bootable)(unsigned int nr);
7777-};
7778+} __no_const;
7779
7780 extern void smp_send_debugger_break(void);
7781 extern void start_secondary_resume(void);
7782diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7783index ba7b197..d292e26 100644
7784--- a/arch/powerpc/include/asm/thread_info.h
7785+++ b/arch/powerpc/include/asm/thread_info.h
7786@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7787 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7788 TIF_NEED_RESCHED */
7789 #define TIF_32BIT 4 /* 32 bit binary */
7790-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7791 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7792 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7793 #define TIF_SINGLESTEP 8 /* singlestepping active */
7794@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7795 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7796 for stack store? */
7797 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7798+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7799+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7800+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7801
7802 /* as above, but as bit values */
7803 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7804@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7805 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7806 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7807 #define _TIF_NOHZ (1<<TIF_NOHZ)
7808+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7809 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7810 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7811- _TIF_NOHZ)
7812+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7813
7814 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7815 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7816diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7817index 4db4959..aba5c41 100644
7818--- a/arch/powerpc/include/asm/uaccess.h
7819+++ b/arch/powerpc/include/asm/uaccess.h
7820@@ -318,52 +318,6 @@ do { \
7821 extern unsigned long __copy_tofrom_user(void __user *to,
7822 const void __user *from, unsigned long size);
7823
7824-#ifndef __powerpc64__
7825-
7826-static inline unsigned long copy_from_user(void *to,
7827- const void __user *from, unsigned long n)
7828-{
7829- unsigned long over;
7830-
7831- if (access_ok(VERIFY_READ, from, n))
7832- return __copy_tofrom_user((__force void __user *)to, from, n);
7833- if ((unsigned long)from < TASK_SIZE) {
7834- over = (unsigned long)from + n - TASK_SIZE;
7835- return __copy_tofrom_user((__force void __user *)to, from,
7836- n - over) + over;
7837- }
7838- return n;
7839-}
7840-
7841-static inline unsigned long copy_to_user(void __user *to,
7842- const void *from, unsigned long n)
7843-{
7844- unsigned long over;
7845-
7846- if (access_ok(VERIFY_WRITE, to, n))
7847- return __copy_tofrom_user(to, (__force void __user *)from, n);
7848- if ((unsigned long)to < TASK_SIZE) {
7849- over = (unsigned long)to + n - TASK_SIZE;
7850- return __copy_tofrom_user(to, (__force void __user *)from,
7851- n - over) + over;
7852- }
7853- return n;
7854-}
7855-
7856-#else /* __powerpc64__ */
7857-
7858-#define __copy_in_user(to, from, size) \
7859- __copy_tofrom_user((to), (from), (size))
7860-
7861-extern unsigned long copy_from_user(void *to, const void __user *from,
7862- unsigned long n);
7863-extern unsigned long copy_to_user(void __user *to, const void *from,
7864- unsigned long n);
7865-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7866- unsigned long n);
7867-
7868-#endif /* __powerpc64__ */
7869-
7870 static inline unsigned long __copy_from_user_inatomic(void *to,
7871 const void __user *from, unsigned long n)
7872 {
7873@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7874 if (ret == 0)
7875 return 0;
7876 }
7877+
7878+ if (!__builtin_constant_p(n))
7879+ check_object_size(to, n, false);
7880+
7881 return __copy_tofrom_user((__force void __user *)to, from, n);
7882 }
7883
7884@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7885 if (ret == 0)
7886 return 0;
7887 }
7888+
7889+ if (!__builtin_constant_p(n))
7890+ check_object_size(from, n, true);
7891+
7892 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7893 }
7894
7895@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7896 return __copy_to_user_inatomic(to, from, size);
7897 }
7898
7899+#ifndef __powerpc64__
7900+
7901+static inline unsigned long __must_check copy_from_user(void *to,
7902+ const void __user *from, unsigned long n)
7903+{
7904+ unsigned long over;
7905+
7906+ if ((long)n < 0)
7907+ return n;
7908+
7909+ if (access_ok(VERIFY_READ, from, n)) {
7910+ if (!__builtin_constant_p(n))
7911+ check_object_size(to, n, false);
7912+ return __copy_tofrom_user((__force void __user *)to, from, n);
7913+ }
7914+ if ((unsigned long)from < TASK_SIZE) {
7915+ over = (unsigned long)from + n - TASK_SIZE;
7916+ if (!__builtin_constant_p(n - over))
7917+ check_object_size(to, n - over, false);
7918+ return __copy_tofrom_user((__force void __user *)to, from,
7919+ n - over) + over;
7920+ }
7921+ return n;
7922+}
7923+
7924+static inline unsigned long __must_check copy_to_user(void __user *to,
7925+ const void *from, unsigned long n)
7926+{
7927+ unsigned long over;
7928+
7929+ if ((long)n < 0)
7930+ return n;
7931+
7932+ if (access_ok(VERIFY_WRITE, to, n)) {
7933+ if (!__builtin_constant_p(n))
7934+ check_object_size(from, n, true);
7935+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7936+ }
7937+ if ((unsigned long)to < TASK_SIZE) {
7938+ over = (unsigned long)to + n - TASK_SIZE;
7939+ if (!__builtin_constant_p(n))
7940+ check_object_size(from, n - over, true);
7941+ return __copy_tofrom_user(to, (__force void __user *)from,
7942+ n - over) + over;
7943+ }
7944+ return n;
7945+}
7946+
7947+#else /* __powerpc64__ */
7948+
7949+#define __copy_in_user(to, from, size) \
7950+ __copy_tofrom_user((to), (from), (size))
7951+
7952+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7953+{
7954+ if ((long)n < 0 || n > INT_MAX)
7955+ return n;
7956+
7957+ if (!__builtin_constant_p(n))
7958+ check_object_size(to, n, false);
7959+
7960+ if (likely(access_ok(VERIFY_READ, from, n)))
7961+ n = __copy_from_user(to, from, n);
7962+ else
7963+ memset(to, 0, n);
7964+ return n;
7965+}
7966+
7967+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7968+{
7969+ if ((long)n < 0 || n > INT_MAX)
7970+ return n;
7971+
7972+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7973+ if (!__builtin_constant_p(n))
7974+ check_object_size(from, n, true);
7975+ n = __copy_to_user(to, from, n);
7976+ }
7977+ return n;
7978+}
7979+
7980+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7981+ unsigned long n);
7982+
7983+#endif /* __powerpc64__ */
7984+
7985 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7986
7987 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7988diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7989index 645170a..6cf0271 100644
7990--- a/arch/powerpc/kernel/exceptions-64e.S
7991+++ b/arch/powerpc/kernel/exceptions-64e.S
7992@@ -757,6 +757,7 @@ storage_fault_common:
7993 std r14,_DAR(r1)
7994 std r15,_DSISR(r1)
7995 addi r3,r1,STACK_FRAME_OVERHEAD
7996+ bl .save_nvgprs
7997 mr r4,r14
7998 mr r5,r15
7999 ld r14,PACA_EXGEN+EX_R14(r13)
8000@@ -765,8 +766,7 @@ storage_fault_common:
8001 cmpdi r3,0
8002 bne- 1f
8003 b .ret_from_except_lite
8004-1: bl .save_nvgprs
8005- mr r5,r3
8006+1: mr r5,r3
8007 addi r3,r1,STACK_FRAME_OVERHEAD
8008 ld r4,_DAR(r1)
8009 bl .bad_page_fault
8010diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8011index 902ca3c..e942155 100644
8012--- a/arch/powerpc/kernel/exceptions-64s.S
8013+++ b/arch/powerpc/kernel/exceptions-64s.S
8014@@ -1357,10 +1357,10 @@ handle_page_fault:
8015 11: ld r4,_DAR(r1)
8016 ld r5,_DSISR(r1)
8017 addi r3,r1,STACK_FRAME_OVERHEAD
8018+ bl .save_nvgprs
8019 bl .do_page_fault
8020 cmpdi r3,0
8021 beq+ 12f
8022- bl .save_nvgprs
8023 mr r5,r3
8024 addi r3,r1,STACK_FRAME_OVERHEAD
8025 lwz r4,_DAR(r1)
8026diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8027index 2e3200c..72095ce 100644
8028--- a/arch/powerpc/kernel/module_32.c
8029+++ b/arch/powerpc/kernel/module_32.c
8030@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8031 me->arch.core_plt_section = i;
8032 }
8033 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8034- printk("Module doesn't contain .plt or .init.plt sections.\n");
8035+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8036 return -ENOEXEC;
8037 }
8038
8039@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
8040
8041 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8042 /* Init, or core PLT? */
8043- if (location >= mod->module_core
8044- && location < mod->module_core + mod->core_size)
8045+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8046+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8047 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8048- else
8049+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8050+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8051 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8052+ else {
8053+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8054+ return ~0UL;
8055+ }
8056
8057 /* Find this entry, or if that fails, the next avail. entry */
8058 while (entry->jump[0]) {
8059diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8060index 7baa27b..f6b394a 100644
8061--- a/arch/powerpc/kernel/process.c
8062+++ b/arch/powerpc/kernel/process.c
8063@@ -884,8 +884,8 @@ void show_regs(struct pt_regs * regs)
8064 * Lookup NIP late so we have the best change of getting the
8065 * above info out without failing
8066 */
8067- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8068- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8069+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8070+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8071 #endif
8072 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
8073 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
8074@@ -1345,10 +1345,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8075 newsp = stack[0];
8076 ip = stack[STACK_FRAME_LR_SAVE];
8077 if (!firstframe || ip != lr) {
8078- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8079+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8080 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8081 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8082- printk(" (%pS)",
8083+ printk(" (%pA)",
8084 (void *)current->ret_stack[curr_frame].ret);
8085 curr_frame--;
8086 }
8087@@ -1368,7 +1368,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8088 struct pt_regs *regs = (struct pt_regs *)
8089 (sp + STACK_FRAME_OVERHEAD);
8090 lr = regs->link;
8091- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8092+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8093 regs->trap, (void *)regs->nip, (void *)lr);
8094 firstframe = 1;
8095 }
8096@@ -1404,58 +1404,3 @@ void notrace __ppc64_runlatch_off(void)
8097 mtspr(SPRN_CTRLT, ctrl);
8098 }
8099 #endif /* CONFIG_PPC64 */
8100-
8101-unsigned long arch_align_stack(unsigned long sp)
8102-{
8103- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8104- sp -= get_random_int() & ~PAGE_MASK;
8105- return sp & ~0xf;
8106-}
8107-
8108-static inline unsigned long brk_rnd(void)
8109-{
8110- unsigned long rnd = 0;
8111-
8112- /* 8MB for 32bit, 1GB for 64bit */
8113- if (is_32bit_task())
8114- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8115- else
8116- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8117-
8118- return rnd << PAGE_SHIFT;
8119-}
8120-
8121-unsigned long arch_randomize_brk(struct mm_struct *mm)
8122-{
8123- unsigned long base = mm->brk;
8124- unsigned long ret;
8125-
8126-#ifdef CONFIG_PPC_STD_MMU_64
8127- /*
8128- * If we are using 1TB segments and we are allowed to randomise
8129- * the heap, we can put it above 1TB so it is backed by a 1TB
8130- * segment. Otherwise the heap will be in the bottom 1TB
8131- * which always uses 256MB segments and this may result in a
8132- * performance penalty.
8133- */
8134- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8135- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8136-#endif
8137-
8138- ret = PAGE_ALIGN(base + brk_rnd());
8139-
8140- if (ret < mm->brk)
8141- return mm->brk;
8142-
8143- return ret;
8144-}
8145-
8146-unsigned long randomize_et_dyn(unsigned long base)
8147-{
8148- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8149-
8150- if (ret < base)
8151- return base;
8152-
8153- return ret;
8154-}
8155diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8156index 64f7bd5..8dd550f 100644
8157--- a/arch/powerpc/kernel/ptrace.c
8158+++ b/arch/powerpc/kernel/ptrace.c
8159@@ -1783,6 +1783,10 @@ long arch_ptrace(struct task_struct *child, long request,
8160 return ret;
8161 }
8162
8163+#ifdef CONFIG_GRKERNSEC_SETXID
8164+extern void gr_delayed_cred_worker(void);
8165+#endif
8166+
8167 /*
8168 * We must return the syscall number to actually look up in the table.
8169 * This can be -1L to skip running any syscall at all.
8170@@ -1795,6 +1799,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8171
8172 secure_computing_strict(regs->gpr[0]);
8173
8174+#ifdef CONFIG_GRKERNSEC_SETXID
8175+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8176+ gr_delayed_cred_worker();
8177+#endif
8178+
8179 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8180 tracehook_report_syscall_entry(regs))
8181 /*
8182@@ -1829,6 +1838,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8183 {
8184 int step;
8185
8186+#ifdef CONFIG_GRKERNSEC_SETXID
8187+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8188+ gr_delayed_cred_worker();
8189+#endif
8190+
8191 audit_syscall_exit(regs);
8192
8193 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8194diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8195index 0f83122..c0aca6a 100644
8196--- a/arch/powerpc/kernel/signal_32.c
8197+++ b/arch/powerpc/kernel/signal_32.c
8198@@ -987,7 +987,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8199 /* Save user registers on the stack */
8200 frame = &rt_sf->uc.uc_mcontext;
8201 addr = frame;
8202- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8203+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8204 sigret = 0;
8205 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8206 } else {
8207diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8208index 887e99d..310bc11 100644
8209--- a/arch/powerpc/kernel/signal_64.c
8210+++ b/arch/powerpc/kernel/signal_64.c
8211@@ -751,7 +751,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8212 #endif
8213
8214 /* Set up to return from userspace. */
8215- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8216+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8217 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8218 } else {
8219 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8220diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
8221index e68a845..8b140e6 100644
8222--- a/arch/powerpc/kernel/sysfs.c
8223+++ b/arch/powerpc/kernel/sysfs.c
8224@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8225 return NOTIFY_OK;
8226 }
8227
8228-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8229+static struct notifier_block sysfs_cpu_nb = {
8230 .notifier_call = sysfs_cpu_notify,
8231 };
8232
8233diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8234index 88929b1..bece8f8 100644
8235--- a/arch/powerpc/kernel/traps.c
8236+++ b/arch/powerpc/kernel/traps.c
8237@@ -141,6 +141,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8238 return flags;
8239 }
8240
8241+extern void gr_handle_kernel_exploit(void);
8242+
8243 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8244 int signr)
8245 {
8246@@ -190,6 +192,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8247 panic("Fatal exception in interrupt");
8248 if (panic_on_oops)
8249 panic("Fatal exception");
8250+
8251+ gr_handle_kernel_exploit();
8252+
8253 do_exit(signr);
8254 }
8255
8256diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8257index d4f463a..8fb7431 100644
8258--- a/arch/powerpc/kernel/vdso.c
8259+++ b/arch/powerpc/kernel/vdso.c
8260@@ -34,6 +34,7 @@
8261 #include <asm/firmware.h>
8262 #include <asm/vdso.h>
8263 #include <asm/vdso_datapage.h>
8264+#include <asm/mman.h>
8265
8266 #include "setup.h"
8267
8268@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8269 vdso_base = VDSO32_MBASE;
8270 #endif
8271
8272- current->mm->context.vdso_base = 0;
8273+ current->mm->context.vdso_base = ~0UL;
8274
8275 /* vDSO has a problem and was disabled, just don't "enable" it for the
8276 * process
8277@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8278 vdso_base = get_unmapped_area(NULL, vdso_base,
8279 (vdso_pages << PAGE_SHIFT) +
8280 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8281- 0, 0);
8282+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8283 if (IS_ERR_VALUE(vdso_base)) {
8284 rc = vdso_base;
8285 goto fail_mmapsem;
8286diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8287index 5eea6f3..5d10396 100644
8288--- a/arch/powerpc/lib/usercopy_64.c
8289+++ b/arch/powerpc/lib/usercopy_64.c
8290@@ -9,22 +9,6 @@
8291 #include <linux/module.h>
8292 #include <asm/uaccess.h>
8293
8294-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8295-{
8296- if (likely(access_ok(VERIFY_READ, from, n)))
8297- n = __copy_from_user(to, from, n);
8298- else
8299- memset(to, 0, n);
8300- return n;
8301-}
8302-
8303-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8304-{
8305- if (likely(access_ok(VERIFY_WRITE, to, n)))
8306- n = __copy_to_user(to, from, n);
8307- return n;
8308-}
8309-
8310 unsigned long copy_in_user(void __user *to, const void __user *from,
8311 unsigned long n)
8312 {
8313@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8314 return n;
8315 }
8316
8317-EXPORT_SYMBOL(copy_from_user);
8318-EXPORT_SYMBOL(copy_to_user);
8319 EXPORT_SYMBOL(copy_in_user);
8320
8321diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8322index 8726779..a33c512 100644
8323--- a/arch/powerpc/mm/fault.c
8324+++ b/arch/powerpc/mm/fault.c
8325@@ -33,6 +33,10 @@
8326 #include <linux/magic.h>
8327 #include <linux/ratelimit.h>
8328 #include <linux/context_tracking.h>
8329+#include <linux/slab.h>
8330+#include <linux/pagemap.h>
8331+#include <linux/compiler.h>
8332+#include <linux/unistd.h>
8333
8334 #include <asm/firmware.h>
8335 #include <asm/page.h>
8336@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8337 }
8338 #endif
8339
8340+#ifdef CONFIG_PAX_PAGEEXEC
8341+/*
8342+ * PaX: decide what to do with offenders (regs->nip = fault address)
8343+ *
8344+ * returns 1 when task should be killed
8345+ */
8346+static int pax_handle_fetch_fault(struct pt_regs *regs)
8347+{
8348+ return 1;
8349+}
8350+
8351+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8352+{
8353+ unsigned long i;
8354+
8355+ printk(KERN_ERR "PAX: bytes at PC: ");
8356+ for (i = 0; i < 5; i++) {
8357+ unsigned int c;
8358+ if (get_user(c, (unsigned int __user *)pc+i))
8359+ printk(KERN_CONT "???????? ");
8360+ else
8361+ printk(KERN_CONT "%08x ", c);
8362+ }
8363+ printk("\n");
8364+}
8365+#endif
8366+
8367 /*
8368 * Check whether the instruction at regs->nip is a store using
8369 * an update addressing form which will update r1.
8370@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8371 * indicate errors in DSISR but can validly be set in SRR1.
8372 */
8373 if (trap == 0x400)
8374- error_code &= 0x48200000;
8375+ error_code &= 0x58200000;
8376 else
8377 is_write = error_code & DSISR_ISSTORE;
8378 #else
8379@@ -371,7 +402,7 @@ good_area:
8380 * "undefined". Of those that can be set, this is the only
8381 * one which seems bad.
8382 */
8383- if (error_code & 0x10000000)
8384+ if (error_code & DSISR_GUARDED)
8385 /* Guarded storage error. */
8386 goto bad_area;
8387 #endif /* CONFIG_8xx */
8388@@ -386,7 +417,7 @@ good_area:
8389 * processors use the same I/D cache coherency mechanism
8390 * as embedded.
8391 */
8392- if (error_code & DSISR_PROTFAULT)
8393+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8394 goto bad_area;
8395 #endif /* CONFIG_PPC_STD_MMU */
8396
8397@@ -471,6 +502,23 @@ bad_area:
8398 bad_area_nosemaphore:
8399 /* User mode accesses cause a SIGSEGV */
8400 if (user_mode(regs)) {
8401+
8402+#ifdef CONFIG_PAX_PAGEEXEC
8403+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8404+#ifdef CONFIG_PPC_STD_MMU
8405+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8406+#else
8407+ if (is_exec && regs->nip == address) {
8408+#endif
8409+ switch (pax_handle_fetch_fault(regs)) {
8410+ }
8411+
8412+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8413+ do_group_exit(SIGKILL);
8414+ }
8415+ }
8416+#endif
8417+
8418 _exception(SIGSEGV, regs, code, address);
8419 goto bail;
8420 }
8421diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
8422index 67a42ed..cd463e0 100644
8423--- a/arch/powerpc/mm/mmap_64.c
8424+++ b/arch/powerpc/mm/mmap_64.c
8425@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8426 {
8427 unsigned long rnd = 0;
8428
8429+#ifdef CONFIG_PAX_RANDMMAP
8430+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8431+#endif
8432+
8433 if (current->flags & PF_RANDOMIZE) {
8434 /* 8MB for 32bit, 1GB for 64bit */
8435 if (is_32bit_task())
8436@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8437 */
8438 if (mmap_is_legacy()) {
8439 mm->mmap_base = TASK_UNMAPPED_BASE;
8440+
8441+#ifdef CONFIG_PAX_RANDMMAP
8442+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8443+ mm->mmap_base += mm->delta_mmap;
8444+#endif
8445+
8446 mm->get_unmapped_area = arch_get_unmapped_area;
8447 mm->unmap_area = arch_unmap_area;
8448 } else {
8449 mm->mmap_base = mmap_base();
8450+
8451+#ifdef CONFIG_PAX_RANDMMAP
8452+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8453+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8454+#endif
8455+
8456 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8457 mm->unmap_area = arch_unmap_area_topdown;
8458 }
8459diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
8460index e779642..e5bb889 100644
8461--- a/arch/powerpc/mm/mmu_context_nohash.c
8462+++ b/arch/powerpc/mm/mmu_context_nohash.c
8463@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
8464 return NOTIFY_OK;
8465 }
8466
8467-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
8468+static struct notifier_block mmu_context_cpu_nb = {
8469 .notifier_call = mmu_context_cpu_notify,
8470 };
8471
8472diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
8473index cafad40..9cbc0fc 100644
8474--- a/arch/powerpc/mm/numa.c
8475+++ b/arch/powerpc/mm/numa.c
8476@@ -920,7 +920,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
8477 return ret;
8478 }
8479
8480-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
8481+static struct notifier_block ppc64_numa_nb = {
8482 .notifier_call = cpu_numa_callback,
8483 .priority = 1 /* Must run before sched domains notifier. */
8484 };
8485diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8486index 3e99c14..f00953c 100644
8487--- a/arch/powerpc/mm/slice.c
8488+++ b/arch/powerpc/mm/slice.c
8489@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8490 if ((mm->task_size - len) < addr)
8491 return 0;
8492 vma = find_vma(mm, addr);
8493- return (!vma || (addr + len) <= vma->vm_start);
8494+ return check_heap_stack_gap(vma, addr, len, 0);
8495 }
8496
8497 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8498@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8499 info.align_offset = 0;
8500
8501 addr = TASK_UNMAPPED_BASE;
8502+
8503+#ifdef CONFIG_PAX_RANDMMAP
8504+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8505+ addr += mm->delta_mmap;
8506+#endif
8507+
8508 while (addr < TASK_SIZE) {
8509 info.low_limit = addr;
8510 if (!slice_scan_available(addr, available, 1, &addr))
8511@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8512 if (fixed && addr > (mm->task_size - len))
8513 return -EINVAL;
8514
8515+#ifdef CONFIG_PAX_RANDMMAP
8516+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8517+ addr = 0;
8518+#endif
8519+
8520 /* If hint, make sure it matches our alignment restrictions */
8521 if (!fixed && addr) {
8522 addr = _ALIGN_UP(addr, 1ul << pshift);
8523diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8524index 9098692..3d54cd1 100644
8525--- a/arch/powerpc/platforms/cell/spufs/file.c
8526+++ b/arch/powerpc/platforms/cell/spufs/file.c
8527@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8528 return VM_FAULT_NOPAGE;
8529 }
8530
8531-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8532+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8533 unsigned long address,
8534- void *buf, int len, int write)
8535+ void *buf, size_t len, int write)
8536 {
8537 struct spu_context *ctx = vma->vm_file->private_data;
8538 unsigned long offset = address - vma->vm_start;
8539diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
8540index bdb738a..49c9f95 100644
8541--- a/arch/powerpc/platforms/powermac/smp.c
8542+++ b/arch/powerpc/platforms/powermac/smp.c
8543@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
8544 return NOTIFY_OK;
8545 }
8546
8547-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
8548+static struct notifier_block smp_core99_cpu_nb = {
8549 .notifier_call = smp_core99_cpu_notify,
8550 };
8551 #endif /* CONFIG_HOTPLUG_CPU */
8552diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8553index c797832..ce575c8 100644
8554--- a/arch/s390/include/asm/atomic.h
8555+++ b/arch/s390/include/asm/atomic.h
8556@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8557 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8558 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8559
8560+#define atomic64_read_unchecked(v) atomic64_read(v)
8561+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8562+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8563+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8564+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8565+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8566+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8567+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8568+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8569+
8570 #define smp_mb__before_atomic_dec() smp_mb()
8571 #define smp_mb__after_atomic_dec() smp_mb()
8572 #define smp_mb__before_atomic_inc() smp_mb()
8573diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8574index 4d7ccac..d03d0ad 100644
8575--- a/arch/s390/include/asm/cache.h
8576+++ b/arch/s390/include/asm/cache.h
8577@@ -9,8 +9,10 @@
8578 #ifndef __ARCH_S390_CACHE_H
8579 #define __ARCH_S390_CACHE_H
8580
8581-#define L1_CACHE_BYTES 256
8582+#include <linux/const.h>
8583+
8584 #define L1_CACHE_SHIFT 8
8585+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8586 #define NET_SKB_PAD 32
8587
8588 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8589diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8590index 78f4f87..598ce39 100644
8591--- a/arch/s390/include/asm/elf.h
8592+++ b/arch/s390/include/asm/elf.h
8593@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8594 the loader. We need to make sure that it is out of the way of the program
8595 that it will "exec", and that there is sufficient room for the brk. */
8596
8597-extern unsigned long randomize_et_dyn(unsigned long base);
8598-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8599+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8600+
8601+#ifdef CONFIG_PAX_ASLR
8602+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8603+
8604+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8605+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8606+#endif
8607
8608 /* This yields a mask that user programs can use to figure out what
8609 instruction set this CPU supports. */
8610@@ -222,9 +228,6 @@ struct linux_binprm;
8611 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8612 int arch_setup_additional_pages(struct linux_binprm *, int);
8613
8614-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8615-#define arch_randomize_brk arch_randomize_brk
8616-
8617 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8618
8619 #endif
8620diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8621index c4a93d6..4d2a9b4 100644
8622--- a/arch/s390/include/asm/exec.h
8623+++ b/arch/s390/include/asm/exec.h
8624@@ -7,6 +7,6 @@
8625 #ifndef __ASM_EXEC_H
8626 #define __ASM_EXEC_H
8627
8628-extern unsigned long arch_align_stack(unsigned long sp);
8629+#define arch_align_stack(x) ((x) & ~0xfUL)
8630
8631 #endif /* __ASM_EXEC_H */
8632diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8633index 9c33ed4..e40cbef 100644
8634--- a/arch/s390/include/asm/uaccess.h
8635+++ b/arch/s390/include/asm/uaccess.h
8636@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8637 copy_to_user(void __user *to, const void *from, unsigned long n)
8638 {
8639 might_fault();
8640+
8641+ if ((long)n < 0)
8642+ return n;
8643+
8644 return __copy_to_user(to, from, n);
8645 }
8646
8647@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8648 static inline unsigned long __must_check
8649 __copy_from_user(void *to, const void __user *from, unsigned long n)
8650 {
8651+ if ((long)n < 0)
8652+ return n;
8653+
8654 if (__builtin_constant_p(n) && (n <= 256))
8655 return uaccess.copy_from_user_small(n, from, to);
8656 else
8657@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8658 static inline unsigned long __must_check
8659 copy_from_user(void *to, const void __user *from, unsigned long n)
8660 {
8661- unsigned int sz = __compiletime_object_size(to);
8662+ size_t sz = __compiletime_object_size(to);
8663
8664 might_fault();
8665- if (unlikely(sz != -1 && sz < n)) {
8666+
8667+ if ((long)n < 0)
8668+ return n;
8669+
8670+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8671 copy_from_user_overflow();
8672 return n;
8673 }
8674diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8675index 7845e15..59c4353 100644
8676--- a/arch/s390/kernel/module.c
8677+++ b/arch/s390/kernel/module.c
8678@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8679
8680 /* Increase core size by size of got & plt and set start
8681 offsets for got and plt. */
8682- me->core_size = ALIGN(me->core_size, 4);
8683- me->arch.got_offset = me->core_size;
8684- me->core_size += me->arch.got_size;
8685- me->arch.plt_offset = me->core_size;
8686- me->core_size += me->arch.plt_size;
8687+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8688+ me->arch.got_offset = me->core_size_rw;
8689+ me->core_size_rw += me->arch.got_size;
8690+ me->arch.plt_offset = me->core_size_rx;
8691+ me->core_size_rx += me->arch.plt_size;
8692 return 0;
8693 }
8694
8695@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8696 if (info->got_initialized == 0) {
8697 Elf_Addr *gotent;
8698
8699- gotent = me->module_core + me->arch.got_offset +
8700+ gotent = me->module_core_rw + me->arch.got_offset +
8701 info->got_offset;
8702 *gotent = val;
8703 info->got_initialized = 1;
8704@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8705 rc = apply_rela_bits(loc, val, 0, 64, 0);
8706 else if (r_type == R_390_GOTENT ||
8707 r_type == R_390_GOTPLTENT) {
8708- val += (Elf_Addr) me->module_core - loc;
8709+ val += (Elf_Addr) me->module_core_rw - loc;
8710 rc = apply_rela_bits(loc, val, 1, 32, 1);
8711 }
8712 break;
8713@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8714 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8715 if (info->plt_initialized == 0) {
8716 unsigned int *ip;
8717- ip = me->module_core + me->arch.plt_offset +
8718+ ip = me->module_core_rx + me->arch.plt_offset +
8719 info->plt_offset;
8720 #ifndef CONFIG_64BIT
8721 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8722@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8723 val - loc + 0xffffUL < 0x1ffffeUL) ||
8724 (r_type == R_390_PLT32DBL &&
8725 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8726- val = (Elf_Addr) me->module_core +
8727+ val = (Elf_Addr) me->module_core_rx +
8728 me->arch.plt_offset +
8729 info->plt_offset;
8730 val += rela->r_addend - loc;
8731@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8732 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8733 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8734 val = val + rela->r_addend -
8735- ((Elf_Addr) me->module_core + me->arch.got_offset);
8736+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8737 if (r_type == R_390_GOTOFF16)
8738 rc = apply_rela_bits(loc, val, 0, 16, 0);
8739 else if (r_type == R_390_GOTOFF32)
8740@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8741 break;
8742 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8743 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8744- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8745+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8746 rela->r_addend - loc;
8747 if (r_type == R_390_GOTPC)
8748 rc = apply_rela_bits(loc, val, 1, 32, 0);
8749diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8750index 2bc3edd..ab9d598 100644
8751--- a/arch/s390/kernel/process.c
8752+++ b/arch/s390/kernel/process.c
8753@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
8754 }
8755 return 0;
8756 }
8757-
8758-unsigned long arch_align_stack(unsigned long sp)
8759-{
8760- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8761- sp -= get_random_int() & ~PAGE_MASK;
8762- return sp & ~0xf;
8763-}
8764-
8765-static inline unsigned long brk_rnd(void)
8766-{
8767- /* 8MB for 32bit, 1GB for 64bit */
8768- if (is_32bit_task())
8769- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8770- else
8771- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8772-}
8773-
8774-unsigned long arch_randomize_brk(struct mm_struct *mm)
8775-{
8776- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8777-
8778- if (ret < mm->brk)
8779- return mm->brk;
8780- return ret;
8781-}
8782-
8783-unsigned long randomize_et_dyn(unsigned long base)
8784-{
8785- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8786-
8787- if (!(current->flags & PF_RANDOMIZE))
8788- return base;
8789- if (ret < base)
8790- return base;
8791- return ret;
8792-}
8793diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8794index 06bafec..2bca531 100644
8795--- a/arch/s390/mm/mmap.c
8796+++ b/arch/s390/mm/mmap.c
8797@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8798 */
8799 if (mmap_is_legacy()) {
8800 mm->mmap_base = TASK_UNMAPPED_BASE;
8801+
8802+#ifdef CONFIG_PAX_RANDMMAP
8803+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8804+ mm->mmap_base += mm->delta_mmap;
8805+#endif
8806+
8807 mm->get_unmapped_area = arch_get_unmapped_area;
8808 mm->unmap_area = arch_unmap_area;
8809 } else {
8810 mm->mmap_base = mmap_base();
8811+
8812+#ifdef CONFIG_PAX_RANDMMAP
8813+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8814+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8815+#endif
8816+
8817 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8818 mm->unmap_area = arch_unmap_area_topdown;
8819 }
8820@@ -175,10 +187,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8821 */
8822 if (mmap_is_legacy()) {
8823 mm->mmap_base = TASK_UNMAPPED_BASE;
8824+
8825+#ifdef CONFIG_PAX_RANDMMAP
8826+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8827+ mm->mmap_base += mm->delta_mmap;
8828+#endif
8829+
8830 mm->get_unmapped_area = s390_get_unmapped_area;
8831 mm->unmap_area = arch_unmap_area;
8832 } else {
8833 mm->mmap_base = mmap_base();
8834+
8835+#ifdef CONFIG_PAX_RANDMMAP
8836+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8837+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8838+#endif
8839+
8840 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8841 mm->unmap_area = arch_unmap_area_topdown;
8842 }
8843diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8844index ae3d59f..f65f075 100644
8845--- a/arch/score/include/asm/cache.h
8846+++ b/arch/score/include/asm/cache.h
8847@@ -1,7 +1,9 @@
8848 #ifndef _ASM_SCORE_CACHE_H
8849 #define _ASM_SCORE_CACHE_H
8850
8851+#include <linux/const.h>
8852+
8853 #define L1_CACHE_SHIFT 4
8854-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8855+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8856
8857 #endif /* _ASM_SCORE_CACHE_H */
8858diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8859index f9f3cd5..58ff438 100644
8860--- a/arch/score/include/asm/exec.h
8861+++ b/arch/score/include/asm/exec.h
8862@@ -1,6 +1,6 @@
8863 #ifndef _ASM_SCORE_EXEC_H
8864 #define _ASM_SCORE_EXEC_H
8865
8866-extern unsigned long arch_align_stack(unsigned long sp);
8867+#define arch_align_stack(x) (x)
8868
8869 #endif /* _ASM_SCORE_EXEC_H */
8870diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8871index f4c6d02..e9355c3 100644
8872--- a/arch/score/kernel/process.c
8873+++ b/arch/score/kernel/process.c
8874@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8875
8876 return task_pt_regs(task)->cp0_epc;
8877 }
8878-
8879-unsigned long arch_align_stack(unsigned long sp)
8880-{
8881- return sp;
8882-}
8883diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8884index ef9e555..331bd29 100644
8885--- a/arch/sh/include/asm/cache.h
8886+++ b/arch/sh/include/asm/cache.h
8887@@ -9,10 +9,11 @@
8888 #define __ASM_SH_CACHE_H
8889 #ifdef __KERNEL__
8890
8891+#include <linux/const.h>
8892 #include <linux/init.h>
8893 #include <cpu/cache.h>
8894
8895-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8896+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8897
8898 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8899
8900diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
8901index 03f2b55..b0270327 100644
8902--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
8903+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
8904@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
8905 return NOTIFY_OK;
8906 }
8907
8908-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
8909+static struct notifier_block shx3_cpu_notifier = {
8910 .notifier_call = shx3_cpu_callback,
8911 };
8912
8913diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8914index 6777177..cb5e44f 100644
8915--- a/arch/sh/mm/mmap.c
8916+++ b/arch/sh/mm/mmap.c
8917@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8918 struct mm_struct *mm = current->mm;
8919 struct vm_area_struct *vma;
8920 int do_colour_align;
8921+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8922 struct vm_unmapped_area_info info;
8923
8924 if (flags & MAP_FIXED) {
8925@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8926 if (filp || (flags & MAP_SHARED))
8927 do_colour_align = 1;
8928
8929+#ifdef CONFIG_PAX_RANDMMAP
8930+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8931+#endif
8932+
8933 if (addr) {
8934 if (do_colour_align)
8935 addr = COLOUR_ALIGN(addr, pgoff);
8936@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8937 addr = PAGE_ALIGN(addr);
8938
8939 vma = find_vma(mm, addr);
8940- if (TASK_SIZE - len >= addr &&
8941- (!vma || addr + len <= vma->vm_start))
8942+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8943 return addr;
8944 }
8945
8946 info.flags = 0;
8947 info.length = len;
8948- info.low_limit = TASK_UNMAPPED_BASE;
8949+ info.low_limit = mm->mmap_base;
8950 info.high_limit = TASK_SIZE;
8951 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8952 info.align_offset = pgoff << PAGE_SHIFT;
8953@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8954 struct mm_struct *mm = current->mm;
8955 unsigned long addr = addr0;
8956 int do_colour_align;
8957+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8958 struct vm_unmapped_area_info info;
8959
8960 if (flags & MAP_FIXED) {
8961@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8962 if (filp || (flags & MAP_SHARED))
8963 do_colour_align = 1;
8964
8965+#ifdef CONFIG_PAX_RANDMMAP
8966+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8967+#endif
8968+
8969 /* requesting a specific address */
8970 if (addr) {
8971 if (do_colour_align)
8972@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8973 addr = PAGE_ALIGN(addr);
8974
8975 vma = find_vma(mm, addr);
8976- if (TASK_SIZE - len >= addr &&
8977- (!vma || addr + len <= vma->vm_start))
8978+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8979 return addr;
8980 }
8981
8982@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8983 VM_BUG_ON(addr != -ENOMEM);
8984 info.flags = 0;
8985 info.low_limit = TASK_UNMAPPED_BASE;
8986+
8987+#ifdef CONFIG_PAX_RANDMMAP
8988+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8989+ info.low_limit += mm->delta_mmap;
8990+#endif
8991+
8992 info.high_limit = TASK_SIZE;
8993 addr = vm_unmapped_area(&info);
8994 }
8995diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8996index be56a24..443328f 100644
8997--- a/arch/sparc/include/asm/atomic_64.h
8998+++ b/arch/sparc/include/asm/atomic_64.h
8999@@ -14,18 +14,40 @@
9000 #define ATOMIC64_INIT(i) { (i) }
9001
9002 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9003+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9004+{
9005+ return v->counter;
9006+}
9007 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9008+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9009+{
9010+ return v->counter;
9011+}
9012
9013 #define atomic_set(v, i) (((v)->counter) = i)
9014+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9015+{
9016+ v->counter = i;
9017+}
9018 #define atomic64_set(v, i) (((v)->counter) = i)
9019+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9020+{
9021+ v->counter = i;
9022+}
9023
9024 extern void atomic_add(int, atomic_t *);
9025+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9026 extern void atomic64_add(long, atomic64_t *);
9027+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9028 extern void atomic_sub(int, atomic_t *);
9029+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9030 extern void atomic64_sub(long, atomic64_t *);
9031+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9032
9033 extern int atomic_add_ret(int, atomic_t *);
9034+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9035 extern long atomic64_add_ret(long, atomic64_t *);
9036+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9037 extern int atomic_sub_ret(int, atomic_t *);
9038 extern long atomic64_sub_ret(long, atomic64_t *);
9039
9040@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9041 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9042
9043 #define atomic_inc_return(v) atomic_add_ret(1, v)
9044+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9045+{
9046+ return atomic_add_ret_unchecked(1, v);
9047+}
9048 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9049+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9050+{
9051+ return atomic64_add_ret_unchecked(1, v);
9052+}
9053
9054 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9055 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9056
9057 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9058+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9059+{
9060+ return atomic_add_ret_unchecked(i, v);
9061+}
9062 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9063+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9064+{
9065+ return atomic64_add_ret_unchecked(i, v);
9066+}
9067
9068 /*
9069 * atomic_inc_and_test - increment and test
9070@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9071 * other cases.
9072 */
9073 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9074+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9075+{
9076+ return atomic_inc_return_unchecked(v) == 0;
9077+}
9078 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9079
9080 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9081@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9082 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9083
9084 #define atomic_inc(v) atomic_add(1, v)
9085+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9086+{
9087+ atomic_add_unchecked(1, v);
9088+}
9089 #define atomic64_inc(v) atomic64_add(1, v)
9090+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9091+{
9092+ atomic64_add_unchecked(1, v);
9093+}
9094
9095 #define atomic_dec(v) atomic_sub(1, v)
9096+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9097+{
9098+ atomic_sub_unchecked(1, v);
9099+}
9100 #define atomic64_dec(v) atomic64_sub(1, v)
9101+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9102+{
9103+ atomic64_sub_unchecked(1, v);
9104+}
9105
9106 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9107 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9108
9109 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9110+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9111+{
9112+ return cmpxchg(&v->counter, old, new);
9113+}
9114 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9115+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9116+{
9117+ return xchg(&v->counter, new);
9118+}
9119
9120 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9121 {
9122- int c, old;
9123+ int c, old, new;
9124 c = atomic_read(v);
9125 for (;;) {
9126- if (unlikely(c == (u)))
9127+ if (unlikely(c == u))
9128 break;
9129- old = atomic_cmpxchg((v), c, c + (a));
9130+
9131+ asm volatile("addcc %2, %0, %0\n"
9132+
9133+#ifdef CONFIG_PAX_REFCOUNT
9134+ "tvs %%icc, 6\n"
9135+#endif
9136+
9137+ : "=r" (new)
9138+ : "0" (c), "ir" (a)
9139+ : "cc");
9140+
9141+ old = atomic_cmpxchg(v, c, new);
9142 if (likely(old == c))
9143 break;
9144 c = old;
9145@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9146 #define atomic64_cmpxchg(v, o, n) \
9147 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9148 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9149+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9150+{
9151+ return xchg(&v->counter, new);
9152+}
9153
9154 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9155 {
9156- long c, old;
9157+ long c, old, new;
9158 c = atomic64_read(v);
9159 for (;;) {
9160- if (unlikely(c == (u)))
9161+ if (unlikely(c == u))
9162 break;
9163- old = atomic64_cmpxchg((v), c, c + (a));
9164+
9165+ asm volatile("addcc %2, %0, %0\n"
9166+
9167+#ifdef CONFIG_PAX_REFCOUNT
9168+ "tvs %%xcc, 6\n"
9169+#endif
9170+
9171+ : "=r" (new)
9172+ : "0" (c), "ir" (a)
9173+ : "cc");
9174+
9175+ old = atomic64_cmpxchg(v, c, new);
9176 if (likely(old == c))
9177 break;
9178 c = old;
9179 }
9180- return c != (u);
9181+ return c != u;
9182 }
9183
9184 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9185diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9186index 5bb6991..5c2132e 100644
9187--- a/arch/sparc/include/asm/cache.h
9188+++ b/arch/sparc/include/asm/cache.h
9189@@ -7,10 +7,12 @@
9190 #ifndef _SPARC_CACHE_H
9191 #define _SPARC_CACHE_H
9192
9193+#include <linux/const.h>
9194+
9195 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9196
9197 #define L1_CACHE_SHIFT 5
9198-#define L1_CACHE_BYTES 32
9199+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9200
9201 #ifdef CONFIG_SPARC32
9202 #define SMP_CACHE_BYTES_SHIFT 5
9203diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9204index a24e41f..47677ff 100644
9205--- a/arch/sparc/include/asm/elf_32.h
9206+++ b/arch/sparc/include/asm/elf_32.h
9207@@ -114,6 +114,13 @@ typedef struct {
9208
9209 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9210
9211+#ifdef CONFIG_PAX_ASLR
9212+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9213+
9214+#define PAX_DELTA_MMAP_LEN 16
9215+#define PAX_DELTA_STACK_LEN 16
9216+#endif
9217+
9218 /* This yields a mask that user programs can use to figure out what
9219 instruction set this cpu supports. This can NOT be done in userspace
9220 on Sparc. */
9221diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9222index 370ca1e..d4f4a98 100644
9223--- a/arch/sparc/include/asm/elf_64.h
9224+++ b/arch/sparc/include/asm/elf_64.h
9225@@ -189,6 +189,13 @@ typedef struct {
9226 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9227 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9228
9229+#ifdef CONFIG_PAX_ASLR
9230+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9231+
9232+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9233+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9234+#endif
9235+
9236 extern unsigned long sparc64_elf_hwcap;
9237 #define ELF_HWCAP sparc64_elf_hwcap
9238
9239diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9240index 9b1c36d..209298b 100644
9241--- a/arch/sparc/include/asm/pgalloc_32.h
9242+++ b/arch/sparc/include/asm/pgalloc_32.h
9243@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9244 }
9245
9246 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9247+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9248
9249 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9250 unsigned long address)
9251diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9252index bcfe063..b333142 100644
9253--- a/arch/sparc/include/asm/pgalloc_64.h
9254+++ b/arch/sparc/include/asm/pgalloc_64.h
9255@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9256 }
9257
9258 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9259+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9260
9261 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9262 {
9263diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9264index 6fc1348..390c50a 100644
9265--- a/arch/sparc/include/asm/pgtable_32.h
9266+++ b/arch/sparc/include/asm/pgtable_32.h
9267@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9268 #define PAGE_SHARED SRMMU_PAGE_SHARED
9269 #define PAGE_COPY SRMMU_PAGE_COPY
9270 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9271+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9272+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9273+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9274 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9275
9276 /* Top-level page directory - dummy used by init-mm.
9277@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9278
9279 /* xwr */
9280 #define __P000 PAGE_NONE
9281-#define __P001 PAGE_READONLY
9282-#define __P010 PAGE_COPY
9283-#define __P011 PAGE_COPY
9284+#define __P001 PAGE_READONLY_NOEXEC
9285+#define __P010 PAGE_COPY_NOEXEC
9286+#define __P011 PAGE_COPY_NOEXEC
9287 #define __P100 PAGE_READONLY
9288 #define __P101 PAGE_READONLY
9289 #define __P110 PAGE_COPY
9290 #define __P111 PAGE_COPY
9291
9292 #define __S000 PAGE_NONE
9293-#define __S001 PAGE_READONLY
9294-#define __S010 PAGE_SHARED
9295-#define __S011 PAGE_SHARED
9296+#define __S001 PAGE_READONLY_NOEXEC
9297+#define __S010 PAGE_SHARED_NOEXEC
9298+#define __S011 PAGE_SHARED_NOEXEC
9299 #define __S100 PAGE_READONLY
9300 #define __S101 PAGE_READONLY
9301 #define __S110 PAGE_SHARED
9302diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9303index 79da178..c2eede8 100644
9304--- a/arch/sparc/include/asm/pgtsrmmu.h
9305+++ b/arch/sparc/include/asm/pgtsrmmu.h
9306@@ -115,6 +115,11 @@
9307 SRMMU_EXEC | SRMMU_REF)
9308 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9309 SRMMU_EXEC | SRMMU_REF)
9310+
9311+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9312+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9313+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9314+
9315 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9316 SRMMU_DIRTY | SRMMU_REF)
9317
9318diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9319index 9689176..63c18ea 100644
9320--- a/arch/sparc/include/asm/spinlock_64.h
9321+++ b/arch/sparc/include/asm/spinlock_64.h
9322@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9323
9324 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9325
9326-static void inline arch_read_lock(arch_rwlock_t *lock)
9327+static inline void arch_read_lock(arch_rwlock_t *lock)
9328 {
9329 unsigned long tmp1, tmp2;
9330
9331 __asm__ __volatile__ (
9332 "1: ldsw [%2], %0\n"
9333 " brlz,pn %0, 2f\n"
9334-"4: add %0, 1, %1\n"
9335+"4: addcc %0, 1, %1\n"
9336+
9337+#ifdef CONFIG_PAX_REFCOUNT
9338+" tvs %%icc, 6\n"
9339+#endif
9340+
9341 " cas [%2], %0, %1\n"
9342 " cmp %0, %1\n"
9343 " bne,pn %%icc, 1b\n"
9344@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9345 " .previous"
9346 : "=&r" (tmp1), "=&r" (tmp2)
9347 : "r" (lock)
9348- : "memory");
9349+ : "memory", "cc");
9350 }
9351
9352-static int inline arch_read_trylock(arch_rwlock_t *lock)
9353+static inline int arch_read_trylock(arch_rwlock_t *lock)
9354 {
9355 int tmp1, tmp2;
9356
9357@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9358 "1: ldsw [%2], %0\n"
9359 " brlz,a,pn %0, 2f\n"
9360 " mov 0, %0\n"
9361-" add %0, 1, %1\n"
9362+" addcc %0, 1, %1\n"
9363+
9364+#ifdef CONFIG_PAX_REFCOUNT
9365+" tvs %%icc, 6\n"
9366+#endif
9367+
9368 " cas [%2], %0, %1\n"
9369 " cmp %0, %1\n"
9370 " bne,pn %%icc, 1b\n"
9371@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9372 return tmp1;
9373 }
9374
9375-static void inline arch_read_unlock(arch_rwlock_t *lock)
9376+static inline void arch_read_unlock(arch_rwlock_t *lock)
9377 {
9378 unsigned long tmp1, tmp2;
9379
9380 __asm__ __volatile__(
9381 "1: lduw [%2], %0\n"
9382-" sub %0, 1, %1\n"
9383+" subcc %0, 1, %1\n"
9384+
9385+#ifdef CONFIG_PAX_REFCOUNT
9386+" tvs %%icc, 6\n"
9387+#endif
9388+
9389 " cas [%2], %0, %1\n"
9390 " cmp %0, %1\n"
9391 " bne,pn %%xcc, 1b\n"
9392@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9393 : "memory");
9394 }
9395
9396-static void inline arch_write_lock(arch_rwlock_t *lock)
9397+static inline void arch_write_lock(arch_rwlock_t *lock)
9398 {
9399 unsigned long mask, tmp1, tmp2;
9400
9401@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9402 : "memory");
9403 }
9404
9405-static void inline arch_write_unlock(arch_rwlock_t *lock)
9406+static inline void arch_write_unlock(arch_rwlock_t *lock)
9407 {
9408 __asm__ __volatile__(
9409 " stw %%g0, [%0]"
9410@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9411 : "memory");
9412 }
9413
9414-static int inline arch_write_trylock(arch_rwlock_t *lock)
9415+static inline int arch_write_trylock(arch_rwlock_t *lock)
9416 {
9417 unsigned long mask, tmp1, tmp2, result;
9418
9419diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9420index dd38075..e7cac83 100644
9421--- a/arch/sparc/include/asm/thread_info_32.h
9422+++ b/arch/sparc/include/asm/thread_info_32.h
9423@@ -49,6 +49,8 @@ struct thread_info {
9424 unsigned long w_saved;
9425
9426 struct restart_block restart_block;
9427+
9428+ unsigned long lowest_stack;
9429 };
9430
9431 /*
9432diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9433index d5e5042..9bfee76 100644
9434--- a/arch/sparc/include/asm/thread_info_64.h
9435+++ b/arch/sparc/include/asm/thread_info_64.h
9436@@ -63,6 +63,8 @@ struct thread_info {
9437 struct pt_regs *kern_una_regs;
9438 unsigned int kern_una_insn;
9439
9440+ unsigned long lowest_stack;
9441+
9442 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9443 };
9444
9445@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9446 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9447 /* flag bit 6 is available */
9448 #define TIF_32BIT 7 /* 32-bit binary */
9449-/* flag bit 8 is available */
9450+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9451 #define TIF_SECCOMP 9 /* secure computing */
9452 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9453 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9454+
9455 /* NOTE: Thread flags >= 12 should be ones we have no interest
9456 * in using in assembly, else we can't use the mask as
9457 * an immediate value in instructions such as andcc.
9458@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9459 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9460 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9461 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9462+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9463
9464 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9465 _TIF_DO_NOTIFY_RESUME_MASK | \
9466 _TIF_NEED_RESCHED)
9467 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9468
9469+#define _TIF_WORK_SYSCALL \
9470+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9471+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9472+
9473+
9474 /*
9475 * Thread-synchronous status.
9476 *
9477diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9478index 0167d26..767bb0c 100644
9479--- a/arch/sparc/include/asm/uaccess.h
9480+++ b/arch/sparc/include/asm/uaccess.h
9481@@ -1,5 +1,6 @@
9482 #ifndef ___ASM_SPARC_UACCESS_H
9483 #define ___ASM_SPARC_UACCESS_H
9484+
9485 #if defined(__sparc__) && defined(__arch64__)
9486 #include <asm/uaccess_64.h>
9487 #else
9488diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9489index 53a28dd..50c38c3 100644
9490--- a/arch/sparc/include/asm/uaccess_32.h
9491+++ b/arch/sparc/include/asm/uaccess_32.h
9492@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9493
9494 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9495 {
9496- if (n && __access_ok((unsigned long) to, n))
9497+ if ((long)n < 0)
9498+ return n;
9499+
9500+ if (n && __access_ok((unsigned long) to, n)) {
9501+ if (!__builtin_constant_p(n))
9502+ check_object_size(from, n, true);
9503 return __copy_user(to, (__force void __user *) from, n);
9504- else
9505+ } else
9506 return n;
9507 }
9508
9509 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9510 {
9511+ if ((long)n < 0)
9512+ return n;
9513+
9514+ if (!__builtin_constant_p(n))
9515+ check_object_size(from, n, true);
9516+
9517 return __copy_user(to, (__force void __user *) from, n);
9518 }
9519
9520 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9521 {
9522- if (n && __access_ok((unsigned long) from, n))
9523+ if ((long)n < 0)
9524+ return n;
9525+
9526+ if (n && __access_ok((unsigned long) from, n)) {
9527+ if (!__builtin_constant_p(n))
9528+ check_object_size(to, n, false);
9529 return __copy_user((__force void __user *) to, from, n);
9530- else
9531+ } else
9532 return n;
9533 }
9534
9535 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9536 {
9537+ if ((long)n < 0)
9538+ return n;
9539+
9540 return __copy_user((__force void __user *) to, from, n);
9541 }
9542
9543diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9544index e562d3c..191f176 100644
9545--- a/arch/sparc/include/asm/uaccess_64.h
9546+++ b/arch/sparc/include/asm/uaccess_64.h
9547@@ -10,6 +10,7 @@
9548 #include <linux/compiler.h>
9549 #include <linux/string.h>
9550 #include <linux/thread_info.h>
9551+#include <linux/kernel.h>
9552 #include <asm/asi.h>
9553 #include <asm/spitfire.h>
9554 #include <asm-generic/uaccess-unaligned.h>
9555@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9556 static inline unsigned long __must_check
9557 copy_from_user(void *to, const void __user *from, unsigned long size)
9558 {
9559- unsigned long ret = ___copy_from_user(to, from, size);
9560+ unsigned long ret;
9561
9562+ if ((long)size < 0 || size > INT_MAX)
9563+ return size;
9564+
9565+ if (!__builtin_constant_p(size))
9566+ check_object_size(to, size, false);
9567+
9568+ ret = ___copy_from_user(to, from, size);
9569 if (unlikely(ret))
9570 ret = copy_from_user_fixup(to, from, size);
9571
9572@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9573 static inline unsigned long __must_check
9574 copy_to_user(void __user *to, const void *from, unsigned long size)
9575 {
9576- unsigned long ret = ___copy_to_user(to, from, size);
9577+ unsigned long ret;
9578
9579+ if ((long)size < 0 || size > INT_MAX)
9580+ return size;
9581+
9582+ if (!__builtin_constant_p(size))
9583+ check_object_size(from, size, true);
9584+
9585+ ret = ___copy_to_user(to, from, size);
9586 if (unlikely(ret))
9587 ret = copy_to_user_fixup(to, from, size);
9588 return ret;
9589diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9590index d432fb2..6056af1 100644
9591--- a/arch/sparc/kernel/Makefile
9592+++ b/arch/sparc/kernel/Makefile
9593@@ -3,7 +3,7 @@
9594 #
9595
9596 asflags-y := -ansi
9597-ccflags-y := -Werror
9598+#ccflags-y := -Werror
9599
9600 extra-y := head_$(BITS).o
9601
9602diff --git a/arch/sparc/kernel/ds.c b/arch/sparc/kernel/ds.c
9603index 5ef48da..11d460f 100644
9604--- a/arch/sparc/kernel/ds.c
9605+++ b/arch/sparc/kernel/ds.c
9606@@ -783,6 +783,16 @@ void ldom_set_var(const char *var, const char *value)
9607 char *base, *p;
9608 int msg_len, loops;
9609
9610+ if (strlen(var) + strlen(value) + 2 >
9611+ sizeof(pkt) - sizeof(pkt.header)) {
9612+ printk(KERN_ERR PFX
9613+ "contents length: %zu, which more than max: %lu,"
9614+ "so could not set (%s) variable to (%s).\n",
9615+ strlen(var) + strlen(value) + 2,
9616+ sizeof(pkt) - sizeof(pkt.header), var, value);
9617+ return;
9618+ }
9619+
9620 memset(&pkt, 0, sizeof(pkt));
9621 pkt.header.data.tag.type = DS_DATA;
9622 pkt.header.data.handle = cp->handle;
9623diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9624index fdd819d..5af08c8 100644
9625--- a/arch/sparc/kernel/process_32.c
9626+++ b/arch/sparc/kernel/process_32.c
9627@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9628
9629 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9630 r->psr, r->pc, r->npc, r->y, print_tainted());
9631- printk("PC: <%pS>\n", (void *) r->pc);
9632+ printk("PC: <%pA>\n", (void *) r->pc);
9633 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9634 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9635 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9636 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9637 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9638 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9639- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9640+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9641
9642 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9643 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9644@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9645 rw = (struct reg_window32 *) fp;
9646 pc = rw->ins[7];
9647 printk("[%08lx : ", pc);
9648- printk("%pS ] ", (void *) pc);
9649+ printk("%pA ] ", (void *) pc);
9650 fp = rw->ins[6];
9651 } while (++count < 16);
9652 printk("\n");
9653diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9654index baebab2..9cd13b1 100644
9655--- a/arch/sparc/kernel/process_64.c
9656+++ b/arch/sparc/kernel/process_64.c
9657@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9658 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9659 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9660 if (regs->tstate & TSTATE_PRIV)
9661- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9662+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9663 }
9664
9665 void show_regs(struct pt_regs *regs)
9666@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9667
9668 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9669 regs->tpc, regs->tnpc, regs->y, print_tainted());
9670- printk("TPC: <%pS>\n", (void *) regs->tpc);
9671+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9672 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9673 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9674 regs->u_regs[3]);
9675@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9676 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9677 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9678 regs->u_regs[15]);
9679- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9680+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9681 show_regwindow(regs);
9682 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9683 }
9684@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9685 ((tp && tp->task) ? tp->task->pid : -1));
9686
9687 if (gp->tstate & TSTATE_PRIV) {
9688- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9689+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9690 (void *) gp->tpc,
9691 (void *) gp->o7,
9692 (void *) gp->i7,
9693diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9694index 79cc0d1..ec62734 100644
9695--- a/arch/sparc/kernel/prom_common.c
9696+++ b/arch/sparc/kernel/prom_common.c
9697@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9698
9699 unsigned int prom_early_allocated __initdata;
9700
9701-static struct of_pdt_ops prom_sparc_ops __initdata = {
9702+static struct of_pdt_ops prom_sparc_ops __initconst = {
9703 .nextprop = prom_common_nextprop,
9704 .getproplen = prom_getproplen,
9705 .getproperty = prom_getproperty,
9706diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9707index 7ff45e4..a58f271 100644
9708--- a/arch/sparc/kernel/ptrace_64.c
9709+++ b/arch/sparc/kernel/ptrace_64.c
9710@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
9711 return ret;
9712 }
9713
9714+#ifdef CONFIG_GRKERNSEC_SETXID
9715+extern void gr_delayed_cred_worker(void);
9716+#endif
9717+
9718 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9719 {
9720 int ret = 0;
9721@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9722 /* do the secure computing check first */
9723 secure_computing_strict(regs->u_regs[UREG_G1]);
9724
9725+#ifdef CONFIG_GRKERNSEC_SETXID
9726+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9727+ gr_delayed_cred_worker();
9728+#endif
9729+
9730 if (test_thread_flag(TIF_SYSCALL_TRACE))
9731 ret = tracehook_report_syscall_entry(regs);
9732
9733@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9734
9735 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9736 {
9737+#ifdef CONFIG_GRKERNSEC_SETXID
9738+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9739+ gr_delayed_cred_worker();
9740+#endif
9741+
9742 audit_syscall_exit(regs);
9743
9744 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9745diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9746index 77539ed..3ffffe7 100644
9747--- a/arch/sparc/kernel/smp_64.c
9748+++ b/arch/sparc/kernel/smp_64.c
9749@@ -868,8 +868,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9750 extern unsigned long xcall_flush_dcache_page_spitfire;
9751
9752 #ifdef CONFIG_DEBUG_DCFLUSH
9753-extern atomic_t dcpage_flushes;
9754-extern atomic_t dcpage_flushes_xcall;
9755+extern atomic_unchecked_t dcpage_flushes;
9756+extern atomic_unchecked_t dcpage_flushes_xcall;
9757 #endif
9758
9759 static inline void __local_flush_dcache_page(struct page *page)
9760@@ -893,7 +893,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9761 return;
9762
9763 #ifdef CONFIG_DEBUG_DCFLUSH
9764- atomic_inc(&dcpage_flushes);
9765+ atomic_inc_unchecked(&dcpage_flushes);
9766 #endif
9767
9768 this_cpu = get_cpu();
9769@@ -917,7 +917,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9770 xcall_deliver(data0, __pa(pg_addr),
9771 (u64) pg_addr, cpumask_of(cpu));
9772 #ifdef CONFIG_DEBUG_DCFLUSH
9773- atomic_inc(&dcpage_flushes_xcall);
9774+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9775 #endif
9776 }
9777 }
9778@@ -936,7 +936,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9779 preempt_disable();
9780
9781 #ifdef CONFIG_DEBUG_DCFLUSH
9782- atomic_inc(&dcpage_flushes);
9783+ atomic_inc_unchecked(&dcpage_flushes);
9784 #endif
9785 data0 = 0;
9786 pg_addr = page_address(page);
9787@@ -953,7 +953,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9788 xcall_deliver(data0, __pa(pg_addr),
9789 (u64) pg_addr, cpu_online_mask);
9790 #ifdef CONFIG_DEBUG_DCFLUSH
9791- atomic_inc(&dcpage_flushes_xcall);
9792+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9793 #endif
9794 }
9795 __local_flush_dcache_page(page);
9796diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9797index 3a8d184..49498a8 100644
9798--- a/arch/sparc/kernel/sys_sparc_32.c
9799+++ b/arch/sparc/kernel/sys_sparc_32.c
9800@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9801 if (len > TASK_SIZE - PAGE_SIZE)
9802 return -ENOMEM;
9803 if (!addr)
9804- addr = TASK_UNMAPPED_BASE;
9805+ addr = current->mm->mmap_base;
9806
9807 info.flags = 0;
9808 info.length = len;
9809diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9810index 2daaaa6..4fb84dc 100644
9811--- a/arch/sparc/kernel/sys_sparc_64.c
9812+++ b/arch/sparc/kernel/sys_sparc_64.c
9813@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9814 struct vm_area_struct * vma;
9815 unsigned long task_size = TASK_SIZE;
9816 int do_color_align;
9817+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9818 struct vm_unmapped_area_info info;
9819
9820 if (flags & MAP_FIXED) {
9821 /* We do not accept a shared mapping if it would violate
9822 * cache aliasing constraints.
9823 */
9824- if ((flags & MAP_SHARED) &&
9825+ if ((filp || (flags & MAP_SHARED)) &&
9826 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9827 return -EINVAL;
9828 return addr;
9829@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9830 if (filp || (flags & MAP_SHARED))
9831 do_color_align = 1;
9832
9833+#ifdef CONFIG_PAX_RANDMMAP
9834+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9835+#endif
9836+
9837 if (addr) {
9838 if (do_color_align)
9839 addr = COLOR_ALIGN(addr, pgoff);
9840@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9841 addr = PAGE_ALIGN(addr);
9842
9843 vma = find_vma(mm, addr);
9844- if (task_size - len >= addr &&
9845- (!vma || addr + len <= vma->vm_start))
9846+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9847 return addr;
9848 }
9849
9850 info.flags = 0;
9851 info.length = len;
9852- info.low_limit = TASK_UNMAPPED_BASE;
9853+ info.low_limit = mm->mmap_base;
9854 info.high_limit = min(task_size, VA_EXCLUDE_START);
9855 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9856 info.align_offset = pgoff << PAGE_SHIFT;
9857+ info.threadstack_offset = offset;
9858 addr = vm_unmapped_area(&info);
9859
9860 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9861 VM_BUG_ON(addr != -ENOMEM);
9862 info.low_limit = VA_EXCLUDE_END;
9863+
9864+#ifdef CONFIG_PAX_RANDMMAP
9865+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9866+ info.low_limit += mm->delta_mmap;
9867+#endif
9868+
9869 info.high_limit = task_size;
9870 addr = vm_unmapped_area(&info);
9871 }
9872@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9873 unsigned long task_size = STACK_TOP32;
9874 unsigned long addr = addr0;
9875 int do_color_align;
9876+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9877 struct vm_unmapped_area_info info;
9878
9879 /* This should only ever run for 32-bit processes. */
9880@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9881 /* We do not accept a shared mapping if it would violate
9882 * cache aliasing constraints.
9883 */
9884- if ((flags & MAP_SHARED) &&
9885+ if ((filp || (flags & MAP_SHARED)) &&
9886 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9887 return -EINVAL;
9888 return addr;
9889@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9890 if (filp || (flags & MAP_SHARED))
9891 do_color_align = 1;
9892
9893+#ifdef CONFIG_PAX_RANDMMAP
9894+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9895+#endif
9896+
9897 /* requesting a specific address */
9898 if (addr) {
9899 if (do_color_align)
9900@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9901 addr = PAGE_ALIGN(addr);
9902
9903 vma = find_vma(mm, addr);
9904- if (task_size - len >= addr &&
9905- (!vma || addr + len <= vma->vm_start))
9906+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9907 return addr;
9908 }
9909
9910@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9911 info.high_limit = mm->mmap_base;
9912 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9913 info.align_offset = pgoff << PAGE_SHIFT;
9914+ info.threadstack_offset = offset;
9915 addr = vm_unmapped_area(&info);
9916
9917 /*
9918@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9919 VM_BUG_ON(addr != -ENOMEM);
9920 info.flags = 0;
9921 info.low_limit = TASK_UNMAPPED_BASE;
9922+
9923+#ifdef CONFIG_PAX_RANDMMAP
9924+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9925+ info.low_limit += mm->delta_mmap;
9926+#endif
9927+
9928 info.high_limit = STACK_TOP32;
9929 addr = vm_unmapped_area(&info);
9930 }
9931@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9932 EXPORT_SYMBOL(get_fb_unmapped_area);
9933
9934 /* Essentially the same as PowerPC. */
9935-static unsigned long mmap_rnd(void)
9936+static unsigned long mmap_rnd(struct mm_struct *mm)
9937 {
9938 unsigned long rnd = 0UL;
9939
9940+#ifdef CONFIG_PAX_RANDMMAP
9941+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9942+#endif
9943+
9944 if (current->flags & PF_RANDOMIZE) {
9945 unsigned long val = get_random_int();
9946 if (test_thread_flag(TIF_32BIT))
9947@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9948
9949 void arch_pick_mmap_layout(struct mm_struct *mm)
9950 {
9951- unsigned long random_factor = mmap_rnd();
9952+ unsigned long random_factor = mmap_rnd(mm);
9953 unsigned long gap;
9954
9955 /*
9956@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9957 gap == RLIM_INFINITY ||
9958 sysctl_legacy_va_layout) {
9959 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9960+
9961+#ifdef CONFIG_PAX_RANDMMAP
9962+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9963+ mm->mmap_base += mm->delta_mmap;
9964+#endif
9965+
9966 mm->get_unmapped_area = arch_get_unmapped_area;
9967 mm->unmap_area = arch_unmap_area;
9968 } else {
9969@@ -301,6 +333,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9970 gap = (task_size / 6 * 5);
9971
9972 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9973+
9974+#ifdef CONFIG_PAX_RANDMMAP
9975+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9976+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9977+#endif
9978+
9979 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9980 mm->unmap_area = arch_unmap_area_topdown;
9981 }
9982diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9983index 22a1098..6255eb9 100644
9984--- a/arch/sparc/kernel/syscalls.S
9985+++ b/arch/sparc/kernel/syscalls.S
9986@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9987 #endif
9988 .align 32
9989 1: ldx [%g6 + TI_FLAGS], %l5
9990- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9991+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9992 be,pt %icc, rtrap
9993 nop
9994 call syscall_trace_leave
9995@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9996
9997 srl %i5, 0, %o5 ! IEU1
9998 srl %i2, 0, %o2 ! IEU0 Group
9999- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
10000+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10001 bne,pn %icc, linux_syscall_trace32 ! CTI
10002 mov %i0, %l5 ! IEU1
10003 call %l7 ! CTI Group brk forced
10004@@ -207,7 +207,7 @@ linux_sparc_syscall:
10005
10006 mov %i3, %o3 ! IEU1
10007 mov %i4, %o4 ! IEU0 Group
10008- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
10009+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10010 bne,pn %icc, linux_syscall_trace ! CTI Group
10011 mov %i0, %l5 ! IEU0
10012 2: call %l7 ! CTI Group brk forced
10013@@ -223,7 +223,7 @@ ret_sys_call:
10014
10015 cmp %o0, -ERESTART_RESTARTBLOCK
10016 bgeu,pn %xcc, 1f
10017- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
10018+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10019 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10020
10021 2:
10022diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
10023index 654e8aa..45f431b 100644
10024--- a/arch/sparc/kernel/sysfs.c
10025+++ b/arch/sparc/kernel/sysfs.c
10026@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
10027 return NOTIFY_OK;
10028 }
10029
10030-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
10031+static struct notifier_block sysfs_cpu_nb = {
10032 .notifier_call = sysfs_cpu_notify,
10033 };
10034
10035diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10036index 6629829..036032d 100644
10037--- a/arch/sparc/kernel/traps_32.c
10038+++ b/arch/sparc/kernel/traps_32.c
10039@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10040 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10041 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10042
10043+extern void gr_handle_kernel_exploit(void);
10044+
10045 void die_if_kernel(char *str, struct pt_regs *regs)
10046 {
10047 static int die_counter;
10048@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10049 count++ < 30 &&
10050 (((unsigned long) rw) >= PAGE_OFFSET) &&
10051 !(((unsigned long) rw) & 0x7)) {
10052- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10053+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10054 (void *) rw->ins[7]);
10055 rw = (struct reg_window32 *)rw->ins[6];
10056 }
10057 }
10058 printk("Instruction DUMP:");
10059 instruction_dump ((unsigned long *) regs->pc);
10060- if(regs->psr & PSR_PS)
10061+ if(regs->psr & PSR_PS) {
10062+ gr_handle_kernel_exploit();
10063 do_exit(SIGKILL);
10064+ }
10065 do_exit(SIGSEGV);
10066 }
10067
10068diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10069index b3f833a..f485f80 100644
10070--- a/arch/sparc/kernel/traps_64.c
10071+++ b/arch/sparc/kernel/traps_64.c
10072@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10073 i + 1,
10074 p->trapstack[i].tstate, p->trapstack[i].tpc,
10075 p->trapstack[i].tnpc, p->trapstack[i].tt);
10076- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10077+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10078 }
10079 }
10080
10081@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10082
10083 lvl -= 0x100;
10084 if (regs->tstate & TSTATE_PRIV) {
10085+
10086+#ifdef CONFIG_PAX_REFCOUNT
10087+ if (lvl == 6)
10088+ pax_report_refcount_overflow(regs);
10089+#endif
10090+
10091 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10092 die_if_kernel(buffer, regs);
10093 }
10094@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10095 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10096 {
10097 char buffer[32];
10098-
10099+
10100 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10101 0, lvl, SIGTRAP) == NOTIFY_STOP)
10102 return;
10103
10104+#ifdef CONFIG_PAX_REFCOUNT
10105+ if (lvl == 6)
10106+ pax_report_refcount_overflow(regs);
10107+#endif
10108+
10109 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10110
10111 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10112@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10113 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10114 printk("%s" "ERROR(%d): ",
10115 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10116- printk("TPC<%pS>\n", (void *) regs->tpc);
10117+ printk("TPC<%pA>\n", (void *) regs->tpc);
10118 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10119 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10120 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10121@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10122 smp_processor_id(),
10123 (type & 0x1) ? 'I' : 'D',
10124 regs->tpc);
10125- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10126+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10127 panic("Irrecoverable Cheetah+ parity error.");
10128 }
10129
10130@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10131 smp_processor_id(),
10132 (type & 0x1) ? 'I' : 'D',
10133 regs->tpc);
10134- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10135+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10136 }
10137
10138 struct sun4v_error_entry {
10139@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
10140 /*0x38*/u64 reserved_5;
10141 };
10142
10143-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10144-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10145+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10146+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10147
10148 static const char *sun4v_err_type_to_str(u8 type)
10149 {
10150@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10151 }
10152
10153 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10154- int cpu, const char *pfx, atomic_t *ocnt)
10155+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10156 {
10157 u64 *raw_ptr = (u64 *) ent;
10158 u32 attrs;
10159@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10160
10161 show_regs(regs);
10162
10163- if ((cnt = atomic_read(ocnt)) != 0) {
10164- atomic_set(ocnt, 0);
10165+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10166+ atomic_set_unchecked(ocnt, 0);
10167 wmb();
10168 printk("%s: Queue overflowed %d times.\n",
10169 pfx, cnt);
10170@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
10171 */
10172 void sun4v_resum_overflow(struct pt_regs *regs)
10173 {
10174- atomic_inc(&sun4v_resum_oflow_cnt);
10175+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10176 }
10177
10178 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10179@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10180 /* XXX Actually even this can make not that much sense. Perhaps
10181 * XXX we should just pull the plug and panic directly from here?
10182 */
10183- atomic_inc(&sun4v_nonresum_oflow_cnt);
10184+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10185 }
10186
10187 unsigned long sun4v_err_itlb_vaddr;
10188@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10189
10190 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10191 regs->tpc, tl);
10192- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10193+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10194 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10195- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10196+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10197 (void *) regs->u_regs[UREG_I7]);
10198 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10199 "pte[%lx] error[%lx]\n",
10200@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10201
10202 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10203 regs->tpc, tl);
10204- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10205+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10206 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10207- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10208+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10209 (void *) regs->u_regs[UREG_I7]);
10210 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10211 "pte[%lx] error[%lx]\n",
10212@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10213 fp = (unsigned long)sf->fp + STACK_BIAS;
10214 }
10215
10216- printk(" [%016lx] %pS\n", pc, (void *) pc);
10217+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10218 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10219 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10220 int index = tsk->curr_ret_stack;
10221 if (tsk->ret_stack && index >= graph) {
10222 pc = tsk->ret_stack[index - graph].ret;
10223- printk(" [%016lx] %pS\n", pc, (void *) pc);
10224+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10225 graph++;
10226 }
10227 }
10228@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10229 return (struct reg_window *) (fp + STACK_BIAS);
10230 }
10231
10232+extern void gr_handle_kernel_exploit(void);
10233+
10234 void die_if_kernel(char *str, struct pt_regs *regs)
10235 {
10236 static int die_counter;
10237@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10238 while (rw &&
10239 count++ < 30 &&
10240 kstack_valid(tp, (unsigned long) rw)) {
10241- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10242+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10243 (void *) rw->ins[7]);
10244
10245 rw = kernel_stack_up(rw);
10246@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10247 }
10248 user_instruction_dump ((unsigned int __user *) regs->tpc);
10249 }
10250- if (regs->tstate & TSTATE_PRIV)
10251+ if (regs->tstate & TSTATE_PRIV) {
10252+ gr_handle_kernel_exploit();
10253 do_exit(SIGKILL);
10254+ }
10255 do_exit(SIGSEGV);
10256 }
10257 EXPORT_SYMBOL(die_if_kernel);
10258diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10259index 8201c25e..072a2a7 100644
10260--- a/arch/sparc/kernel/unaligned_64.c
10261+++ b/arch/sparc/kernel/unaligned_64.c
10262@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10263 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10264
10265 if (__ratelimit(&ratelimit)) {
10266- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10267+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10268 regs->tpc, (void *) regs->tpc);
10269 }
10270 }
10271diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10272index dbe119b..089c7c1 100644
10273--- a/arch/sparc/lib/Makefile
10274+++ b/arch/sparc/lib/Makefile
10275@@ -2,7 +2,7 @@
10276 #
10277
10278 asflags-y := -ansi -DST_DIV0=0x02
10279-ccflags-y := -Werror
10280+#ccflags-y := -Werror
10281
10282 lib-$(CONFIG_SPARC32) += ashrdi3.o
10283 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10284diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10285index 85c233d..68500e0 100644
10286--- a/arch/sparc/lib/atomic_64.S
10287+++ b/arch/sparc/lib/atomic_64.S
10288@@ -17,7 +17,12 @@
10289 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10290 BACKOFF_SETUP(%o2)
10291 1: lduw [%o1], %g1
10292- add %g1, %o0, %g7
10293+ addcc %g1, %o0, %g7
10294+
10295+#ifdef CONFIG_PAX_REFCOUNT
10296+ tvs %icc, 6
10297+#endif
10298+
10299 cas [%o1], %g1, %g7
10300 cmp %g1, %g7
10301 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10302@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10303 2: BACKOFF_SPIN(%o2, %o3, 1b)
10304 ENDPROC(atomic_add)
10305
10306+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10307+ BACKOFF_SETUP(%o2)
10308+1: lduw [%o1], %g1
10309+ add %g1, %o0, %g7
10310+ cas [%o1], %g1, %g7
10311+ cmp %g1, %g7
10312+ bne,pn %icc, 2f
10313+ nop
10314+ retl
10315+ nop
10316+2: BACKOFF_SPIN(%o2, %o3, 1b)
10317+ENDPROC(atomic_add_unchecked)
10318+
10319 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10320 BACKOFF_SETUP(%o2)
10321 1: lduw [%o1], %g1
10322- sub %g1, %o0, %g7
10323+ subcc %g1, %o0, %g7
10324+
10325+#ifdef CONFIG_PAX_REFCOUNT
10326+ tvs %icc, 6
10327+#endif
10328+
10329 cas [%o1], %g1, %g7
10330 cmp %g1, %g7
10331 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10332@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10333 2: BACKOFF_SPIN(%o2, %o3, 1b)
10334 ENDPROC(atomic_sub)
10335
10336+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10337+ BACKOFF_SETUP(%o2)
10338+1: lduw [%o1], %g1
10339+ sub %g1, %o0, %g7
10340+ cas [%o1], %g1, %g7
10341+ cmp %g1, %g7
10342+ bne,pn %icc, 2f
10343+ nop
10344+ retl
10345+ nop
10346+2: BACKOFF_SPIN(%o2, %o3, 1b)
10347+ENDPROC(atomic_sub_unchecked)
10348+
10349 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10350 BACKOFF_SETUP(%o2)
10351 1: lduw [%o1], %g1
10352- add %g1, %o0, %g7
10353+ addcc %g1, %o0, %g7
10354+
10355+#ifdef CONFIG_PAX_REFCOUNT
10356+ tvs %icc, 6
10357+#endif
10358+
10359 cas [%o1], %g1, %g7
10360 cmp %g1, %g7
10361 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10362@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10363 2: BACKOFF_SPIN(%o2, %o3, 1b)
10364 ENDPROC(atomic_add_ret)
10365
10366+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10367+ BACKOFF_SETUP(%o2)
10368+1: lduw [%o1], %g1
10369+ addcc %g1, %o0, %g7
10370+ cas [%o1], %g1, %g7
10371+ cmp %g1, %g7
10372+ bne,pn %icc, 2f
10373+ add %g7, %o0, %g7
10374+ sra %g7, 0, %o0
10375+ retl
10376+ nop
10377+2: BACKOFF_SPIN(%o2, %o3, 1b)
10378+ENDPROC(atomic_add_ret_unchecked)
10379+
10380 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10381 BACKOFF_SETUP(%o2)
10382 1: lduw [%o1], %g1
10383- sub %g1, %o0, %g7
10384+ subcc %g1, %o0, %g7
10385+
10386+#ifdef CONFIG_PAX_REFCOUNT
10387+ tvs %icc, 6
10388+#endif
10389+
10390 cas [%o1], %g1, %g7
10391 cmp %g1, %g7
10392 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10393@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10394 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10395 BACKOFF_SETUP(%o2)
10396 1: ldx [%o1], %g1
10397- add %g1, %o0, %g7
10398+ addcc %g1, %o0, %g7
10399+
10400+#ifdef CONFIG_PAX_REFCOUNT
10401+ tvs %xcc, 6
10402+#endif
10403+
10404 casx [%o1], %g1, %g7
10405 cmp %g1, %g7
10406 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10407@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10408 2: BACKOFF_SPIN(%o2, %o3, 1b)
10409 ENDPROC(atomic64_add)
10410
10411+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10412+ BACKOFF_SETUP(%o2)
10413+1: ldx [%o1], %g1
10414+ addcc %g1, %o0, %g7
10415+ casx [%o1], %g1, %g7
10416+ cmp %g1, %g7
10417+ bne,pn %xcc, 2f
10418+ nop
10419+ retl
10420+ nop
10421+2: BACKOFF_SPIN(%o2, %o3, 1b)
10422+ENDPROC(atomic64_add_unchecked)
10423+
10424 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10425 BACKOFF_SETUP(%o2)
10426 1: ldx [%o1], %g1
10427- sub %g1, %o0, %g7
10428+ subcc %g1, %o0, %g7
10429+
10430+#ifdef CONFIG_PAX_REFCOUNT
10431+ tvs %xcc, 6
10432+#endif
10433+
10434 casx [%o1], %g1, %g7
10435 cmp %g1, %g7
10436 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10437@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10438 2: BACKOFF_SPIN(%o2, %o3, 1b)
10439 ENDPROC(atomic64_sub)
10440
10441+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10442+ BACKOFF_SETUP(%o2)
10443+1: ldx [%o1], %g1
10444+ subcc %g1, %o0, %g7
10445+ casx [%o1], %g1, %g7
10446+ cmp %g1, %g7
10447+ bne,pn %xcc, 2f
10448+ nop
10449+ retl
10450+ nop
10451+2: BACKOFF_SPIN(%o2, %o3, 1b)
10452+ENDPROC(atomic64_sub_unchecked)
10453+
10454 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10455 BACKOFF_SETUP(%o2)
10456 1: ldx [%o1], %g1
10457- add %g1, %o0, %g7
10458+ addcc %g1, %o0, %g7
10459+
10460+#ifdef CONFIG_PAX_REFCOUNT
10461+ tvs %xcc, 6
10462+#endif
10463+
10464 casx [%o1], %g1, %g7
10465 cmp %g1, %g7
10466 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10467@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10468 2: BACKOFF_SPIN(%o2, %o3, 1b)
10469 ENDPROC(atomic64_add_ret)
10470
10471+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10472+ BACKOFF_SETUP(%o2)
10473+1: ldx [%o1], %g1
10474+ addcc %g1, %o0, %g7
10475+ casx [%o1], %g1, %g7
10476+ cmp %g1, %g7
10477+ bne,pn %xcc, 2f
10478+ add %g7, %o0, %g7
10479+ mov %g7, %o0
10480+ retl
10481+ nop
10482+2: BACKOFF_SPIN(%o2, %o3, 1b)
10483+ENDPROC(atomic64_add_ret_unchecked)
10484+
10485 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10486 BACKOFF_SETUP(%o2)
10487 1: ldx [%o1], %g1
10488- sub %g1, %o0, %g7
10489+ subcc %g1, %o0, %g7
10490+
10491+#ifdef CONFIG_PAX_REFCOUNT
10492+ tvs %xcc, 6
10493+#endif
10494+
10495 casx [%o1], %g1, %g7
10496 cmp %g1, %g7
10497 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10498diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10499index 0c4e35e..745d3e4 100644
10500--- a/arch/sparc/lib/ksyms.c
10501+++ b/arch/sparc/lib/ksyms.c
10502@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
10503
10504 /* Atomic counter implementation. */
10505 EXPORT_SYMBOL(atomic_add);
10506+EXPORT_SYMBOL(atomic_add_unchecked);
10507 EXPORT_SYMBOL(atomic_add_ret);
10508+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10509 EXPORT_SYMBOL(atomic_sub);
10510+EXPORT_SYMBOL(atomic_sub_unchecked);
10511 EXPORT_SYMBOL(atomic_sub_ret);
10512 EXPORT_SYMBOL(atomic64_add);
10513+EXPORT_SYMBOL(atomic64_add_unchecked);
10514 EXPORT_SYMBOL(atomic64_add_ret);
10515+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10516 EXPORT_SYMBOL(atomic64_sub);
10517+EXPORT_SYMBOL(atomic64_sub_unchecked);
10518 EXPORT_SYMBOL(atomic64_sub_ret);
10519 EXPORT_SYMBOL(atomic64_dec_if_positive);
10520
10521diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10522index 30c3ecc..736f015 100644
10523--- a/arch/sparc/mm/Makefile
10524+++ b/arch/sparc/mm/Makefile
10525@@ -2,7 +2,7 @@
10526 #
10527
10528 asflags-y := -ansi
10529-ccflags-y := -Werror
10530+#ccflags-y := -Werror
10531
10532 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10533 obj-y += fault_$(BITS).o
10534diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10535index e98bfda..ea8d221 100644
10536--- a/arch/sparc/mm/fault_32.c
10537+++ b/arch/sparc/mm/fault_32.c
10538@@ -21,6 +21,9 @@
10539 #include <linux/perf_event.h>
10540 #include <linux/interrupt.h>
10541 #include <linux/kdebug.h>
10542+#include <linux/slab.h>
10543+#include <linux/pagemap.h>
10544+#include <linux/compiler.h>
10545
10546 #include <asm/page.h>
10547 #include <asm/pgtable.h>
10548@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10549 return safe_compute_effective_address(regs, insn);
10550 }
10551
10552+#ifdef CONFIG_PAX_PAGEEXEC
10553+#ifdef CONFIG_PAX_DLRESOLVE
10554+static void pax_emuplt_close(struct vm_area_struct *vma)
10555+{
10556+ vma->vm_mm->call_dl_resolve = 0UL;
10557+}
10558+
10559+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10560+{
10561+ unsigned int *kaddr;
10562+
10563+ vmf->page = alloc_page(GFP_HIGHUSER);
10564+ if (!vmf->page)
10565+ return VM_FAULT_OOM;
10566+
10567+ kaddr = kmap(vmf->page);
10568+ memset(kaddr, 0, PAGE_SIZE);
10569+ kaddr[0] = 0x9DE3BFA8U; /* save */
10570+ flush_dcache_page(vmf->page);
10571+ kunmap(vmf->page);
10572+ return VM_FAULT_MAJOR;
10573+}
10574+
10575+static const struct vm_operations_struct pax_vm_ops = {
10576+ .close = pax_emuplt_close,
10577+ .fault = pax_emuplt_fault
10578+};
10579+
10580+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10581+{
10582+ int ret;
10583+
10584+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10585+ vma->vm_mm = current->mm;
10586+ vma->vm_start = addr;
10587+ vma->vm_end = addr + PAGE_SIZE;
10588+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10589+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10590+ vma->vm_ops = &pax_vm_ops;
10591+
10592+ ret = insert_vm_struct(current->mm, vma);
10593+ if (ret)
10594+ return ret;
10595+
10596+ ++current->mm->total_vm;
10597+ return 0;
10598+}
10599+#endif
10600+
10601+/*
10602+ * PaX: decide what to do with offenders (regs->pc = fault address)
10603+ *
10604+ * returns 1 when task should be killed
10605+ * 2 when patched PLT trampoline was detected
10606+ * 3 when unpatched PLT trampoline was detected
10607+ */
10608+static int pax_handle_fetch_fault(struct pt_regs *regs)
10609+{
10610+
10611+#ifdef CONFIG_PAX_EMUPLT
10612+ int err;
10613+
10614+ do { /* PaX: patched PLT emulation #1 */
10615+ unsigned int sethi1, sethi2, jmpl;
10616+
10617+ err = get_user(sethi1, (unsigned int *)regs->pc);
10618+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10619+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10620+
10621+ if (err)
10622+ break;
10623+
10624+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10625+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10626+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10627+ {
10628+ unsigned int addr;
10629+
10630+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10631+ addr = regs->u_regs[UREG_G1];
10632+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10633+ regs->pc = addr;
10634+ regs->npc = addr+4;
10635+ return 2;
10636+ }
10637+ } while (0);
10638+
10639+ do { /* PaX: patched PLT emulation #2 */
10640+ unsigned int ba;
10641+
10642+ err = get_user(ba, (unsigned int *)regs->pc);
10643+
10644+ if (err)
10645+ break;
10646+
10647+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10648+ unsigned int addr;
10649+
10650+ if ((ba & 0xFFC00000U) == 0x30800000U)
10651+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10652+ else
10653+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10654+ regs->pc = addr;
10655+ regs->npc = addr+4;
10656+ return 2;
10657+ }
10658+ } while (0);
10659+
10660+ do { /* PaX: patched PLT emulation #3 */
10661+ unsigned int sethi, bajmpl, nop;
10662+
10663+ err = get_user(sethi, (unsigned int *)regs->pc);
10664+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10665+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10666+
10667+ if (err)
10668+ break;
10669+
10670+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10671+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10672+ nop == 0x01000000U)
10673+ {
10674+ unsigned int addr;
10675+
10676+ addr = (sethi & 0x003FFFFFU) << 10;
10677+ regs->u_regs[UREG_G1] = addr;
10678+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10679+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10680+ else
10681+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10682+ regs->pc = addr;
10683+ regs->npc = addr+4;
10684+ return 2;
10685+ }
10686+ } while (0);
10687+
10688+ do { /* PaX: unpatched PLT emulation step 1 */
10689+ unsigned int sethi, ba, nop;
10690+
10691+ err = get_user(sethi, (unsigned int *)regs->pc);
10692+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10693+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10694+
10695+ if (err)
10696+ break;
10697+
10698+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10699+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10700+ nop == 0x01000000U)
10701+ {
10702+ unsigned int addr, save, call;
10703+
10704+ if ((ba & 0xFFC00000U) == 0x30800000U)
10705+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10706+ else
10707+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10708+
10709+ err = get_user(save, (unsigned int *)addr);
10710+ err |= get_user(call, (unsigned int *)(addr+4));
10711+ err |= get_user(nop, (unsigned int *)(addr+8));
10712+ if (err)
10713+ break;
10714+
10715+#ifdef CONFIG_PAX_DLRESOLVE
10716+ if (save == 0x9DE3BFA8U &&
10717+ (call & 0xC0000000U) == 0x40000000U &&
10718+ nop == 0x01000000U)
10719+ {
10720+ struct vm_area_struct *vma;
10721+ unsigned long call_dl_resolve;
10722+
10723+ down_read(&current->mm->mmap_sem);
10724+ call_dl_resolve = current->mm->call_dl_resolve;
10725+ up_read(&current->mm->mmap_sem);
10726+ if (likely(call_dl_resolve))
10727+ goto emulate;
10728+
10729+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10730+
10731+ down_write(&current->mm->mmap_sem);
10732+ if (current->mm->call_dl_resolve) {
10733+ call_dl_resolve = current->mm->call_dl_resolve;
10734+ up_write(&current->mm->mmap_sem);
10735+ if (vma)
10736+ kmem_cache_free(vm_area_cachep, vma);
10737+ goto emulate;
10738+ }
10739+
10740+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10741+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10742+ up_write(&current->mm->mmap_sem);
10743+ if (vma)
10744+ kmem_cache_free(vm_area_cachep, vma);
10745+ return 1;
10746+ }
10747+
10748+ if (pax_insert_vma(vma, call_dl_resolve)) {
10749+ up_write(&current->mm->mmap_sem);
10750+ kmem_cache_free(vm_area_cachep, vma);
10751+ return 1;
10752+ }
10753+
10754+ current->mm->call_dl_resolve = call_dl_resolve;
10755+ up_write(&current->mm->mmap_sem);
10756+
10757+emulate:
10758+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10759+ regs->pc = call_dl_resolve;
10760+ regs->npc = addr+4;
10761+ return 3;
10762+ }
10763+#endif
10764+
10765+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10766+ if ((save & 0xFFC00000U) == 0x05000000U &&
10767+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10768+ nop == 0x01000000U)
10769+ {
10770+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10771+ regs->u_regs[UREG_G2] = addr + 4;
10772+ addr = (save & 0x003FFFFFU) << 10;
10773+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10774+ regs->pc = addr;
10775+ regs->npc = addr+4;
10776+ return 3;
10777+ }
10778+ }
10779+ } while (0);
10780+
10781+ do { /* PaX: unpatched PLT emulation step 2 */
10782+ unsigned int save, call, nop;
10783+
10784+ err = get_user(save, (unsigned int *)(regs->pc-4));
10785+ err |= get_user(call, (unsigned int *)regs->pc);
10786+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10787+ if (err)
10788+ break;
10789+
10790+ if (save == 0x9DE3BFA8U &&
10791+ (call & 0xC0000000U) == 0x40000000U &&
10792+ nop == 0x01000000U)
10793+ {
10794+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10795+
10796+ regs->u_regs[UREG_RETPC] = regs->pc;
10797+ regs->pc = dl_resolve;
10798+ regs->npc = dl_resolve+4;
10799+ return 3;
10800+ }
10801+ } while (0);
10802+#endif
10803+
10804+ return 1;
10805+}
10806+
10807+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10808+{
10809+ unsigned long i;
10810+
10811+ printk(KERN_ERR "PAX: bytes at PC: ");
10812+ for (i = 0; i < 8; i++) {
10813+ unsigned int c;
10814+ if (get_user(c, (unsigned int *)pc+i))
10815+ printk(KERN_CONT "???????? ");
10816+ else
10817+ printk(KERN_CONT "%08x ", c);
10818+ }
10819+ printk("\n");
10820+}
10821+#endif
10822+
10823 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10824 int text_fault)
10825 {
10826@@ -230,6 +504,24 @@ good_area:
10827 if (!(vma->vm_flags & VM_WRITE))
10828 goto bad_area;
10829 } else {
10830+
10831+#ifdef CONFIG_PAX_PAGEEXEC
10832+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10833+ up_read(&mm->mmap_sem);
10834+ switch (pax_handle_fetch_fault(regs)) {
10835+
10836+#ifdef CONFIG_PAX_EMUPLT
10837+ case 2:
10838+ case 3:
10839+ return;
10840+#endif
10841+
10842+ }
10843+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10844+ do_group_exit(SIGKILL);
10845+ }
10846+#endif
10847+
10848 /* Allow reads even for write-only mappings */
10849 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10850 goto bad_area;
10851diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10852index 5062ff3..e0b75f3 100644
10853--- a/arch/sparc/mm/fault_64.c
10854+++ b/arch/sparc/mm/fault_64.c
10855@@ -21,6 +21,9 @@
10856 #include <linux/kprobes.h>
10857 #include <linux/kdebug.h>
10858 #include <linux/percpu.h>
10859+#include <linux/slab.h>
10860+#include <linux/pagemap.h>
10861+#include <linux/compiler.h>
10862
10863 #include <asm/page.h>
10864 #include <asm/pgtable.h>
10865@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10866 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10867 regs->tpc);
10868 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10869- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10870+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10871 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10872 dump_stack();
10873 unhandled_fault(regs->tpc, current, regs);
10874@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10875 show_regs(regs);
10876 }
10877
10878+#ifdef CONFIG_PAX_PAGEEXEC
10879+#ifdef CONFIG_PAX_DLRESOLVE
10880+static void pax_emuplt_close(struct vm_area_struct *vma)
10881+{
10882+ vma->vm_mm->call_dl_resolve = 0UL;
10883+}
10884+
10885+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10886+{
10887+ unsigned int *kaddr;
10888+
10889+ vmf->page = alloc_page(GFP_HIGHUSER);
10890+ if (!vmf->page)
10891+ return VM_FAULT_OOM;
10892+
10893+ kaddr = kmap(vmf->page);
10894+ memset(kaddr, 0, PAGE_SIZE);
10895+ kaddr[0] = 0x9DE3BFA8U; /* save */
10896+ flush_dcache_page(vmf->page);
10897+ kunmap(vmf->page);
10898+ return VM_FAULT_MAJOR;
10899+}
10900+
10901+static const struct vm_operations_struct pax_vm_ops = {
10902+ .close = pax_emuplt_close,
10903+ .fault = pax_emuplt_fault
10904+};
10905+
10906+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10907+{
10908+ int ret;
10909+
10910+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10911+ vma->vm_mm = current->mm;
10912+ vma->vm_start = addr;
10913+ vma->vm_end = addr + PAGE_SIZE;
10914+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10915+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10916+ vma->vm_ops = &pax_vm_ops;
10917+
10918+ ret = insert_vm_struct(current->mm, vma);
10919+ if (ret)
10920+ return ret;
10921+
10922+ ++current->mm->total_vm;
10923+ return 0;
10924+}
10925+#endif
10926+
10927+/*
10928+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10929+ *
10930+ * returns 1 when task should be killed
10931+ * 2 when patched PLT trampoline was detected
10932+ * 3 when unpatched PLT trampoline was detected
10933+ */
10934+static int pax_handle_fetch_fault(struct pt_regs *regs)
10935+{
10936+
10937+#ifdef CONFIG_PAX_EMUPLT
10938+ int err;
10939+
10940+ do { /* PaX: patched PLT emulation #1 */
10941+ unsigned int sethi1, sethi2, jmpl;
10942+
10943+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10944+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10945+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10946+
10947+ if (err)
10948+ break;
10949+
10950+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10951+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10952+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10953+ {
10954+ unsigned long addr;
10955+
10956+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10957+ addr = regs->u_regs[UREG_G1];
10958+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10959+
10960+ if (test_thread_flag(TIF_32BIT))
10961+ addr &= 0xFFFFFFFFUL;
10962+
10963+ regs->tpc = addr;
10964+ regs->tnpc = addr+4;
10965+ return 2;
10966+ }
10967+ } while (0);
10968+
10969+ do { /* PaX: patched PLT emulation #2 */
10970+ unsigned int ba;
10971+
10972+ err = get_user(ba, (unsigned int *)regs->tpc);
10973+
10974+ if (err)
10975+ break;
10976+
10977+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10978+ unsigned long addr;
10979+
10980+ if ((ba & 0xFFC00000U) == 0x30800000U)
10981+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10982+ else
10983+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10984+
10985+ if (test_thread_flag(TIF_32BIT))
10986+ addr &= 0xFFFFFFFFUL;
10987+
10988+ regs->tpc = addr;
10989+ regs->tnpc = addr+4;
10990+ return 2;
10991+ }
10992+ } while (0);
10993+
10994+ do { /* PaX: patched PLT emulation #3 */
10995+ unsigned int sethi, bajmpl, nop;
10996+
10997+ err = get_user(sethi, (unsigned int *)regs->tpc);
10998+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10999+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11000+
11001+ if (err)
11002+ break;
11003+
11004+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11005+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11006+ nop == 0x01000000U)
11007+ {
11008+ unsigned long addr;
11009+
11010+ addr = (sethi & 0x003FFFFFU) << 10;
11011+ regs->u_regs[UREG_G1] = addr;
11012+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11013+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11014+ else
11015+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11016+
11017+ if (test_thread_flag(TIF_32BIT))
11018+ addr &= 0xFFFFFFFFUL;
11019+
11020+ regs->tpc = addr;
11021+ regs->tnpc = addr+4;
11022+ return 2;
11023+ }
11024+ } while (0);
11025+
11026+ do { /* PaX: patched PLT emulation #4 */
11027+ unsigned int sethi, mov1, call, mov2;
11028+
11029+ err = get_user(sethi, (unsigned int *)regs->tpc);
11030+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11031+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11032+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11033+
11034+ if (err)
11035+ break;
11036+
11037+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11038+ mov1 == 0x8210000FU &&
11039+ (call & 0xC0000000U) == 0x40000000U &&
11040+ mov2 == 0x9E100001U)
11041+ {
11042+ unsigned long addr;
11043+
11044+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11045+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11046+
11047+ if (test_thread_flag(TIF_32BIT))
11048+ addr &= 0xFFFFFFFFUL;
11049+
11050+ regs->tpc = addr;
11051+ regs->tnpc = addr+4;
11052+ return 2;
11053+ }
11054+ } while (0);
11055+
11056+ do { /* PaX: patched PLT emulation #5 */
11057+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11058+
11059+ err = get_user(sethi, (unsigned int *)regs->tpc);
11060+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11061+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11062+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11063+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11064+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11065+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11066+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11067+
11068+ if (err)
11069+ break;
11070+
11071+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11072+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11073+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11074+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11075+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11076+ sllx == 0x83287020U &&
11077+ jmpl == 0x81C04005U &&
11078+ nop == 0x01000000U)
11079+ {
11080+ unsigned long addr;
11081+
11082+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11083+ regs->u_regs[UREG_G1] <<= 32;
11084+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11085+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11086+ regs->tpc = addr;
11087+ regs->tnpc = addr+4;
11088+ return 2;
11089+ }
11090+ } while (0);
11091+
11092+ do { /* PaX: patched PLT emulation #6 */
11093+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11094+
11095+ err = get_user(sethi, (unsigned int *)regs->tpc);
11096+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11097+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11098+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11099+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11100+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11101+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11102+
11103+ if (err)
11104+ break;
11105+
11106+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11107+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11108+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11109+ sllx == 0x83287020U &&
11110+ (or & 0xFFFFE000U) == 0x8A116000U &&
11111+ jmpl == 0x81C04005U &&
11112+ nop == 0x01000000U)
11113+ {
11114+ unsigned long addr;
11115+
11116+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11117+ regs->u_regs[UREG_G1] <<= 32;
11118+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11119+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11120+ regs->tpc = addr;
11121+ regs->tnpc = addr+4;
11122+ return 2;
11123+ }
11124+ } while (0);
11125+
11126+ do { /* PaX: unpatched PLT emulation step 1 */
11127+ unsigned int sethi, ba, nop;
11128+
11129+ err = get_user(sethi, (unsigned int *)regs->tpc);
11130+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11131+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11132+
11133+ if (err)
11134+ break;
11135+
11136+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11137+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11138+ nop == 0x01000000U)
11139+ {
11140+ unsigned long addr;
11141+ unsigned int save, call;
11142+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11143+
11144+ if ((ba & 0xFFC00000U) == 0x30800000U)
11145+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11146+ else
11147+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11148+
11149+ if (test_thread_flag(TIF_32BIT))
11150+ addr &= 0xFFFFFFFFUL;
11151+
11152+ err = get_user(save, (unsigned int *)addr);
11153+ err |= get_user(call, (unsigned int *)(addr+4));
11154+ err |= get_user(nop, (unsigned int *)(addr+8));
11155+ if (err)
11156+ break;
11157+
11158+#ifdef CONFIG_PAX_DLRESOLVE
11159+ if (save == 0x9DE3BFA8U &&
11160+ (call & 0xC0000000U) == 0x40000000U &&
11161+ nop == 0x01000000U)
11162+ {
11163+ struct vm_area_struct *vma;
11164+ unsigned long call_dl_resolve;
11165+
11166+ down_read(&current->mm->mmap_sem);
11167+ call_dl_resolve = current->mm->call_dl_resolve;
11168+ up_read(&current->mm->mmap_sem);
11169+ if (likely(call_dl_resolve))
11170+ goto emulate;
11171+
11172+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11173+
11174+ down_write(&current->mm->mmap_sem);
11175+ if (current->mm->call_dl_resolve) {
11176+ call_dl_resolve = current->mm->call_dl_resolve;
11177+ up_write(&current->mm->mmap_sem);
11178+ if (vma)
11179+ kmem_cache_free(vm_area_cachep, vma);
11180+ goto emulate;
11181+ }
11182+
11183+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11184+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11185+ up_write(&current->mm->mmap_sem);
11186+ if (vma)
11187+ kmem_cache_free(vm_area_cachep, vma);
11188+ return 1;
11189+ }
11190+
11191+ if (pax_insert_vma(vma, call_dl_resolve)) {
11192+ up_write(&current->mm->mmap_sem);
11193+ kmem_cache_free(vm_area_cachep, vma);
11194+ return 1;
11195+ }
11196+
11197+ current->mm->call_dl_resolve = call_dl_resolve;
11198+ up_write(&current->mm->mmap_sem);
11199+
11200+emulate:
11201+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11202+ regs->tpc = call_dl_resolve;
11203+ regs->tnpc = addr+4;
11204+ return 3;
11205+ }
11206+#endif
11207+
11208+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11209+ if ((save & 0xFFC00000U) == 0x05000000U &&
11210+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11211+ nop == 0x01000000U)
11212+ {
11213+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11214+ regs->u_regs[UREG_G2] = addr + 4;
11215+ addr = (save & 0x003FFFFFU) << 10;
11216+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11217+
11218+ if (test_thread_flag(TIF_32BIT))
11219+ addr &= 0xFFFFFFFFUL;
11220+
11221+ regs->tpc = addr;
11222+ regs->tnpc = addr+4;
11223+ return 3;
11224+ }
11225+
11226+ /* PaX: 64-bit PLT stub */
11227+ err = get_user(sethi1, (unsigned int *)addr);
11228+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11229+ err |= get_user(or1, (unsigned int *)(addr+8));
11230+ err |= get_user(or2, (unsigned int *)(addr+12));
11231+ err |= get_user(sllx, (unsigned int *)(addr+16));
11232+ err |= get_user(add, (unsigned int *)(addr+20));
11233+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11234+ err |= get_user(nop, (unsigned int *)(addr+28));
11235+ if (err)
11236+ break;
11237+
11238+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11239+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11240+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11241+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11242+ sllx == 0x89293020U &&
11243+ add == 0x8A010005U &&
11244+ jmpl == 0x89C14000U &&
11245+ nop == 0x01000000U)
11246+ {
11247+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11248+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11249+ regs->u_regs[UREG_G4] <<= 32;
11250+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11251+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11252+ regs->u_regs[UREG_G4] = addr + 24;
11253+ addr = regs->u_regs[UREG_G5];
11254+ regs->tpc = addr;
11255+ regs->tnpc = addr+4;
11256+ return 3;
11257+ }
11258+ }
11259+ } while (0);
11260+
11261+#ifdef CONFIG_PAX_DLRESOLVE
11262+ do { /* PaX: unpatched PLT emulation step 2 */
11263+ unsigned int save, call, nop;
11264+
11265+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11266+ err |= get_user(call, (unsigned int *)regs->tpc);
11267+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11268+ if (err)
11269+ break;
11270+
11271+ if (save == 0x9DE3BFA8U &&
11272+ (call & 0xC0000000U) == 0x40000000U &&
11273+ nop == 0x01000000U)
11274+ {
11275+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11276+
11277+ if (test_thread_flag(TIF_32BIT))
11278+ dl_resolve &= 0xFFFFFFFFUL;
11279+
11280+ regs->u_regs[UREG_RETPC] = regs->tpc;
11281+ regs->tpc = dl_resolve;
11282+ regs->tnpc = dl_resolve+4;
11283+ return 3;
11284+ }
11285+ } while (0);
11286+#endif
11287+
11288+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11289+ unsigned int sethi, ba, nop;
11290+
11291+ err = get_user(sethi, (unsigned int *)regs->tpc);
11292+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11293+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11294+
11295+ if (err)
11296+ break;
11297+
11298+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11299+ (ba & 0xFFF00000U) == 0x30600000U &&
11300+ nop == 0x01000000U)
11301+ {
11302+ unsigned long addr;
11303+
11304+ addr = (sethi & 0x003FFFFFU) << 10;
11305+ regs->u_regs[UREG_G1] = addr;
11306+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11307+
11308+ if (test_thread_flag(TIF_32BIT))
11309+ addr &= 0xFFFFFFFFUL;
11310+
11311+ regs->tpc = addr;
11312+ regs->tnpc = addr+4;
11313+ return 2;
11314+ }
11315+ } while (0);
11316+
11317+#endif
11318+
11319+ return 1;
11320+}
11321+
11322+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11323+{
11324+ unsigned long i;
11325+
11326+ printk(KERN_ERR "PAX: bytes at PC: ");
11327+ for (i = 0; i < 8; i++) {
11328+ unsigned int c;
11329+ if (get_user(c, (unsigned int *)pc+i))
11330+ printk(KERN_CONT "???????? ");
11331+ else
11332+ printk(KERN_CONT "%08x ", c);
11333+ }
11334+ printk("\n");
11335+}
11336+#endif
11337+
11338 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11339 {
11340 struct mm_struct *mm = current->mm;
11341@@ -341,6 +804,29 @@ retry:
11342 if (!vma)
11343 goto bad_area;
11344
11345+#ifdef CONFIG_PAX_PAGEEXEC
11346+ /* PaX: detect ITLB misses on non-exec pages */
11347+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11348+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11349+ {
11350+ if (address != regs->tpc)
11351+ goto good_area;
11352+
11353+ up_read(&mm->mmap_sem);
11354+ switch (pax_handle_fetch_fault(regs)) {
11355+
11356+#ifdef CONFIG_PAX_EMUPLT
11357+ case 2:
11358+ case 3:
11359+ return;
11360+#endif
11361+
11362+ }
11363+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11364+ do_group_exit(SIGKILL);
11365+ }
11366+#endif
11367+
11368 /* Pure DTLB misses do not tell us whether the fault causing
11369 * load/store/atomic was a write or not, it only says that there
11370 * was no match. So in such a case we (carefully) read the
11371diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11372index d2b5944..d878f3c 100644
11373--- a/arch/sparc/mm/hugetlbpage.c
11374+++ b/arch/sparc/mm/hugetlbpage.c
11375@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11376 unsigned long addr,
11377 unsigned long len,
11378 unsigned long pgoff,
11379- unsigned long flags)
11380+ unsigned long flags,
11381+ unsigned long offset)
11382 {
11383 unsigned long task_size = TASK_SIZE;
11384 struct vm_unmapped_area_info info;
11385@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11386
11387 info.flags = 0;
11388 info.length = len;
11389- info.low_limit = TASK_UNMAPPED_BASE;
11390+ info.low_limit = mm->mmap_base;
11391 info.high_limit = min(task_size, VA_EXCLUDE_START);
11392 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11393 info.align_offset = 0;
11394+ info.threadstack_offset = offset;
11395 addr = vm_unmapped_area(&info);
11396
11397 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11398 VM_BUG_ON(addr != -ENOMEM);
11399 info.low_limit = VA_EXCLUDE_END;
11400+
11401+#ifdef CONFIG_PAX_RANDMMAP
11402+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11403+ info.low_limit += mm->delta_mmap;
11404+#endif
11405+
11406 info.high_limit = task_size;
11407 addr = vm_unmapped_area(&info);
11408 }
11409@@ -58,7 +66,8 @@ static unsigned long
11410 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11411 const unsigned long len,
11412 const unsigned long pgoff,
11413- const unsigned long flags)
11414+ const unsigned long flags,
11415+ const unsigned long offset)
11416 {
11417 struct mm_struct *mm = current->mm;
11418 unsigned long addr = addr0;
11419@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11420 info.high_limit = mm->mmap_base;
11421 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11422 info.align_offset = 0;
11423+ info.threadstack_offset = offset;
11424 addr = vm_unmapped_area(&info);
11425
11426 /*
11427@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11428 VM_BUG_ON(addr != -ENOMEM);
11429 info.flags = 0;
11430 info.low_limit = TASK_UNMAPPED_BASE;
11431+
11432+#ifdef CONFIG_PAX_RANDMMAP
11433+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11434+ info.low_limit += mm->delta_mmap;
11435+#endif
11436+
11437 info.high_limit = STACK_TOP32;
11438 addr = vm_unmapped_area(&info);
11439 }
11440@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11441 struct mm_struct *mm = current->mm;
11442 struct vm_area_struct *vma;
11443 unsigned long task_size = TASK_SIZE;
11444+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11445
11446 if (test_thread_flag(TIF_32BIT))
11447 task_size = STACK_TOP32;
11448@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11449 return addr;
11450 }
11451
11452+#ifdef CONFIG_PAX_RANDMMAP
11453+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11454+#endif
11455+
11456 if (addr) {
11457 addr = ALIGN(addr, HPAGE_SIZE);
11458 vma = find_vma(mm, addr);
11459- if (task_size - len >= addr &&
11460- (!vma || addr + len <= vma->vm_start))
11461+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11462 return addr;
11463 }
11464 if (mm->get_unmapped_area == arch_get_unmapped_area)
11465 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11466- pgoff, flags);
11467+ pgoff, flags, offset);
11468 else
11469 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11470- pgoff, flags);
11471+ pgoff, flags, offset);
11472 }
11473
11474 pte_t *huge_pte_alloc(struct mm_struct *mm,
11475diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11476index 04fd55a..4ede686 100644
11477--- a/arch/sparc/mm/init_64.c
11478+++ b/arch/sparc/mm/init_64.c
11479@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11480 int num_kernel_image_mappings;
11481
11482 #ifdef CONFIG_DEBUG_DCFLUSH
11483-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11484+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11485 #ifdef CONFIG_SMP
11486-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11487+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11488 #endif
11489 #endif
11490
11491@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11492 {
11493 BUG_ON(tlb_type == hypervisor);
11494 #ifdef CONFIG_DEBUG_DCFLUSH
11495- atomic_inc(&dcpage_flushes);
11496+ atomic_inc_unchecked(&dcpage_flushes);
11497 #endif
11498
11499 #ifdef DCACHE_ALIASING_POSSIBLE
11500@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11501
11502 #ifdef CONFIG_DEBUG_DCFLUSH
11503 seq_printf(m, "DCPageFlushes\t: %d\n",
11504- atomic_read(&dcpage_flushes));
11505+ atomic_read_unchecked(&dcpage_flushes));
11506 #ifdef CONFIG_SMP
11507 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11508- atomic_read(&dcpage_flushes_xcall));
11509+ atomic_read_unchecked(&dcpage_flushes_xcall));
11510 #endif /* CONFIG_SMP */
11511 #endif /* CONFIG_DEBUG_DCFLUSH */
11512 }
11513diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11514index f4500c6..889656c 100644
11515--- a/arch/tile/include/asm/atomic_64.h
11516+++ b/arch/tile/include/asm/atomic_64.h
11517@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11518
11519 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11520
11521+#define atomic64_read_unchecked(v) atomic64_read(v)
11522+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11523+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11524+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11525+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11526+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11527+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11528+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11529+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11530+
11531 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11532 #define smp_mb__before_atomic_dec() smp_mb()
11533 #define smp_mb__after_atomic_dec() smp_mb()
11534diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11535index a9a5299..0fce79e 100644
11536--- a/arch/tile/include/asm/cache.h
11537+++ b/arch/tile/include/asm/cache.h
11538@@ -15,11 +15,12 @@
11539 #ifndef _ASM_TILE_CACHE_H
11540 #define _ASM_TILE_CACHE_H
11541
11542+#include <linux/const.h>
11543 #include <arch/chip.h>
11544
11545 /* bytes per L1 data cache line */
11546 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11547-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11548+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11549
11550 /* bytes per L2 cache line */
11551 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11552diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11553index 8a082bc..7a6bf87 100644
11554--- a/arch/tile/include/asm/uaccess.h
11555+++ b/arch/tile/include/asm/uaccess.h
11556@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11557 const void __user *from,
11558 unsigned long n)
11559 {
11560- int sz = __compiletime_object_size(to);
11561+ size_t sz = __compiletime_object_size(to);
11562
11563- if (likely(sz == -1 || sz >= n))
11564+ if (likely(sz == (size_t)-1 || sz >= n))
11565 n = _copy_from_user(to, from, n);
11566 else
11567 copy_from_user_overflow();
11568diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11569index 650ccff..45fe2d6 100644
11570--- a/arch/tile/mm/hugetlbpage.c
11571+++ b/arch/tile/mm/hugetlbpage.c
11572@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11573 info.high_limit = TASK_SIZE;
11574 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11575 info.align_offset = 0;
11576+ info.threadstack_offset = 0;
11577 return vm_unmapped_area(&info);
11578 }
11579
11580@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11581 info.high_limit = current->mm->mmap_base;
11582 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11583 info.align_offset = 0;
11584+ info.threadstack_offset = 0;
11585 addr = vm_unmapped_area(&info);
11586
11587 /*
11588diff --git a/arch/um/Makefile b/arch/um/Makefile
11589index 133f7de..1d6f2f1 100644
11590--- a/arch/um/Makefile
11591+++ b/arch/um/Makefile
11592@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11593 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11594 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11595
11596+ifdef CONSTIFY_PLUGIN
11597+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11598+endif
11599+
11600 #This will adjust *FLAGS accordingly to the platform.
11601 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11602
11603diff --git a/arch/um/defconfig b/arch/um/defconfig
11604index 08107a7..ab22afe 100644
11605--- a/arch/um/defconfig
11606+++ b/arch/um/defconfig
11607@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11608 CONFIG_X86_L1_CACHE_SHIFT=5
11609 CONFIG_X86_XADD=y
11610 CONFIG_X86_PPRO_FENCE=y
11611-CONFIG_X86_WP_WORKS_OK=y
11612 CONFIG_X86_INVLPG=y
11613 CONFIG_X86_BSWAP=y
11614 CONFIG_X86_POPAD_OK=y
11615diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11616index 19e1bdd..3665b77 100644
11617--- a/arch/um/include/asm/cache.h
11618+++ b/arch/um/include/asm/cache.h
11619@@ -1,6 +1,7 @@
11620 #ifndef __UM_CACHE_H
11621 #define __UM_CACHE_H
11622
11623+#include <linux/const.h>
11624
11625 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11626 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11627@@ -12,6 +13,6 @@
11628 # define L1_CACHE_SHIFT 5
11629 #endif
11630
11631-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11632+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11633
11634 #endif
11635diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11636index 2e0a6b1..a64d0f5 100644
11637--- a/arch/um/include/asm/kmap_types.h
11638+++ b/arch/um/include/asm/kmap_types.h
11639@@ -8,6 +8,6 @@
11640
11641 /* No more #include "asm/arch/kmap_types.h" ! */
11642
11643-#define KM_TYPE_NR 14
11644+#define KM_TYPE_NR 15
11645
11646 #endif
11647diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11648index 5ff53d9..5850cdf 100644
11649--- a/arch/um/include/asm/page.h
11650+++ b/arch/um/include/asm/page.h
11651@@ -14,6 +14,9 @@
11652 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11653 #define PAGE_MASK (~(PAGE_SIZE-1))
11654
11655+#define ktla_ktva(addr) (addr)
11656+#define ktva_ktla(addr) (addr)
11657+
11658 #ifndef __ASSEMBLY__
11659
11660 struct page;
11661diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11662index 0032f92..cd151e0 100644
11663--- a/arch/um/include/asm/pgtable-3level.h
11664+++ b/arch/um/include/asm/pgtable-3level.h
11665@@ -58,6 +58,7 @@
11666 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11667 #define pud_populate(mm, pud, pmd) \
11668 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11669+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11670
11671 #ifdef CONFIG_64BIT
11672 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11673diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11674index bbcef52..6a2a483 100644
11675--- a/arch/um/kernel/process.c
11676+++ b/arch/um/kernel/process.c
11677@@ -367,22 +367,6 @@ int singlestepping(void * t)
11678 return 2;
11679 }
11680
11681-/*
11682- * Only x86 and x86_64 have an arch_align_stack().
11683- * All other arches have "#define arch_align_stack(x) (x)"
11684- * in their asm/system.h
11685- * As this is included in UML from asm-um/system-generic.h,
11686- * we can use it to behave as the subarch does.
11687- */
11688-#ifndef arch_align_stack
11689-unsigned long arch_align_stack(unsigned long sp)
11690-{
11691- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11692- sp -= get_random_int() % 8192;
11693- return sp & ~0xf;
11694-}
11695-#endif
11696-
11697 unsigned long get_wchan(struct task_struct *p)
11698 {
11699 unsigned long stack_page, sp, ip;
11700diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11701index ad8f795..2c7eec6 100644
11702--- a/arch/unicore32/include/asm/cache.h
11703+++ b/arch/unicore32/include/asm/cache.h
11704@@ -12,8 +12,10 @@
11705 #ifndef __UNICORE_CACHE_H__
11706 #define __UNICORE_CACHE_H__
11707
11708-#define L1_CACHE_SHIFT (5)
11709-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11710+#include <linux/const.h>
11711+
11712+#define L1_CACHE_SHIFT 5
11713+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11714
11715 /*
11716 * Memory returned by kmalloc() may be used for DMA, so we must make
11717diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11718index fe120da..24177f7 100644
11719--- a/arch/x86/Kconfig
11720+++ b/arch/x86/Kconfig
11721@@ -239,7 +239,7 @@ config X86_HT
11722
11723 config X86_32_LAZY_GS
11724 def_bool y
11725- depends on X86_32 && !CC_STACKPROTECTOR
11726+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11727
11728 config ARCH_HWEIGHT_CFLAGS
11729 string
11730@@ -1073,6 +1073,7 @@ config MICROCODE_EARLY
11731
11732 config X86_MSR
11733 tristate "/dev/cpu/*/msr - Model-specific register support"
11734+ depends on !GRKERNSEC_KMEM
11735 ---help---
11736 This device gives privileged processes access to the x86
11737 Model-Specific Registers (MSRs). It is a character device with
11738@@ -1096,7 +1097,7 @@ choice
11739
11740 config NOHIGHMEM
11741 bool "off"
11742- depends on !X86_NUMAQ
11743+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11744 ---help---
11745 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11746 However, the address space of 32-bit x86 processors is only 4
11747@@ -1133,7 +1134,7 @@ config NOHIGHMEM
11748
11749 config HIGHMEM4G
11750 bool "4GB"
11751- depends on !X86_NUMAQ
11752+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11753 ---help---
11754 Select this if you have a 32-bit processor and between 1 and 4
11755 gigabytes of physical RAM.
11756@@ -1186,7 +1187,7 @@ config PAGE_OFFSET
11757 hex
11758 default 0xB0000000 if VMSPLIT_3G_OPT
11759 default 0x80000000 if VMSPLIT_2G
11760- default 0x78000000 if VMSPLIT_2G_OPT
11761+ default 0x70000000 if VMSPLIT_2G_OPT
11762 default 0x40000000 if VMSPLIT_1G
11763 default 0xC0000000
11764 depends on X86_32
11765@@ -1584,6 +1585,7 @@ config SECCOMP
11766
11767 config CC_STACKPROTECTOR
11768 bool "Enable -fstack-protector buffer overflow detection"
11769+ depends on X86_64 || !PAX_MEMORY_UDEREF
11770 ---help---
11771 This option turns on the -fstack-protector GCC feature. This
11772 feature puts, at the beginning of functions, a canary value on
11773@@ -1703,6 +1705,8 @@ config X86_NEED_RELOCS
11774 config PHYSICAL_ALIGN
11775 hex "Alignment value to which kernel should be aligned" if X86_32
11776 default "0x1000000"
11777+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11778+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11779 range 0x2000 0x1000000
11780 ---help---
11781 This value puts the alignment restrictions on physical address
11782@@ -1778,9 +1782,10 @@ config DEBUG_HOTPLUG_CPU0
11783 If unsure, say N.
11784
11785 config COMPAT_VDSO
11786- def_bool y
11787+ def_bool n
11788 prompt "Compat VDSO support"
11789 depends on X86_32 || IA32_EMULATION
11790+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11791 ---help---
11792 Map the 32-bit VDSO to the predictable old-style address too.
11793
11794diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11795index c026cca..14657ae 100644
11796--- a/arch/x86/Kconfig.cpu
11797+++ b/arch/x86/Kconfig.cpu
11798@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11799
11800 config X86_F00F_BUG
11801 def_bool y
11802- depends on M586MMX || M586TSC || M586 || M486
11803+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11804
11805 config X86_INVD_BUG
11806 def_bool y
11807@@ -327,7 +327,7 @@ config X86_INVD_BUG
11808
11809 config X86_ALIGNMENT_16
11810 def_bool y
11811- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11812+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11813
11814 config X86_INTEL_USERCOPY
11815 def_bool y
11816@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11817 # generates cmov.
11818 config X86_CMOV
11819 def_bool y
11820- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11821+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11822
11823 config X86_MINIMUM_CPU_FAMILY
11824 int
11825diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11826index c198b7e..63eea60 100644
11827--- a/arch/x86/Kconfig.debug
11828+++ b/arch/x86/Kconfig.debug
11829@@ -84,7 +84,7 @@ config X86_PTDUMP
11830 config DEBUG_RODATA
11831 bool "Write protect kernel read-only data structures"
11832 default y
11833- depends on DEBUG_KERNEL
11834+ depends on DEBUG_KERNEL && BROKEN
11835 ---help---
11836 Mark the kernel read-only data as write-protected in the pagetables,
11837 in order to catch accidental (and incorrect) writes to such const
11838@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
11839
11840 config DEBUG_SET_MODULE_RONX
11841 bool "Set loadable kernel module data as NX and text as RO"
11842- depends on MODULES
11843+ depends on MODULES && BROKEN
11844 ---help---
11845 This option helps catch unintended modifications to loadable
11846 kernel module's text and read-only data. It also prevents execution
11847diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11848index 5c47726..8c4fa67 100644
11849--- a/arch/x86/Makefile
11850+++ b/arch/x86/Makefile
11851@@ -54,6 +54,7 @@ else
11852 UTS_MACHINE := x86_64
11853 CHECKFLAGS += -D__x86_64__ -m64
11854
11855+ biarch := $(call cc-option,-m64)
11856 KBUILD_AFLAGS += -m64
11857 KBUILD_CFLAGS += -m64
11858
11859@@ -234,3 +235,12 @@ define archhelp
11860 echo ' FDARGS="..." arguments for the booted kernel'
11861 echo ' FDINITRD=file initrd for the booted kernel'
11862 endef
11863+
11864+define OLD_LD
11865+
11866+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11867+*** Please upgrade your binutils to 2.18 or newer
11868+endef
11869+
11870+archprepare:
11871+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11872diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11873index 379814b..add62ce 100644
11874--- a/arch/x86/boot/Makefile
11875+++ b/arch/x86/boot/Makefile
11876@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11877 $(call cc-option, -fno-stack-protector) \
11878 $(call cc-option, -mpreferred-stack-boundary=2)
11879 KBUILD_CFLAGS += $(call cc-option, -m32)
11880+ifdef CONSTIFY_PLUGIN
11881+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11882+endif
11883 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11884 GCOV_PROFILE := n
11885
11886diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11887index 878e4b9..20537ab 100644
11888--- a/arch/x86/boot/bitops.h
11889+++ b/arch/x86/boot/bitops.h
11890@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11891 u8 v;
11892 const u32 *p = (const u32 *)addr;
11893
11894- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11895+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11896 return v;
11897 }
11898
11899@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11900
11901 static inline void set_bit(int nr, void *addr)
11902 {
11903- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11904+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11905 }
11906
11907 #endif /* BOOT_BITOPS_H */
11908diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11909index 5b75319..331a4ca 100644
11910--- a/arch/x86/boot/boot.h
11911+++ b/arch/x86/boot/boot.h
11912@@ -85,7 +85,7 @@ static inline void io_delay(void)
11913 static inline u16 ds(void)
11914 {
11915 u16 seg;
11916- asm("movw %%ds,%0" : "=rm" (seg));
11917+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11918 return seg;
11919 }
11920
11921@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11922 static inline int memcmp(const void *s1, const void *s2, size_t len)
11923 {
11924 u8 diff;
11925- asm("repe; cmpsb; setnz %0"
11926+ asm volatile("repe; cmpsb; setnz %0"
11927 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11928 return diff;
11929 }
11930diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11931index 5ef205c..342191d 100644
11932--- a/arch/x86/boot/compressed/Makefile
11933+++ b/arch/x86/boot/compressed/Makefile
11934@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11935 KBUILD_CFLAGS += $(cflags-y)
11936 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11937 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11938+ifdef CONSTIFY_PLUGIN
11939+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11940+endif
11941
11942 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11943 GCOV_PROFILE := n
11944diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11945index d606463..b887794 100644
11946--- a/arch/x86/boot/compressed/eboot.c
11947+++ b/arch/x86/boot/compressed/eboot.c
11948@@ -150,7 +150,6 @@ again:
11949 *addr = max_addr;
11950 }
11951
11952-free_pool:
11953 efi_call_phys1(sys_table->boottime->free_pool, map);
11954
11955 fail:
11956@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11957 if (i == map_size / desc_size)
11958 status = EFI_NOT_FOUND;
11959
11960-free_pool:
11961 efi_call_phys1(sys_table->boottime->free_pool, map);
11962 fail:
11963 return status;
11964diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11965index a53440e..c3dbf1e 100644
11966--- a/arch/x86/boot/compressed/efi_stub_32.S
11967+++ b/arch/x86/boot/compressed/efi_stub_32.S
11968@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11969 * parameter 2, ..., param n. To make things easy, we save the return
11970 * address of efi_call_phys in a global variable.
11971 */
11972- popl %ecx
11973- movl %ecx, saved_return_addr(%edx)
11974- /* get the function pointer into ECX*/
11975- popl %ecx
11976- movl %ecx, efi_rt_function_ptr(%edx)
11977+ popl saved_return_addr(%edx)
11978+ popl efi_rt_function_ptr(%edx)
11979
11980 /*
11981 * 3. Call the physical function.
11982 */
11983- call *%ecx
11984+ call *efi_rt_function_ptr(%edx)
11985
11986 /*
11987 * 4. Balance the stack. And because EAX contain the return value,
11988@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11989 1: popl %edx
11990 subl $1b, %edx
11991
11992- movl efi_rt_function_ptr(%edx), %ecx
11993- pushl %ecx
11994+ pushl efi_rt_function_ptr(%edx)
11995
11996 /*
11997 * 10. Push the saved return address onto the stack and return.
11998 */
11999- movl saved_return_addr(%edx), %ecx
12000- pushl %ecx
12001- ret
12002+ jmpl *saved_return_addr(%edx)
12003 ENDPROC(efi_call_phys)
12004 .previous
12005
12006diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12007index 1e3184f..0d11e2e 100644
12008--- a/arch/x86/boot/compressed/head_32.S
12009+++ b/arch/x86/boot/compressed/head_32.S
12010@@ -118,7 +118,7 @@ preferred_addr:
12011 notl %eax
12012 andl %eax, %ebx
12013 #else
12014- movl $LOAD_PHYSICAL_ADDR, %ebx
12015+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12016 #endif
12017
12018 /* Target address to relocate to for decompression */
12019@@ -204,7 +204,7 @@ relocated:
12020 * and where it was actually loaded.
12021 */
12022 movl %ebp, %ebx
12023- subl $LOAD_PHYSICAL_ADDR, %ebx
12024+ subl $____LOAD_PHYSICAL_ADDR, %ebx
12025 jz 2f /* Nothing to be done if loaded at compiled addr. */
12026 /*
12027 * Process relocations.
12028@@ -212,8 +212,7 @@ relocated:
12029
12030 1: subl $4, %edi
12031 movl (%edi), %ecx
12032- testl %ecx, %ecx
12033- jz 2f
12034+ jecxz 2f
12035 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
12036 jmp 1b
12037 2:
12038diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12039index 16f24e6..47491a3 100644
12040--- a/arch/x86/boot/compressed/head_64.S
12041+++ b/arch/x86/boot/compressed/head_64.S
12042@@ -97,7 +97,7 @@ ENTRY(startup_32)
12043 notl %eax
12044 andl %eax, %ebx
12045 #else
12046- movl $LOAD_PHYSICAL_ADDR, %ebx
12047+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12048 #endif
12049
12050 /* Target address to relocate to for decompression */
12051@@ -272,7 +272,7 @@ preferred_addr:
12052 notq %rax
12053 andq %rax, %rbp
12054 #else
12055- movq $LOAD_PHYSICAL_ADDR, %rbp
12056+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12057 #endif
12058
12059 /* Target address to relocate to for decompression */
12060@@ -363,8 +363,8 @@ gdt:
12061 .long gdt
12062 .word 0
12063 .quad 0x0000000000000000 /* NULL descriptor */
12064- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12065- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12066+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12067+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12068 .quad 0x0080890000000000 /* TS descriptor */
12069 .quad 0x0000000000000000 /* TS continued */
12070 gdt_end:
12071diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12072index 7cb56c6..d382d84 100644
12073--- a/arch/x86/boot/compressed/misc.c
12074+++ b/arch/x86/boot/compressed/misc.c
12075@@ -303,7 +303,7 @@ static void parse_elf(void *output)
12076 case PT_LOAD:
12077 #ifdef CONFIG_RELOCATABLE
12078 dest = output;
12079- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12080+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12081 #else
12082 dest = (void *)(phdr->p_paddr);
12083 #endif
12084@@ -354,7 +354,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
12085 error("Destination address too large");
12086 #endif
12087 #ifndef CONFIG_RELOCATABLE
12088- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12089+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12090 error("Wrong destination address");
12091 #endif
12092
12093diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12094index 4d3ff03..e4972ff 100644
12095--- a/arch/x86/boot/cpucheck.c
12096+++ b/arch/x86/boot/cpucheck.c
12097@@ -74,7 +74,7 @@ static int has_fpu(void)
12098 u16 fcw = -1, fsw = -1;
12099 u32 cr0;
12100
12101- asm("movl %%cr0,%0" : "=r" (cr0));
12102+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
12103 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12104 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12105 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12106@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12107 {
12108 u32 f0, f1;
12109
12110- asm("pushfl ; "
12111+ asm volatile("pushfl ; "
12112 "pushfl ; "
12113 "popl %0 ; "
12114 "movl %0,%1 ; "
12115@@ -115,7 +115,7 @@ static void get_flags(void)
12116 set_bit(X86_FEATURE_FPU, cpu.flags);
12117
12118 if (has_eflag(X86_EFLAGS_ID)) {
12119- asm("cpuid"
12120+ asm volatile("cpuid"
12121 : "=a" (max_intel_level),
12122 "=b" (cpu_vendor[0]),
12123 "=d" (cpu_vendor[1]),
12124@@ -124,7 +124,7 @@ static void get_flags(void)
12125
12126 if (max_intel_level >= 0x00000001 &&
12127 max_intel_level <= 0x0000ffff) {
12128- asm("cpuid"
12129+ asm volatile("cpuid"
12130 : "=a" (tfms),
12131 "=c" (cpu.flags[4]),
12132 "=d" (cpu.flags[0])
12133@@ -136,7 +136,7 @@ static void get_flags(void)
12134 cpu.model += ((tfms >> 16) & 0xf) << 4;
12135 }
12136
12137- asm("cpuid"
12138+ asm volatile("cpuid"
12139 : "=a" (max_amd_level)
12140 : "a" (0x80000000)
12141 : "ebx", "ecx", "edx");
12142@@ -144,7 +144,7 @@ static void get_flags(void)
12143 if (max_amd_level >= 0x80000001 &&
12144 max_amd_level <= 0x8000ffff) {
12145 u32 eax = 0x80000001;
12146- asm("cpuid"
12147+ asm volatile("cpuid"
12148 : "+a" (eax),
12149 "=c" (cpu.flags[6]),
12150 "=d" (cpu.flags[1])
12151@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12152 u32 ecx = MSR_K7_HWCR;
12153 u32 eax, edx;
12154
12155- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12156+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12157 eax &= ~(1 << 15);
12158- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12159+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12160
12161 get_flags(); /* Make sure it really did something */
12162 err = check_flags();
12163@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12164 u32 ecx = MSR_VIA_FCR;
12165 u32 eax, edx;
12166
12167- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12168+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12169 eax |= (1<<1)|(1<<7);
12170- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12171+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12172
12173 set_bit(X86_FEATURE_CX8, cpu.flags);
12174 err = check_flags();
12175@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12176 u32 eax, edx;
12177 u32 level = 1;
12178
12179- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12180- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12181- asm("cpuid"
12182+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12183+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12184+ asm volatile("cpuid"
12185 : "+a" (level), "=d" (cpu.flags[0])
12186 : : "ecx", "ebx");
12187- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12188+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12189
12190 err = check_flags();
12191 }
12192diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12193index 9ec06a1..2c25e79 100644
12194--- a/arch/x86/boot/header.S
12195+++ b/arch/x86/boot/header.S
12196@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12197 # single linked list of
12198 # struct setup_data
12199
12200-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12201+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12202
12203 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12204+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12205+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12206+#else
12207 #define VO_INIT_SIZE (VO__end - VO__text)
12208+#endif
12209 #if ZO_INIT_SIZE > VO_INIT_SIZE
12210 #define INIT_SIZE ZO_INIT_SIZE
12211 #else
12212diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12213index db75d07..8e6d0af 100644
12214--- a/arch/x86/boot/memory.c
12215+++ b/arch/x86/boot/memory.c
12216@@ -19,7 +19,7 @@
12217
12218 static int detect_memory_e820(void)
12219 {
12220- int count = 0;
12221+ unsigned int count = 0;
12222 struct biosregs ireg, oreg;
12223 struct e820entry *desc = boot_params.e820_map;
12224 static struct e820entry buf; /* static so it is zeroed */
12225diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12226index 11e8c6e..fdbb1ed 100644
12227--- a/arch/x86/boot/video-vesa.c
12228+++ b/arch/x86/boot/video-vesa.c
12229@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12230
12231 boot_params.screen_info.vesapm_seg = oreg.es;
12232 boot_params.screen_info.vesapm_off = oreg.di;
12233+ boot_params.screen_info.vesapm_size = oreg.cx;
12234 }
12235
12236 /*
12237diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12238index 43eda28..5ab5fdb 100644
12239--- a/arch/x86/boot/video.c
12240+++ b/arch/x86/boot/video.c
12241@@ -96,7 +96,7 @@ static void store_mode_params(void)
12242 static unsigned int get_entry(void)
12243 {
12244 char entry_buf[4];
12245- int i, len = 0;
12246+ unsigned int i, len = 0;
12247 int key;
12248 unsigned int v;
12249
12250diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12251index 9105655..5e37f27 100644
12252--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12253+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12254@@ -8,6 +8,8 @@
12255 * including this sentence is retained in full.
12256 */
12257
12258+#include <asm/alternative-asm.h>
12259+
12260 .extern crypto_ft_tab
12261 .extern crypto_it_tab
12262 .extern crypto_fl_tab
12263@@ -70,6 +72,8 @@
12264 je B192; \
12265 leaq 32(r9),r9;
12266
12267+#define ret pax_force_retaddr 0, 1; ret
12268+
12269 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12270 movq r1,r2; \
12271 movq r3,r4; \
12272diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12273index 477e9d7..3ab339f 100644
12274--- a/arch/x86/crypto/aesni-intel_asm.S
12275+++ b/arch/x86/crypto/aesni-intel_asm.S
12276@@ -31,6 +31,7 @@
12277
12278 #include <linux/linkage.h>
12279 #include <asm/inst.h>
12280+#include <asm/alternative-asm.h>
12281
12282 #ifdef __x86_64__
12283 .data
12284@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
12285 pop %r14
12286 pop %r13
12287 pop %r12
12288+ pax_force_retaddr 0, 1
12289 ret
12290 ENDPROC(aesni_gcm_dec)
12291
12292@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
12293 pop %r14
12294 pop %r13
12295 pop %r12
12296+ pax_force_retaddr 0, 1
12297 ret
12298 ENDPROC(aesni_gcm_enc)
12299
12300@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12301 pxor %xmm1, %xmm0
12302 movaps %xmm0, (TKEYP)
12303 add $0x10, TKEYP
12304+ pax_force_retaddr_bts
12305 ret
12306 ENDPROC(_key_expansion_128)
12307 ENDPROC(_key_expansion_256a)
12308@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12309 shufps $0b01001110, %xmm2, %xmm1
12310 movaps %xmm1, 0x10(TKEYP)
12311 add $0x20, TKEYP
12312+ pax_force_retaddr_bts
12313 ret
12314 ENDPROC(_key_expansion_192a)
12315
12316@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12317
12318 movaps %xmm0, (TKEYP)
12319 add $0x10, TKEYP
12320+ pax_force_retaddr_bts
12321 ret
12322 ENDPROC(_key_expansion_192b)
12323
12324@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12325 pxor %xmm1, %xmm2
12326 movaps %xmm2, (TKEYP)
12327 add $0x10, TKEYP
12328+ pax_force_retaddr_bts
12329 ret
12330 ENDPROC(_key_expansion_256b)
12331
12332@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12333 #ifndef __x86_64__
12334 popl KEYP
12335 #endif
12336+ pax_force_retaddr 0, 1
12337 ret
12338 ENDPROC(aesni_set_key)
12339
12340@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12341 popl KLEN
12342 popl KEYP
12343 #endif
12344+ pax_force_retaddr 0, 1
12345 ret
12346 ENDPROC(aesni_enc)
12347
12348@@ -1974,6 +1983,7 @@ _aesni_enc1:
12349 AESENC KEY STATE
12350 movaps 0x70(TKEYP), KEY
12351 AESENCLAST KEY STATE
12352+ pax_force_retaddr_bts
12353 ret
12354 ENDPROC(_aesni_enc1)
12355
12356@@ -2083,6 +2093,7 @@ _aesni_enc4:
12357 AESENCLAST KEY STATE2
12358 AESENCLAST KEY STATE3
12359 AESENCLAST KEY STATE4
12360+ pax_force_retaddr_bts
12361 ret
12362 ENDPROC(_aesni_enc4)
12363
12364@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12365 popl KLEN
12366 popl KEYP
12367 #endif
12368+ pax_force_retaddr 0, 1
12369 ret
12370 ENDPROC(aesni_dec)
12371
12372@@ -2164,6 +2176,7 @@ _aesni_dec1:
12373 AESDEC KEY STATE
12374 movaps 0x70(TKEYP), KEY
12375 AESDECLAST KEY STATE
12376+ pax_force_retaddr_bts
12377 ret
12378 ENDPROC(_aesni_dec1)
12379
12380@@ -2273,6 +2286,7 @@ _aesni_dec4:
12381 AESDECLAST KEY STATE2
12382 AESDECLAST KEY STATE3
12383 AESDECLAST KEY STATE4
12384+ pax_force_retaddr_bts
12385 ret
12386 ENDPROC(_aesni_dec4)
12387
12388@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12389 popl KEYP
12390 popl LEN
12391 #endif
12392+ pax_force_retaddr 0, 1
12393 ret
12394 ENDPROC(aesni_ecb_enc)
12395
12396@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12397 popl KEYP
12398 popl LEN
12399 #endif
12400+ pax_force_retaddr 0, 1
12401 ret
12402 ENDPROC(aesni_ecb_dec)
12403
12404@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12405 popl LEN
12406 popl IVP
12407 #endif
12408+ pax_force_retaddr 0, 1
12409 ret
12410 ENDPROC(aesni_cbc_enc)
12411
12412@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12413 popl LEN
12414 popl IVP
12415 #endif
12416+ pax_force_retaddr 0, 1
12417 ret
12418 ENDPROC(aesni_cbc_dec)
12419
12420@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12421 mov $1, TCTR_LOW
12422 MOVQ_R64_XMM TCTR_LOW INC
12423 MOVQ_R64_XMM CTR TCTR_LOW
12424+ pax_force_retaddr_bts
12425 ret
12426 ENDPROC(_aesni_inc_init)
12427
12428@@ -2579,6 +2598,7 @@ _aesni_inc:
12429 .Linc_low:
12430 movaps CTR, IV
12431 PSHUFB_XMM BSWAP_MASK IV
12432+ pax_force_retaddr_bts
12433 ret
12434 ENDPROC(_aesni_inc)
12435
12436@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12437 .Lctr_enc_ret:
12438 movups IV, (IVP)
12439 .Lctr_enc_just_ret:
12440+ pax_force_retaddr 0, 1
12441 ret
12442 ENDPROC(aesni_ctr_enc)
12443
12444@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12445 pxor INC, STATE4
12446 movdqu STATE4, 0x70(OUTP)
12447
12448+ pax_force_retaddr 0, 1
12449 ret
12450 ENDPROC(aesni_xts_crypt8)
12451
12452diff --git a/arch/x86/crypto/blowfish-avx2-asm_64.S b/arch/x86/crypto/blowfish-avx2-asm_64.S
12453index 784452e..46982c7 100644
12454--- a/arch/x86/crypto/blowfish-avx2-asm_64.S
12455+++ b/arch/x86/crypto/blowfish-avx2-asm_64.S
12456@@ -221,6 +221,7 @@ __blowfish_enc_blk32:
12457
12458 write_block(RXl, RXr);
12459
12460+ pax_force_retaddr 0, 1
12461 ret;
12462 ENDPROC(__blowfish_enc_blk32)
12463
12464@@ -250,6 +251,7 @@ __blowfish_dec_blk32:
12465
12466 write_block(RXl, RXr);
12467
12468+ pax_force_retaddr 0, 1
12469 ret;
12470 ENDPROC(__blowfish_dec_blk32)
12471
12472@@ -284,6 +286,7 @@ ENTRY(blowfish_ecb_enc_32way)
12473
12474 vzeroupper;
12475
12476+ pax_force_retaddr 0, 1
12477 ret;
12478 ENDPROC(blowfish_ecb_enc_32way)
12479
12480@@ -318,6 +321,7 @@ ENTRY(blowfish_ecb_dec_32way)
12481
12482 vzeroupper;
12483
12484+ pax_force_retaddr 0, 1
12485 ret;
12486 ENDPROC(blowfish_ecb_dec_32way)
12487
12488@@ -365,6 +369,7 @@ ENTRY(blowfish_cbc_dec_32way)
12489
12490 vzeroupper;
12491
12492+ pax_force_retaddr 0, 1
12493 ret;
12494 ENDPROC(blowfish_cbc_dec_32way)
12495
12496@@ -445,5 +450,6 @@ ENTRY(blowfish_ctr_32way)
12497
12498 vzeroupper;
12499
12500+ pax_force_retaddr 0, 1
12501 ret;
12502 ENDPROC(blowfish_ctr_32way)
12503diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12504index 246c670..4d1ed00 100644
12505--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12506+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12507@@ -21,6 +21,7 @@
12508 */
12509
12510 #include <linux/linkage.h>
12511+#include <asm/alternative-asm.h>
12512
12513 .file "blowfish-x86_64-asm.S"
12514 .text
12515@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12516 jnz .L__enc_xor;
12517
12518 write_block();
12519+ pax_force_retaddr 0, 1
12520 ret;
12521 .L__enc_xor:
12522 xor_block();
12523+ pax_force_retaddr 0, 1
12524 ret;
12525 ENDPROC(__blowfish_enc_blk)
12526
12527@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12528
12529 movq %r11, %rbp;
12530
12531+ pax_force_retaddr 0, 1
12532 ret;
12533 ENDPROC(blowfish_dec_blk)
12534
12535@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12536
12537 popq %rbx;
12538 popq %rbp;
12539+ pax_force_retaddr 0, 1
12540 ret;
12541
12542 .L__enc_xor4:
12543@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12544
12545 popq %rbx;
12546 popq %rbp;
12547+ pax_force_retaddr 0, 1
12548 ret;
12549 ENDPROC(__blowfish_enc_blk_4way)
12550
12551@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12552 popq %rbx;
12553 popq %rbp;
12554
12555+ pax_force_retaddr 0, 1
12556 ret;
12557 ENDPROC(blowfish_dec_blk_4way)
12558diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12559index ce71f92..2dd5b1e 100644
12560--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12561+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12562@@ -16,6 +16,7 @@
12563 */
12564
12565 #include <linux/linkage.h>
12566+#include <asm/alternative-asm.h>
12567
12568 #define CAMELLIA_TABLE_BYTE_LEN 272
12569
12570@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12571 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12572 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12573 %rcx, (%r9));
12574+ pax_force_retaddr_bts
12575 ret;
12576 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12577
12578@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12579 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12580 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12581 %rax, (%r9));
12582+ pax_force_retaddr_bts
12583 ret;
12584 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12585
12586@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12587 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12588 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12589
12590+ pax_force_retaddr_bts
12591 ret;
12592
12593 .align 8
12594@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12595 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12596 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12597
12598+ pax_force_retaddr_bts
12599 ret;
12600
12601 .align 8
12602@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12603 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12604 %xmm8, %rsi);
12605
12606+ pax_force_retaddr 0, 1
12607 ret;
12608 ENDPROC(camellia_ecb_enc_16way)
12609
12610@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12611 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12612 %xmm8, %rsi);
12613
12614+ pax_force_retaddr 0, 1
12615 ret;
12616 ENDPROC(camellia_ecb_dec_16way)
12617
12618@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12619 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12620 %xmm8, %rsi);
12621
12622+ pax_force_retaddr 0, 1
12623 ret;
12624 ENDPROC(camellia_cbc_dec_16way)
12625
12626@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12627 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12628 %xmm8, %rsi);
12629
12630+ pax_force_retaddr 0, 1
12631 ret;
12632 ENDPROC(camellia_ctr_16way)
12633
12634@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12635 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12636 %xmm8, %rsi);
12637
12638+ pax_force_retaddr 0, 1
12639 ret;
12640 ENDPROC(camellia_xts_crypt_16way)
12641
12642diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12643index 91a1878..bcf340a 100644
12644--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12645+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12646@@ -11,6 +11,7 @@
12647 */
12648
12649 #include <linux/linkage.h>
12650+#include <asm/alternative-asm.h>
12651
12652 #define CAMELLIA_TABLE_BYTE_LEN 272
12653
12654@@ -212,6 +213,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12655 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12656 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12657 %rcx, (%r9));
12658+ pax_force_retaddr_bts
12659 ret;
12660 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12661
12662@@ -220,6 +222,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12663 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12664 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12665 %rax, (%r9));
12666+ pax_force_retaddr_bts
12667 ret;
12668 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12669
12670@@ -802,6 +805,7 @@ __camellia_enc_blk32:
12671 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12672 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12673
12674+ pax_force_retaddr_bts
12675 ret;
12676
12677 .align 8
12678@@ -887,6 +891,7 @@ __camellia_dec_blk32:
12679 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12680 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12681
12682+ pax_force_retaddr_bts
12683 ret;
12684
12685 .align 8
12686@@ -930,6 +935,7 @@ ENTRY(camellia_ecb_enc_32way)
12687
12688 vzeroupper;
12689
12690+ pax_force_retaddr 0, 1
12691 ret;
12692 ENDPROC(camellia_ecb_enc_32way)
12693
12694@@ -962,6 +968,7 @@ ENTRY(camellia_ecb_dec_32way)
12695
12696 vzeroupper;
12697
12698+ pax_force_retaddr 0, 1
12699 ret;
12700 ENDPROC(camellia_ecb_dec_32way)
12701
12702@@ -1028,6 +1035,7 @@ ENTRY(camellia_cbc_dec_32way)
12703
12704 vzeroupper;
12705
12706+ pax_force_retaddr 0, 1
12707 ret;
12708 ENDPROC(camellia_cbc_dec_32way)
12709
12710@@ -1166,6 +1174,7 @@ ENTRY(camellia_ctr_32way)
12711
12712 vzeroupper;
12713
12714+ pax_force_retaddr 0, 1
12715 ret;
12716 ENDPROC(camellia_ctr_32way)
12717
12718@@ -1331,6 +1340,7 @@ camellia_xts_crypt_32way:
12719
12720 vzeroupper;
12721
12722+ pax_force_retaddr 0, 1
12723 ret;
12724 ENDPROC(camellia_xts_crypt_32way)
12725
12726diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12727index 310319c..ce174a4 100644
12728--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12729+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12730@@ -21,6 +21,7 @@
12731 */
12732
12733 #include <linux/linkage.h>
12734+#include <asm/alternative-asm.h>
12735
12736 .file "camellia-x86_64-asm_64.S"
12737 .text
12738@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12739 enc_outunpack(mov, RT1);
12740
12741 movq RRBP, %rbp;
12742+ pax_force_retaddr 0, 1
12743 ret;
12744
12745 .L__enc_xor:
12746 enc_outunpack(xor, RT1);
12747
12748 movq RRBP, %rbp;
12749+ pax_force_retaddr 0, 1
12750 ret;
12751 ENDPROC(__camellia_enc_blk)
12752
12753@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12754 dec_outunpack();
12755
12756 movq RRBP, %rbp;
12757+ pax_force_retaddr 0, 1
12758 ret;
12759 ENDPROC(camellia_dec_blk)
12760
12761@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12762
12763 movq RRBP, %rbp;
12764 popq %rbx;
12765+ pax_force_retaddr 0, 1
12766 ret;
12767
12768 .L__enc2_xor:
12769@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12770
12771 movq RRBP, %rbp;
12772 popq %rbx;
12773+ pax_force_retaddr 0, 1
12774 ret;
12775 ENDPROC(__camellia_enc_blk_2way)
12776
12777@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12778
12779 movq RRBP, %rbp;
12780 movq RXOR, %rbx;
12781+ pax_force_retaddr 0, 1
12782 ret;
12783 ENDPROC(camellia_dec_blk_2way)
12784diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12785index c35fd5d..c1ee236 100644
12786--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12787+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12788@@ -24,6 +24,7 @@
12789 */
12790
12791 #include <linux/linkage.h>
12792+#include <asm/alternative-asm.h>
12793
12794 .file "cast5-avx-x86_64-asm_64.S"
12795
12796@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12797 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12798 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12799
12800+ pax_force_retaddr 0, 1
12801 ret;
12802 ENDPROC(__cast5_enc_blk16)
12803
12804@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12805 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12806 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12807
12808+ pax_force_retaddr 0, 1
12809 ret;
12810
12811 .L__skip_dec:
12812@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12813 vmovdqu RR4, (6*4*4)(%r11);
12814 vmovdqu RL4, (7*4*4)(%r11);
12815
12816+ pax_force_retaddr
12817 ret;
12818 ENDPROC(cast5_ecb_enc_16way)
12819
12820@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12821 vmovdqu RR4, (6*4*4)(%r11);
12822 vmovdqu RL4, (7*4*4)(%r11);
12823
12824+ pax_force_retaddr
12825 ret;
12826 ENDPROC(cast5_ecb_dec_16way)
12827
12828@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
12829
12830 popq %r12;
12831
12832+ pax_force_retaddr
12833 ret;
12834 ENDPROC(cast5_cbc_dec_16way)
12835
12836@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
12837
12838 popq %r12;
12839
12840+ pax_force_retaddr
12841 ret;
12842 ENDPROC(cast5_ctr_16way)
12843diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12844index e3531f8..18ded3a 100644
12845--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12846+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12847@@ -24,6 +24,7 @@
12848 */
12849
12850 #include <linux/linkage.h>
12851+#include <asm/alternative-asm.h>
12852 #include "glue_helper-asm-avx.S"
12853
12854 .file "cast6-avx-x86_64-asm_64.S"
12855@@ -295,6 +296,7 @@ __cast6_enc_blk8:
12856 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12857 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12858
12859+ pax_force_retaddr 0, 1
12860 ret;
12861 ENDPROC(__cast6_enc_blk8)
12862
12863@@ -340,6 +342,7 @@ __cast6_dec_blk8:
12864 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12865 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12866
12867+ pax_force_retaddr 0, 1
12868 ret;
12869 ENDPROC(__cast6_dec_blk8)
12870
12871@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
12872
12873 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12874
12875+ pax_force_retaddr
12876 ret;
12877 ENDPROC(cast6_ecb_enc_8way)
12878
12879@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
12880
12881 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12882
12883+ pax_force_retaddr
12884 ret;
12885 ENDPROC(cast6_ecb_dec_8way)
12886
12887@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
12888
12889 popq %r12;
12890
12891+ pax_force_retaddr
12892 ret;
12893 ENDPROC(cast6_cbc_dec_8way)
12894
12895@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
12896
12897 popq %r12;
12898
12899+ pax_force_retaddr
12900 ret;
12901 ENDPROC(cast6_ctr_8way)
12902
12903@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
12904 /* dst <= regs xor IVs(in dst) */
12905 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12906
12907+ pax_force_retaddr
12908 ret;
12909 ENDPROC(cast6_xts_enc_8way)
12910
12911@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
12912 /* dst <= regs xor IVs(in dst) */
12913 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12914
12915+ pax_force_retaddr
12916 ret;
12917 ENDPROC(cast6_xts_dec_8way)
12918diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12919index dbc4339..3d868c5 100644
12920--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12921+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12922@@ -45,6 +45,7 @@
12923
12924 #include <asm/inst.h>
12925 #include <linux/linkage.h>
12926+#include <asm/alternative-asm.h>
12927
12928 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
12929
12930@@ -312,6 +313,7 @@ do_return:
12931 popq %rsi
12932 popq %rdi
12933 popq %rbx
12934+ pax_force_retaddr 0, 1
12935 ret
12936
12937 ################################################################
12938diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12939index 586f41a..d02851e 100644
12940--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
12941+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12942@@ -18,6 +18,7 @@
12943
12944 #include <linux/linkage.h>
12945 #include <asm/inst.h>
12946+#include <asm/alternative-asm.h>
12947
12948 .data
12949
12950@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
12951 psrlq $1, T2
12952 pxor T2, T1
12953 pxor T1, DATA
12954+ pax_force_retaddr
12955 ret
12956 ENDPROC(__clmul_gf128mul_ble)
12957
12958@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
12959 call __clmul_gf128mul_ble
12960 PSHUFB_XMM BSWAP DATA
12961 movups DATA, (%rdi)
12962+ pax_force_retaddr
12963 ret
12964 ENDPROC(clmul_ghash_mul)
12965
12966@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
12967 PSHUFB_XMM BSWAP DATA
12968 movups DATA, (%rdi)
12969 .Lupdate_just_ret:
12970+ pax_force_retaddr
12971 ret
12972 ENDPROC(clmul_ghash_update)
12973
12974@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
12975 pand .Lpoly, %xmm1
12976 pxor %xmm1, %xmm0
12977 movups %xmm0, (%rdi)
12978+ pax_force_retaddr
12979 ret
12980 ENDPROC(clmul_ghash_setkey)
12981diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12982index 9279e0b..9270820 100644
12983--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
12984+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12985@@ -1,4 +1,5 @@
12986 #include <linux/linkage.h>
12987+#include <asm/alternative-asm.h>
12988
12989 # enter salsa20_encrypt_bytes
12990 ENTRY(salsa20_encrypt_bytes)
12991@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
12992 add %r11,%rsp
12993 mov %rdi,%rax
12994 mov %rsi,%rdx
12995+ pax_force_retaddr 0, 1
12996 ret
12997 # bytesatleast65:
12998 ._bytesatleast65:
12999@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13000 add %r11,%rsp
13001 mov %rdi,%rax
13002 mov %rsi,%rdx
13003+ pax_force_retaddr
13004 ret
13005 ENDPROC(salsa20_keysetup)
13006
13007@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13008 add %r11,%rsp
13009 mov %rdi,%rax
13010 mov %rsi,%rdx
13011+ pax_force_retaddr
13012 ret
13013 ENDPROC(salsa20_ivsetup)
13014diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13015index 2f202f4..d9164d6 100644
13016--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13017+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13018@@ -24,6 +24,7 @@
13019 */
13020
13021 #include <linux/linkage.h>
13022+#include <asm/alternative-asm.h>
13023 #include "glue_helper-asm-avx.S"
13024
13025 .file "serpent-avx-x86_64-asm_64.S"
13026@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13027 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13028 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13029
13030+ pax_force_retaddr
13031 ret;
13032 ENDPROC(__serpent_enc_blk8_avx)
13033
13034@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13035 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13036 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13037
13038+ pax_force_retaddr
13039 ret;
13040 ENDPROC(__serpent_dec_blk8_avx)
13041
13042@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13043
13044 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13045
13046+ pax_force_retaddr
13047 ret;
13048 ENDPROC(serpent_ecb_enc_8way_avx)
13049
13050@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13051
13052 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13053
13054+ pax_force_retaddr
13055 ret;
13056 ENDPROC(serpent_ecb_dec_8way_avx)
13057
13058@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13059
13060 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13061
13062+ pax_force_retaddr
13063 ret;
13064 ENDPROC(serpent_cbc_dec_8way_avx)
13065
13066@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13067
13068 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13069
13070+ pax_force_retaddr
13071 ret;
13072 ENDPROC(serpent_ctr_8way_avx)
13073
13074@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13075 /* dst <= regs xor IVs(in dst) */
13076 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13077
13078+ pax_force_retaddr
13079 ret;
13080 ENDPROC(serpent_xts_enc_8way_avx)
13081
13082@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13083 /* dst <= regs xor IVs(in dst) */
13084 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13085
13086+ pax_force_retaddr
13087 ret;
13088 ENDPROC(serpent_xts_dec_8way_avx)
13089diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13090index b222085..abd483c 100644
13091--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13092+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13093@@ -15,6 +15,7 @@
13094 */
13095
13096 #include <linux/linkage.h>
13097+#include <asm/alternative-asm.h>
13098 #include "glue_helper-asm-avx2.S"
13099
13100 .file "serpent-avx2-asm_64.S"
13101@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13102 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13103 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13104
13105+ pax_force_retaddr
13106 ret;
13107 ENDPROC(__serpent_enc_blk16)
13108
13109@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13110 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13111 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13112
13113+ pax_force_retaddr
13114 ret;
13115 ENDPROC(__serpent_dec_blk16)
13116
13117@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13118
13119 vzeroupper;
13120
13121+ pax_force_retaddr
13122 ret;
13123 ENDPROC(serpent_ecb_enc_16way)
13124
13125@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13126
13127 vzeroupper;
13128
13129+ pax_force_retaddr
13130 ret;
13131 ENDPROC(serpent_ecb_dec_16way)
13132
13133@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13134
13135 vzeroupper;
13136
13137+ pax_force_retaddr
13138 ret;
13139 ENDPROC(serpent_cbc_dec_16way)
13140
13141@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13142
13143 vzeroupper;
13144
13145+ pax_force_retaddr
13146 ret;
13147 ENDPROC(serpent_ctr_16way)
13148
13149@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13150
13151 vzeroupper;
13152
13153+ pax_force_retaddr
13154 ret;
13155 ENDPROC(serpent_xts_enc_16way)
13156
13157@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13158
13159 vzeroupper;
13160
13161+ pax_force_retaddr
13162 ret;
13163 ENDPROC(serpent_xts_dec_16way)
13164diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13165index acc066c..1559cc4 100644
13166--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13167+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13168@@ -25,6 +25,7 @@
13169 */
13170
13171 #include <linux/linkage.h>
13172+#include <asm/alternative-asm.h>
13173
13174 .file "serpent-sse2-x86_64-asm_64.S"
13175 .text
13176@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13177 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13178 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13179
13180+ pax_force_retaddr
13181 ret;
13182
13183 .L__enc_xor8:
13184 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13185 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13186
13187+ pax_force_retaddr
13188 ret;
13189 ENDPROC(__serpent_enc_blk_8way)
13190
13191@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13192 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13193 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13194
13195+ pax_force_retaddr
13196 ret;
13197 ENDPROC(serpent_dec_blk_8way)
13198diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13199index a410950..3356d42 100644
13200--- a/arch/x86/crypto/sha1_ssse3_asm.S
13201+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13202@@ -29,6 +29,7 @@
13203 */
13204
13205 #include <linux/linkage.h>
13206+#include <asm/alternative-asm.h>
13207
13208 #define CTX %rdi // arg1
13209 #define BUF %rsi // arg2
13210@@ -104,6 +105,7 @@
13211 pop %r12
13212 pop %rbp
13213 pop %rbx
13214+ pax_force_retaddr 0, 1
13215 ret
13216
13217 ENDPROC(\name)
13218diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13219index 642f156..4ab07b9 100644
13220--- a/arch/x86/crypto/sha256-avx-asm.S
13221+++ b/arch/x86/crypto/sha256-avx-asm.S
13222@@ -49,6 +49,7 @@
13223
13224 #ifdef CONFIG_AS_AVX
13225 #include <linux/linkage.h>
13226+#include <asm/alternative-asm.h>
13227
13228 ## assume buffers not aligned
13229 #define VMOVDQ vmovdqu
13230@@ -460,6 +461,7 @@ done_hash:
13231 popq %r13
13232 popq %rbp
13233 popq %rbx
13234+ pax_force_retaddr 0, 1
13235 ret
13236 ENDPROC(sha256_transform_avx)
13237
13238diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13239index 9e86944..2e7f95a 100644
13240--- a/arch/x86/crypto/sha256-avx2-asm.S
13241+++ b/arch/x86/crypto/sha256-avx2-asm.S
13242@@ -50,6 +50,7 @@
13243
13244 #ifdef CONFIG_AS_AVX2
13245 #include <linux/linkage.h>
13246+#include <asm/alternative-asm.h>
13247
13248 ## assume buffers not aligned
13249 #define VMOVDQ vmovdqu
13250@@ -720,6 +721,7 @@ done_hash:
13251 popq %r12
13252 popq %rbp
13253 popq %rbx
13254+ pax_force_retaddr 0, 1
13255 ret
13256 ENDPROC(sha256_transform_rorx)
13257
13258diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13259index f833b74..c36ed14 100644
13260--- a/arch/x86/crypto/sha256-ssse3-asm.S
13261+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13262@@ -47,6 +47,7 @@
13263 ########################################################################
13264
13265 #include <linux/linkage.h>
13266+#include <asm/alternative-asm.h>
13267
13268 ## assume buffers not aligned
13269 #define MOVDQ movdqu
13270@@ -471,6 +472,7 @@ done_hash:
13271 popq %rbp
13272 popq %rbx
13273
13274+ pax_force_retaddr 0, 1
13275 ret
13276 ENDPROC(sha256_transform_ssse3)
13277
13278diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13279index 974dde9..4533d34 100644
13280--- a/arch/x86/crypto/sha512-avx-asm.S
13281+++ b/arch/x86/crypto/sha512-avx-asm.S
13282@@ -49,6 +49,7 @@
13283
13284 #ifdef CONFIG_AS_AVX
13285 #include <linux/linkage.h>
13286+#include <asm/alternative-asm.h>
13287
13288 .text
13289
13290@@ -364,6 +365,7 @@ updateblock:
13291 mov frame_RSPSAVE(%rsp), %rsp
13292
13293 nowork:
13294+ pax_force_retaddr 0, 1
13295 ret
13296 ENDPROC(sha512_transform_avx)
13297
13298diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13299index 568b961..061ef1d 100644
13300--- a/arch/x86/crypto/sha512-avx2-asm.S
13301+++ b/arch/x86/crypto/sha512-avx2-asm.S
13302@@ -51,6 +51,7 @@
13303
13304 #ifdef CONFIG_AS_AVX2
13305 #include <linux/linkage.h>
13306+#include <asm/alternative-asm.h>
13307
13308 .text
13309
13310@@ -678,6 +679,7 @@ done_hash:
13311
13312 # Restore Stack Pointer
13313 mov frame_RSPSAVE(%rsp), %rsp
13314+ pax_force_retaddr 0, 1
13315 ret
13316 ENDPROC(sha512_transform_rorx)
13317
13318diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13319index fb56855..e23914f 100644
13320--- a/arch/x86/crypto/sha512-ssse3-asm.S
13321+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13322@@ -48,6 +48,7 @@
13323 ########################################################################
13324
13325 #include <linux/linkage.h>
13326+#include <asm/alternative-asm.h>
13327
13328 .text
13329
13330@@ -363,6 +364,7 @@ updateblock:
13331 mov frame_RSPSAVE(%rsp), %rsp
13332
13333 nowork:
13334+ pax_force_retaddr 0, 1
13335 ret
13336 ENDPROC(sha512_transform_ssse3)
13337
13338diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13339index 0505813..63b1d00 100644
13340--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13341+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13342@@ -24,6 +24,7 @@
13343 */
13344
13345 #include <linux/linkage.h>
13346+#include <asm/alternative-asm.h>
13347 #include "glue_helper-asm-avx.S"
13348
13349 .file "twofish-avx-x86_64-asm_64.S"
13350@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13351 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13352 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13353
13354+ pax_force_retaddr 0, 1
13355 ret;
13356 ENDPROC(__twofish_enc_blk8)
13357
13358@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13359 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13360 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13361
13362+ pax_force_retaddr 0, 1
13363 ret;
13364 ENDPROC(__twofish_dec_blk8)
13365
13366@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13367
13368 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13369
13370+ pax_force_retaddr 0, 1
13371 ret;
13372 ENDPROC(twofish_ecb_enc_8way)
13373
13374@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13375
13376 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13377
13378+ pax_force_retaddr 0, 1
13379 ret;
13380 ENDPROC(twofish_ecb_dec_8way)
13381
13382@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
13383
13384 popq %r12;
13385
13386+ pax_force_retaddr 0, 1
13387 ret;
13388 ENDPROC(twofish_cbc_dec_8way)
13389
13390@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
13391
13392 popq %r12;
13393
13394+ pax_force_retaddr 0, 1
13395 ret;
13396 ENDPROC(twofish_ctr_8way)
13397
13398@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13399 /* dst <= regs xor IVs(in dst) */
13400 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13401
13402+ pax_force_retaddr 0, 1
13403 ret;
13404 ENDPROC(twofish_xts_enc_8way)
13405
13406@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13407 /* dst <= regs xor IVs(in dst) */
13408 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13409
13410+ pax_force_retaddr 0, 1
13411 ret;
13412 ENDPROC(twofish_xts_dec_8way)
13413diff --git a/arch/x86/crypto/twofish-avx2-asm_64.S b/arch/x86/crypto/twofish-avx2-asm_64.S
13414index e1a83b9..33006b9 100644
13415--- a/arch/x86/crypto/twofish-avx2-asm_64.S
13416+++ b/arch/x86/crypto/twofish-avx2-asm_64.S
13417@@ -11,6 +11,7 @@
13418 */
13419
13420 #include <linux/linkage.h>
13421+#include <asm/alternative-asm.h>
13422 #include "glue_helper-asm-avx2.S"
13423
13424 .file "twofish-avx2-asm_64.S"
13425@@ -422,6 +423,7 @@ __twofish_enc_blk16:
13426 outunpack_enc16(RA, RB, RC, RD);
13427 write_blocks16(RA, RB, RC, RD);
13428
13429+ pax_force_retaddr_bts
13430 ret;
13431 ENDPROC(__twofish_enc_blk16)
13432
13433@@ -454,6 +456,7 @@ __twofish_dec_blk16:
13434 outunpack_dec16(RA, RB, RC, RD);
13435 write_blocks16(RA, RB, RC, RD);
13436
13437+ pax_force_retaddr_bts
13438 ret;
13439 ENDPROC(__twofish_dec_blk16)
13440
13441@@ -476,6 +479,7 @@ ENTRY(twofish_ecb_enc_16way)
13442 popq %r12;
13443 vzeroupper;
13444
13445+ pax_force_retaddr 0, 1
13446 ret;
13447 ENDPROC(twofish_ecb_enc_16way)
13448
13449@@ -498,6 +502,7 @@ ENTRY(twofish_ecb_dec_16way)
13450 popq %r12;
13451 vzeroupper;
13452
13453+ pax_force_retaddr 0, 1
13454 ret;
13455 ENDPROC(twofish_ecb_dec_16way)
13456
13457@@ -521,6 +526,7 @@ ENTRY(twofish_cbc_dec_16way)
13458 popq %r12;
13459 vzeroupper;
13460
13461+ pax_force_retaddr 0, 1
13462 ret;
13463 ENDPROC(twofish_cbc_dec_16way)
13464
13465@@ -546,6 +552,7 @@ ENTRY(twofish_ctr_16way)
13466 popq %r12;
13467 vzeroupper;
13468
13469+ pax_force_retaddr 0, 1
13470 ret;
13471 ENDPROC(twofish_ctr_16way)
13472
13473@@ -574,6 +581,7 @@ twofish_xts_crypt_16way:
13474 popq %r12;
13475 vzeroupper;
13476
13477+ pax_force_retaddr 0, 1
13478 ret;
13479 ENDPROC(twofish_xts_crypt_16way)
13480
13481diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13482index 1c3b7ce..b365c5e 100644
13483--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13484+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13485@@ -21,6 +21,7 @@
13486 */
13487
13488 #include <linux/linkage.h>
13489+#include <asm/alternative-asm.h>
13490
13491 .file "twofish-x86_64-asm-3way.S"
13492 .text
13493@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13494 popq %r13;
13495 popq %r14;
13496 popq %r15;
13497+ pax_force_retaddr 0, 1
13498 ret;
13499
13500 .L__enc_xor3:
13501@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13502 popq %r13;
13503 popq %r14;
13504 popq %r15;
13505+ pax_force_retaddr 0, 1
13506 ret;
13507 ENDPROC(__twofish_enc_blk_3way)
13508
13509@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13510 popq %r13;
13511 popq %r14;
13512 popq %r15;
13513+ pax_force_retaddr 0, 1
13514 ret;
13515 ENDPROC(twofish_dec_blk_3way)
13516diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13517index a039d21..29e7615 100644
13518--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13519+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13520@@ -22,6 +22,7 @@
13521
13522 #include <linux/linkage.h>
13523 #include <asm/asm-offsets.h>
13524+#include <asm/alternative-asm.h>
13525
13526 #define a_offset 0
13527 #define b_offset 4
13528@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13529
13530 popq R1
13531 movq $1,%rax
13532+ pax_force_retaddr 0, 1
13533 ret
13534 ENDPROC(twofish_enc_blk)
13535
13536@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13537
13538 popq R1
13539 movq $1,%rax
13540+ pax_force_retaddr 0, 1
13541 ret
13542 ENDPROC(twofish_dec_blk)
13543diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13544index 52ff81c..98af645 100644
13545--- a/arch/x86/ia32/ia32_aout.c
13546+++ b/arch/x86/ia32/ia32_aout.c
13547@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13548 unsigned long dump_start, dump_size;
13549 struct user32 dump;
13550
13551+ memset(&dump, 0, sizeof(dump));
13552+
13553 fs = get_fs();
13554 set_fs(KERNEL_DS);
13555 has_dumped = 1;
13556diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13557index cf1a471..5ba2673 100644
13558--- a/arch/x86/ia32/ia32_signal.c
13559+++ b/arch/x86/ia32/ia32_signal.c
13560@@ -340,7 +340,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13561 sp -= frame_size;
13562 /* Align the stack pointer according to the i386 ABI,
13563 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13564- sp = ((sp + 4) & -16ul) - 4;
13565+ sp = ((sp - 12) & -16ul) - 4;
13566 return (void __user *) sp;
13567 }
13568
13569@@ -398,7 +398,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13570 * These are actually not used anymore, but left because some
13571 * gdb versions depend on them as a marker.
13572 */
13573- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13574+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13575 } put_user_catch(err);
13576
13577 if (err)
13578@@ -440,7 +440,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13579 0xb8,
13580 __NR_ia32_rt_sigreturn,
13581 0x80cd,
13582- 0,
13583+ 0
13584 };
13585
13586 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13587@@ -459,20 +459,22 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13588 else
13589 put_user_ex(0, &frame->uc.uc_flags);
13590 put_user_ex(0, &frame->uc.uc_link);
13591- err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
13592+ __compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
13593
13594 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13595 restorer = ksig->ka.sa.sa_restorer;
13596+ else if (current->mm->context.vdso)
13597+ /* Return stub is in 32bit vsyscall page */
13598+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13599 else
13600- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13601- rt_sigreturn);
13602+ restorer = &frame->retcode;
13603 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13604
13605 /*
13606 * Not actually used anymore, but left because some gdb
13607 * versions need it.
13608 */
13609- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13610+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13611 } put_user_catch(err);
13612
13613 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13614diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13615index 474dc1b..9297c58 100644
13616--- a/arch/x86/ia32/ia32entry.S
13617+++ b/arch/x86/ia32/ia32entry.S
13618@@ -15,8 +15,10 @@
13619 #include <asm/irqflags.h>
13620 #include <asm/asm.h>
13621 #include <asm/smap.h>
13622+#include <asm/pgtable.h>
13623 #include <linux/linkage.h>
13624 #include <linux/err.h>
13625+#include <asm/alternative-asm.h>
13626
13627 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13628 #include <linux/elf-em.h>
13629@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13630 ENDPROC(native_irq_enable_sysexit)
13631 #endif
13632
13633+ .macro pax_enter_kernel_user
13634+ pax_set_fptr_mask
13635+#ifdef CONFIG_PAX_MEMORY_UDEREF
13636+ call pax_enter_kernel_user
13637+#endif
13638+ .endm
13639+
13640+ .macro pax_exit_kernel_user
13641+#ifdef CONFIG_PAX_MEMORY_UDEREF
13642+ call pax_exit_kernel_user
13643+#endif
13644+#ifdef CONFIG_PAX_RANDKSTACK
13645+ pushq %rax
13646+ pushq %r11
13647+ call pax_randomize_kstack
13648+ popq %r11
13649+ popq %rax
13650+#endif
13651+ .endm
13652+
13653+ .macro pax_erase_kstack
13654+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13655+ call pax_erase_kstack
13656+#endif
13657+ .endm
13658+
13659 /*
13660 * 32bit SYSENTER instruction entry.
13661 *
13662@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13663 CFI_REGISTER rsp,rbp
13664 SWAPGS_UNSAFE_STACK
13665 movq PER_CPU_VAR(kernel_stack), %rsp
13666- addq $(KERNEL_STACK_OFFSET),%rsp
13667- /*
13668- * No need to follow this irqs on/off section: the syscall
13669- * disabled irqs, here we enable it straight after entry:
13670- */
13671- ENABLE_INTERRUPTS(CLBR_NONE)
13672 movl %ebp,%ebp /* zero extension */
13673 pushq_cfi $__USER32_DS
13674 /*CFI_REL_OFFSET ss,0*/
13675@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13676 CFI_REL_OFFSET rsp,0
13677 pushfq_cfi
13678 /*CFI_REL_OFFSET rflags,0*/
13679- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13680- CFI_REGISTER rip,r10
13681+ orl $X86_EFLAGS_IF,(%rsp)
13682+ GET_THREAD_INFO(%r11)
13683+ movl TI_sysenter_return(%r11), %r11d
13684+ CFI_REGISTER rip,r11
13685 pushq_cfi $__USER32_CS
13686 /*CFI_REL_OFFSET cs,0*/
13687 movl %eax, %eax
13688- pushq_cfi %r10
13689+ pushq_cfi %r11
13690 CFI_REL_OFFSET rip,0
13691 pushq_cfi %rax
13692 cld
13693 SAVE_ARGS 0,1,0
13694+ pax_enter_kernel_user
13695+
13696+#ifdef CONFIG_PAX_RANDKSTACK
13697+ pax_erase_kstack
13698+#endif
13699+
13700+ /*
13701+ * No need to follow this irqs on/off section: the syscall
13702+ * disabled irqs, here we enable it straight after entry:
13703+ */
13704+ ENABLE_INTERRUPTS(CLBR_NONE)
13705 /* no need to do an access_ok check here because rbp has been
13706 32bit zero extended */
13707+
13708+#ifdef CONFIG_PAX_MEMORY_UDEREF
13709+ addq pax_user_shadow_base,%rbp
13710+ ASM_PAX_OPEN_USERLAND
13711+#endif
13712+
13713 ASM_STAC
13714 1: movl (%rbp),%ebp
13715 _ASM_EXTABLE(1b,ia32_badarg)
13716 ASM_CLAC
13717- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13718- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13719+
13720+#ifdef CONFIG_PAX_MEMORY_UDEREF
13721+ ASM_PAX_CLOSE_USERLAND
13722+#endif
13723+
13724+ GET_THREAD_INFO(%r11)
13725+ orl $TS_COMPAT,TI_status(%r11)
13726+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13727 CFI_REMEMBER_STATE
13728 jnz sysenter_tracesys
13729 cmpq $(IA32_NR_syscalls-1),%rax
13730@@ -162,12 +209,15 @@ sysenter_do_call:
13731 sysenter_dispatch:
13732 call *ia32_sys_call_table(,%rax,8)
13733 movq %rax,RAX-ARGOFFSET(%rsp)
13734+ GET_THREAD_INFO(%r11)
13735 DISABLE_INTERRUPTS(CLBR_NONE)
13736 TRACE_IRQS_OFF
13737- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13738+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13739 jnz sysexit_audit
13740 sysexit_from_sys_call:
13741- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13742+ pax_exit_kernel_user
13743+ pax_erase_kstack
13744+ andl $~TS_COMPAT,TI_status(%r11)
13745 /* clear IF, that popfq doesn't enable interrupts early */
13746 andl $~0x200,EFLAGS-R11(%rsp)
13747 movl RIP-R11(%rsp),%edx /* User %eip */
13748@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13749 movl %eax,%esi /* 2nd arg: syscall number */
13750 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13751 call __audit_syscall_entry
13752+
13753+ pax_erase_kstack
13754+
13755 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13756 cmpq $(IA32_NR_syscalls-1),%rax
13757 ja ia32_badsys
13758@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13759 .endm
13760
13761 .macro auditsys_exit exit
13762- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13763+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13764 jnz ia32_ret_from_sys_call
13765 TRACE_IRQS_ON
13766 ENABLE_INTERRUPTS(CLBR_NONE)
13767@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13768 1: setbe %al /* 1 if error, 0 if not */
13769 movzbl %al,%edi /* zero-extend that into %edi */
13770 call __audit_syscall_exit
13771+ GET_THREAD_INFO(%r11)
13772 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13773 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13774 DISABLE_INTERRUPTS(CLBR_NONE)
13775 TRACE_IRQS_OFF
13776- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13777+ testl %edi,TI_flags(%r11)
13778 jz \exit
13779 CLEAR_RREGS -ARGOFFSET
13780 jmp int_with_check
13781@@ -237,7 +291,7 @@ sysexit_audit:
13782
13783 sysenter_tracesys:
13784 #ifdef CONFIG_AUDITSYSCALL
13785- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13786+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13787 jz sysenter_auditsys
13788 #endif
13789 SAVE_REST
13790@@ -249,6 +303,9 @@ sysenter_tracesys:
13791 RESTORE_REST
13792 cmpq $(IA32_NR_syscalls-1),%rax
13793 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13794+
13795+ pax_erase_kstack
13796+
13797 jmp sysenter_do_call
13798 CFI_ENDPROC
13799 ENDPROC(ia32_sysenter_target)
13800@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13801 ENTRY(ia32_cstar_target)
13802 CFI_STARTPROC32 simple
13803 CFI_SIGNAL_FRAME
13804- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13805+ CFI_DEF_CFA rsp,0
13806 CFI_REGISTER rip,rcx
13807 /*CFI_REGISTER rflags,r11*/
13808 SWAPGS_UNSAFE_STACK
13809 movl %esp,%r8d
13810 CFI_REGISTER rsp,r8
13811 movq PER_CPU_VAR(kernel_stack),%rsp
13812+ SAVE_ARGS 8*6,0,0
13813+ pax_enter_kernel_user
13814+
13815+#ifdef CONFIG_PAX_RANDKSTACK
13816+ pax_erase_kstack
13817+#endif
13818+
13819 /*
13820 * No need to follow this irqs on/off section: the syscall
13821 * disabled irqs and here we enable it straight after entry:
13822 */
13823 ENABLE_INTERRUPTS(CLBR_NONE)
13824- SAVE_ARGS 8,0,0
13825 movl %eax,%eax /* zero extension */
13826 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13827 movq %rcx,RIP-ARGOFFSET(%rsp)
13828@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
13829 /* no need to do an access_ok check here because r8 has been
13830 32bit zero extended */
13831 /* hardware stack frame is complete now */
13832+
13833+#ifdef CONFIG_PAX_MEMORY_UDEREF
13834+ ASM_PAX_OPEN_USERLAND
13835+ movq pax_user_shadow_base,%r8
13836+ addq RSP-ARGOFFSET(%rsp),%r8
13837+#endif
13838+
13839 ASM_STAC
13840 1: movl (%r8),%r9d
13841 _ASM_EXTABLE(1b,ia32_badarg)
13842 ASM_CLAC
13843- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13844- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13845+
13846+#ifdef CONFIG_PAX_MEMORY_UDEREF
13847+ ASM_PAX_CLOSE_USERLAND
13848+#endif
13849+
13850+ GET_THREAD_INFO(%r11)
13851+ orl $TS_COMPAT,TI_status(%r11)
13852+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13853 CFI_REMEMBER_STATE
13854 jnz cstar_tracesys
13855 cmpq $IA32_NR_syscalls-1,%rax
13856@@ -319,12 +395,15 @@ cstar_do_call:
13857 cstar_dispatch:
13858 call *ia32_sys_call_table(,%rax,8)
13859 movq %rax,RAX-ARGOFFSET(%rsp)
13860+ GET_THREAD_INFO(%r11)
13861 DISABLE_INTERRUPTS(CLBR_NONE)
13862 TRACE_IRQS_OFF
13863- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13864+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13865 jnz sysretl_audit
13866 sysretl_from_sys_call:
13867- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13868+ pax_exit_kernel_user
13869+ pax_erase_kstack
13870+ andl $~TS_COMPAT,TI_status(%r11)
13871 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
13872 movl RIP-ARGOFFSET(%rsp),%ecx
13873 CFI_REGISTER rip,rcx
13874@@ -352,7 +431,7 @@ sysretl_audit:
13875
13876 cstar_tracesys:
13877 #ifdef CONFIG_AUDITSYSCALL
13878- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13879+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13880 jz cstar_auditsys
13881 #endif
13882 xchgl %r9d,%ebp
13883@@ -366,11 +445,19 @@ cstar_tracesys:
13884 xchgl %ebp,%r9d
13885 cmpq $(IA32_NR_syscalls-1),%rax
13886 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
13887+
13888+ pax_erase_kstack
13889+
13890 jmp cstar_do_call
13891 END(ia32_cstar_target)
13892
13893 ia32_badarg:
13894 ASM_CLAC
13895+
13896+#ifdef CONFIG_PAX_MEMORY_UDEREF
13897+ ASM_PAX_CLOSE_USERLAND
13898+#endif
13899+
13900 movq $-EFAULT,%rax
13901 jmp ia32_sysret
13902 CFI_ENDPROC
13903@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
13904 CFI_REL_OFFSET rip,RIP-RIP
13905 PARAVIRT_ADJUST_EXCEPTION_FRAME
13906 SWAPGS
13907- /*
13908- * No need to follow this irqs on/off section: the syscall
13909- * disabled irqs and here we enable it straight after entry:
13910- */
13911- ENABLE_INTERRUPTS(CLBR_NONE)
13912 movl %eax,%eax
13913 pushq_cfi %rax
13914 cld
13915 /* note the registers are not zero extended to the sf.
13916 this could be a problem. */
13917 SAVE_ARGS 0,1,0
13918- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13919- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13920+ pax_enter_kernel_user
13921+
13922+#ifdef CONFIG_PAX_RANDKSTACK
13923+ pax_erase_kstack
13924+#endif
13925+
13926+ /*
13927+ * No need to follow this irqs on/off section: the syscall
13928+ * disabled irqs and here we enable it straight after entry:
13929+ */
13930+ ENABLE_INTERRUPTS(CLBR_NONE)
13931+ GET_THREAD_INFO(%r11)
13932+ orl $TS_COMPAT,TI_status(%r11)
13933+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13934 jnz ia32_tracesys
13935 cmpq $(IA32_NR_syscalls-1),%rax
13936 ja ia32_badsys
13937@@ -442,6 +536,9 @@ ia32_tracesys:
13938 RESTORE_REST
13939 cmpq $(IA32_NR_syscalls-1),%rax
13940 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
13941+
13942+ pax_erase_kstack
13943+
13944 jmp ia32_do_call
13945 END(ia32_syscall)
13946
13947diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
13948index 8e0ceec..af13504 100644
13949--- a/arch/x86/ia32/sys_ia32.c
13950+++ b/arch/x86/ia32/sys_ia32.c
13951@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
13952 */
13953 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
13954 {
13955- typeof(ubuf->st_uid) uid = 0;
13956- typeof(ubuf->st_gid) gid = 0;
13957+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
13958+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
13959 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
13960 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
13961 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
13962diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
13963index 372231c..a5aa1a1 100644
13964--- a/arch/x86/include/asm/alternative-asm.h
13965+++ b/arch/x86/include/asm/alternative-asm.h
13966@@ -18,6 +18,45 @@
13967 .endm
13968 #endif
13969
13970+#ifdef KERNEXEC_PLUGIN
13971+ .macro pax_force_retaddr_bts rip=0
13972+ btsq $63,\rip(%rsp)
13973+ .endm
13974+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13975+ .macro pax_force_retaddr rip=0, reload=0
13976+ btsq $63,\rip(%rsp)
13977+ .endm
13978+ .macro pax_force_fptr ptr
13979+ btsq $63,\ptr
13980+ .endm
13981+ .macro pax_set_fptr_mask
13982+ .endm
13983+#endif
13984+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
13985+ .macro pax_force_retaddr rip=0, reload=0
13986+ .if \reload
13987+ pax_set_fptr_mask
13988+ .endif
13989+ orq %r10,\rip(%rsp)
13990+ .endm
13991+ .macro pax_force_fptr ptr
13992+ orq %r10,\ptr
13993+ .endm
13994+ .macro pax_set_fptr_mask
13995+ movabs $0x8000000000000000,%r10
13996+ .endm
13997+#endif
13998+#else
13999+ .macro pax_force_retaddr rip=0, reload=0
14000+ .endm
14001+ .macro pax_force_fptr ptr
14002+ .endm
14003+ .macro pax_force_retaddr_bts rip=0
14004+ .endm
14005+ .macro pax_set_fptr_mask
14006+ .endm
14007+#endif
14008+
14009 .macro altinstruction_entry orig alt feature orig_len alt_len
14010 .long \orig - .
14011 .long \alt - .
14012diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14013index 58ed6d9..f1cbe58 100644
14014--- a/arch/x86/include/asm/alternative.h
14015+++ b/arch/x86/include/asm/alternative.h
14016@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14017 ".pushsection .discard,\"aw\",@progbits\n" \
14018 DISCARD_ENTRY(1) \
14019 ".popsection\n" \
14020- ".pushsection .altinstr_replacement, \"ax\"\n" \
14021+ ".pushsection .altinstr_replacement, \"a\"\n" \
14022 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14023 ".popsection"
14024
14025@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14026 DISCARD_ENTRY(1) \
14027 DISCARD_ENTRY(2) \
14028 ".popsection\n" \
14029- ".pushsection .altinstr_replacement, \"ax\"\n" \
14030+ ".pushsection .altinstr_replacement, \"a\"\n" \
14031 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14032 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14033 ".popsection"
14034diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14035index 3388034..050f0b9 100644
14036--- a/arch/x86/include/asm/apic.h
14037+++ b/arch/x86/include/asm/apic.h
14038@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
14039
14040 #ifdef CONFIG_X86_LOCAL_APIC
14041
14042-extern unsigned int apic_verbosity;
14043+extern int apic_verbosity;
14044 extern int local_apic_timer_c2_ok;
14045
14046 extern int disable_apic;
14047diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14048index 20370c6..a2eb9b0 100644
14049--- a/arch/x86/include/asm/apm.h
14050+++ b/arch/x86/include/asm/apm.h
14051@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14052 __asm__ __volatile__(APM_DO_ZERO_SEGS
14053 "pushl %%edi\n\t"
14054 "pushl %%ebp\n\t"
14055- "lcall *%%cs:apm_bios_entry\n\t"
14056+ "lcall *%%ss:apm_bios_entry\n\t"
14057 "setc %%al\n\t"
14058 "popl %%ebp\n\t"
14059 "popl %%edi\n\t"
14060@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14061 __asm__ __volatile__(APM_DO_ZERO_SEGS
14062 "pushl %%edi\n\t"
14063 "pushl %%ebp\n\t"
14064- "lcall *%%cs:apm_bios_entry\n\t"
14065+ "lcall *%%ss:apm_bios_entry\n\t"
14066 "setc %%bl\n\t"
14067 "popl %%ebp\n\t"
14068 "popl %%edi\n\t"
14069diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14070index 722aa3b..3a0bb27 100644
14071--- a/arch/x86/include/asm/atomic.h
14072+++ b/arch/x86/include/asm/atomic.h
14073@@ -22,7 +22,18 @@
14074 */
14075 static inline int atomic_read(const atomic_t *v)
14076 {
14077- return (*(volatile int *)&(v)->counter);
14078+ return (*(volatile const int *)&(v)->counter);
14079+}
14080+
14081+/**
14082+ * atomic_read_unchecked - read atomic variable
14083+ * @v: pointer of type atomic_unchecked_t
14084+ *
14085+ * Atomically reads the value of @v.
14086+ */
14087+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
14088+{
14089+ return (*(volatile const int *)&(v)->counter);
14090 }
14091
14092 /**
14093@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
14094 }
14095
14096 /**
14097+ * atomic_set_unchecked - set atomic variable
14098+ * @v: pointer of type atomic_unchecked_t
14099+ * @i: required value
14100+ *
14101+ * Atomically sets the value of @v to @i.
14102+ */
14103+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14104+{
14105+ v->counter = i;
14106+}
14107+
14108+/**
14109 * atomic_add - add integer to atomic variable
14110 * @i: integer value to add
14111 * @v: pointer of type atomic_t
14112@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
14113 */
14114 static inline void atomic_add(int i, atomic_t *v)
14115 {
14116- asm volatile(LOCK_PREFIX "addl %1,%0"
14117+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14118+
14119+#ifdef CONFIG_PAX_REFCOUNT
14120+ "jno 0f\n"
14121+ LOCK_PREFIX "subl %1,%0\n"
14122+ "int $4\n0:\n"
14123+ _ASM_EXTABLE(0b, 0b)
14124+#endif
14125+
14126+ : "+m" (v->counter)
14127+ : "ir" (i));
14128+}
14129+
14130+/**
14131+ * atomic_add_unchecked - add integer to atomic variable
14132+ * @i: integer value to add
14133+ * @v: pointer of type atomic_unchecked_t
14134+ *
14135+ * Atomically adds @i to @v.
14136+ */
14137+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14138+{
14139+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14140 : "+m" (v->counter)
14141 : "ir" (i));
14142 }
14143@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
14144 */
14145 static inline void atomic_sub(int i, atomic_t *v)
14146 {
14147- asm volatile(LOCK_PREFIX "subl %1,%0"
14148+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14149+
14150+#ifdef CONFIG_PAX_REFCOUNT
14151+ "jno 0f\n"
14152+ LOCK_PREFIX "addl %1,%0\n"
14153+ "int $4\n0:\n"
14154+ _ASM_EXTABLE(0b, 0b)
14155+#endif
14156+
14157+ : "+m" (v->counter)
14158+ : "ir" (i));
14159+}
14160+
14161+/**
14162+ * atomic_sub_unchecked - subtract integer from atomic variable
14163+ * @i: integer value to subtract
14164+ * @v: pointer of type atomic_unchecked_t
14165+ *
14166+ * Atomically subtracts @i from @v.
14167+ */
14168+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14169+{
14170+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14171 : "+m" (v->counter)
14172 : "ir" (i));
14173 }
14174@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14175 {
14176 unsigned char c;
14177
14178- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
14179+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
14180+
14181+#ifdef CONFIG_PAX_REFCOUNT
14182+ "jno 0f\n"
14183+ LOCK_PREFIX "addl %2,%0\n"
14184+ "int $4\n0:\n"
14185+ _ASM_EXTABLE(0b, 0b)
14186+#endif
14187+
14188+ "sete %1\n"
14189 : "+m" (v->counter), "=qm" (c)
14190 : "ir" (i) : "memory");
14191 return c;
14192@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14193 */
14194 static inline void atomic_inc(atomic_t *v)
14195 {
14196- asm volatile(LOCK_PREFIX "incl %0"
14197+ asm volatile(LOCK_PREFIX "incl %0\n"
14198+
14199+#ifdef CONFIG_PAX_REFCOUNT
14200+ "jno 0f\n"
14201+ LOCK_PREFIX "decl %0\n"
14202+ "int $4\n0:\n"
14203+ _ASM_EXTABLE(0b, 0b)
14204+#endif
14205+
14206+ : "+m" (v->counter));
14207+}
14208+
14209+/**
14210+ * atomic_inc_unchecked - increment atomic variable
14211+ * @v: pointer of type atomic_unchecked_t
14212+ *
14213+ * Atomically increments @v by 1.
14214+ */
14215+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14216+{
14217+ asm volatile(LOCK_PREFIX "incl %0\n"
14218 : "+m" (v->counter));
14219 }
14220
14221@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
14222 */
14223 static inline void atomic_dec(atomic_t *v)
14224 {
14225- asm volatile(LOCK_PREFIX "decl %0"
14226+ asm volatile(LOCK_PREFIX "decl %0\n"
14227+
14228+#ifdef CONFIG_PAX_REFCOUNT
14229+ "jno 0f\n"
14230+ LOCK_PREFIX "incl %0\n"
14231+ "int $4\n0:\n"
14232+ _ASM_EXTABLE(0b, 0b)
14233+#endif
14234+
14235+ : "+m" (v->counter));
14236+}
14237+
14238+/**
14239+ * atomic_dec_unchecked - decrement atomic variable
14240+ * @v: pointer of type atomic_unchecked_t
14241+ *
14242+ * Atomically decrements @v by 1.
14243+ */
14244+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14245+{
14246+ asm volatile(LOCK_PREFIX "decl %0\n"
14247 : "+m" (v->counter));
14248 }
14249
14250@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
14251 {
14252 unsigned char c;
14253
14254- asm volatile(LOCK_PREFIX "decl %0; sete %1"
14255+ asm volatile(LOCK_PREFIX "decl %0\n"
14256+
14257+#ifdef CONFIG_PAX_REFCOUNT
14258+ "jno 0f\n"
14259+ LOCK_PREFIX "incl %0\n"
14260+ "int $4\n0:\n"
14261+ _ASM_EXTABLE(0b, 0b)
14262+#endif
14263+
14264+ "sete %1\n"
14265 : "+m" (v->counter), "=qm" (c)
14266 : : "memory");
14267 return c != 0;
14268@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
14269 {
14270 unsigned char c;
14271
14272- asm volatile(LOCK_PREFIX "incl %0; sete %1"
14273+ asm volatile(LOCK_PREFIX "incl %0\n"
14274+
14275+#ifdef CONFIG_PAX_REFCOUNT
14276+ "jno 0f\n"
14277+ LOCK_PREFIX "decl %0\n"
14278+ "int $4\n0:\n"
14279+ _ASM_EXTABLE(0b, 0b)
14280+#endif
14281+
14282+ "sete %1\n"
14283+ : "+m" (v->counter), "=qm" (c)
14284+ : : "memory");
14285+ return c != 0;
14286+}
14287+
14288+/**
14289+ * atomic_inc_and_test_unchecked - increment and test
14290+ * @v: pointer of type atomic_unchecked_t
14291+ *
14292+ * Atomically increments @v by 1
14293+ * and returns true if the result is zero, or false for all
14294+ * other cases.
14295+ */
14296+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14297+{
14298+ unsigned char c;
14299+
14300+ asm volatile(LOCK_PREFIX "incl %0\n"
14301+ "sete %1\n"
14302 : "+m" (v->counter), "=qm" (c)
14303 : : "memory");
14304 return c != 0;
14305@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14306 {
14307 unsigned char c;
14308
14309- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
14310+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
14311+
14312+#ifdef CONFIG_PAX_REFCOUNT
14313+ "jno 0f\n"
14314+ LOCK_PREFIX "subl %2,%0\n"
14315+ "int $4\n0:\n"
14316+ _ASM_EXTABLE(0b, 0b)
14317+#endif
14318+
14319+ "sets %1\n"
14320 : "+m" (v->counter), "=qm" (c)
14321 : "ir" (i) : "memory");
14322 return c;
14323@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14324 */
14325 static inline int atomic_add_return(int i, atomic_t *v)
14326 {
14327+ return i + xadd_check_overflow(&v->counter, i);
14328+}
14329+
14330+/**
14331+ * atomic_add_return_unchecked - add integer and return
14332+ * @i: integer value to add
14333+ * @v: pointer of type atomic_unchecked_t
14334+ *
14335+ * Atomically adds @i to @v and returns @i + @v
14336+ */
14337+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14338+{
14339 return i + xadd(&v->counter, i);
14340 }
14341
14342@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14343 }
14344
14345 #define atomic_inc_return(v) (atomic_add_return(1, v))
14346+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14347+{
14348+ return atomic_add_return_unchecked(1, v);
14349+}
14350 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14351
14352 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14353@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14354 return cmpxchg(&v->counter, old, new);
14355 }
14356
14357+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14358+{
14359+ return cmpxchg(&v->counter, old, new);
14360+}
14361+
14362 static inline int atomic_xchg(atomic_t *v, int new)
14363 {
14364 return xchg(&v->counter, new);
14365 }
14366
14367+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14368+{
14369+ return xchg(&v->counter, new);
14370+}
14371+
14372 /**
14373 * __atomic_add_unless - add unless the number is already a given value
14374 * @v: pointer of type atomic_t
14375@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
14376 */
14377 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14378 {
14379- int c, old;
14380+ int c, old, new;
14381 c = atomic_read(v);
14382 for (;;) {
14383- if (unlikely(c == (u)))
14384+ if (unlikely(c == u))
14385 break;
14386- old = atomic_cmpxchg((v), c, c + (a));
14387+
14388+ asm volatile("addl %2,%0\n"
14389+
14390+#ifdef CONFIG_PAX_REFCOUNT
14391+ "jno 0f\n"
14392+ "subl %2,%0\n"
14393+ "int $4\n0:\n"
14394+ _ASM_EXTABLE(0b, 0b)
14395+#endif
14396+
14397+ : "=r" (new)
14398+ : "0" (c), "ir" (a));
14399+
14400+ old = atomic_cmpxchg(v, c, new);
14401 if (likely(old == c))
14402 break;
14403 c = old;
14404@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14405 }
14406
14407 /**
14408+ * atomic_inc_not_zero_hint - increment if not null
14409+ * @v: pointer of type atomic_t
14410+ * @hint: probable value of the atomic before the increment
14411+ *
14412+ * This version of atomic_inc_not_zero() gives a hint of probable
14413+ * value of the atomic. This helps processor to not read the memory
14414+ * before doing the atomic read/modify/write cycle, lowering
14415+ * number of bus transactions on some arches.
14416+ *
14417+ * Returns: 0 if increment was not done, 1 otherwise.
14418+ */
14419+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14420+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14421+{
14422+ int val, c = hint, new;
14423+
14424+ /* sanity test, should be removed by compiler if hint is a constant */
14425+ if (!hint)
14426+ return __atomic_add_unless(v, 1, 0);
14427+
14428+ do {
14429+ asm volatile("incl %0\n"
14430+
14431+#ifdef CONFIG_PAX_REFCOUNT
14432+ "jno 0f\n"
14433+ "decl %0\n"
14434+ "int $4\n0:\n"
14435+ _ASM_EXTABLE(0b, 0b)
14436+#endif
14437+
14438+ : "=r" (new)
14439+ : "0" (c));
14440+
14441+ val = atomic_cmpxchg(v, c, new);
14442+ if (val == c)
14443+ return 1;
14444+ c = val;
14445+ } while (c);
14446+
14447+ return 0;
14448+}
14449+
14450+/**
14451 * atomic_inc_short - increment of a short integer
14452 * @v: pointer to type int
14453 *
14454@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14455 #endif
14456
14457 /* These are x86-specific, used by some header files */
14458-#define atomic_clear_mask(mask, addr) \
14459- asm volatile(LOCK_PREFIX "andl %0,%1" \
14460- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14461+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14462+{
14463+ asm volatile(LOCK_PREFIX "andl %1,%0"
14464+ : "+m" (v->counter)
14465+ : "r" (~(mask))
14466+ : "memory");
14467+}
14468
14469-#define atomic_set_mask(mask, addr) \
14470- asm volatile(LOCK_PREFIX "orl %0,%1" \
14471- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14472- : "memory")
14473+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14474+{
14475+ asm volatile(LOCK_PREFIX "andl %1,%0"
14476+ : "+m" (v->counter)
14477+ : "r" (~(mask))
14478+ : "memory");
14479+}
14480+
14481+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14482+{
14483+ asm volatile(LOCK_PREFIX "orl %1,%0"
14484+ : "+m" (v->counter)
14485+ : "r" (mask)
14486+ : "memory");
14487+}
14488+
14489+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14490+{
14491+ asm volatile(LOCK_PREFIX "orl %1,%0"
14492+ : "+m" (v->counter)
14493+ : "r" (mask)
14494+ : "memory");
14495+}
14496
14497 /* Atomic operations are already serializing on x86 */
14498 #define smp_mb__before_atomic_dec() barrier()
14499diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14500index b154de7..aadebd8 100644
14501--- a/arch/x86/include/asm/atomic64_32.h
14502+++ b/arch/x86/include/asm/atomic64_32.h
14503@@ -12,6 +12,14 @@ typedef struct {
14504 u64 __aligned(8) counter;
14505 } atomic64_t;
14506
14507+#ifdef CONFIG_PAX_REFCOUNT
14508+typedef struct {
14509+ u64 __aligned(8) counter;
14510+} atomic64_unchecked_t;
14511+#else
14512+typedef atomic64_t atomic64_unchecked_t;
14513+#endif
14514+
14515 #define ATOMIC64_INIT(val) { (val) }
14516
14517 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14518@@ -37,21 +45,31 @@ typedef struct {
14519 ATOMIC64_DECL_ONE(sym##_386)
14520
14521 ATOMIC64_DECL_ONE(add_386);
14522+ATOMIC64_DECL_ONE(add_unchecked_386);
14523 ATOMIC64_DECL_ONE(sub_386);
14524+ATOMIC64_DECL_ONE(sub_unchecked_386);
14525 ATOMIC64_DECL_ONE(inc_386);
14526+ATOMIC64_DECL_ONE(inc_unchecked_386);
14527 ATOMIC64_DECL_ONE(dec_386);
14528+ATOMIC64_DECL_ONE(dec_unchecked_386);
14529 #endif
14530
14531 #define alternative_atomic64(f, out, in...) \
14532 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14533
14534 ATOMIC64_DECL(read);
14535+ATOMIC64_DECL(read_unchecked);
14536 ATOMIC64_DECL(set);
14537+ATOMIC64_DECL(set_unchecked);
14538 ATOMIC64_DECL(xchg);
14539 ATOMIC64_DECL(add_return);
14540+ATOMIC64_DECL(add_return_unchecked);
14541 ATOMIC64_DECL(sub_return);
14542+ATOMIC64_DECL(sub_return_unchecked);
14543 ATOMIC64_DECL(inc_return);
14544+ATOMIC64_DECL(inc_return_unchecked);
14545 ATOMIC64_DECL(dec_return);
14546+ATOMIC64_DECL(dec_return_unchecked);
14547 ATOMIC64_DECL(dec_if_positive);
14548 ATOMIC64_DECL(inc_not_zero);
14549 ATOMIC64_DECL(add_unless);
14550@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14551 }
14552
14553 /**
14554+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14555+ * @p: pointer to type atomic64_unchecked_t
14556+ * @o: expected value
14557+ * @n: new value
14558+ *
14559+ * Atomically sets @v to @n if it was equal to @o and returns
14560+ * the old value.
14561+ */
14562+
14563+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14564+{
14565+ return cmpxchg64(&v->counter, o, n);
14566+}
14567+
14568+/**
14569 * atomic64_xchg - xchg atomic64 variable
14570 * @v: pointer to type atomic64_t
14571 * @n: value to assign
14572@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14573 }
14574
14575 /**
14576+ * atomic64_set_unchecked - set atomic64 variable
14577+ * @v: pointer to type atomic64_unchecked_t
14578+ * @n: value to assign
14579+ *
14580+ * Atomically sets the value of @v to @n.
14581+ */
14582+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14583+{
14584+ unsigned high = (unsigned)(i >> 32);
14585+ unsigned low = (unsigned)i;
14586+ alternative_atomic64(set, /* no output */,
14587+ "S" (v), "b" (low), "c" (high)
14588+ : "eax", "edx", "memory");
14589+}
14590+
14591+/**
14592 * atomic64_read - read atomic64 variable
14593 * @v: pointer to type atomic64_t
14594 *
14595@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14596 }
14597
14598 /**
14599+ * atomic64_read_unchecked - read atomic64 variable
14600+ * @v: pointer to type atomic64_unchecked_t
14601+ *
14602+ * Atomically reads the value of @v and returns it.
14603+ */
14604+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
14605+{
14606+ long long r;
14607+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14608+ return r;
14609+ }
14610+
14611+/**
14612 * atomic64_add_return - add and return
14613 * @i: integer value to add
14614 * @v: pointer to type atomic64_t
14615@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14616 return i;
14617 }
14618
14619+/**
14620+ * atomic64_add_return_unchecked - add and return
14621+ * @i: integer value to add
14622+ * @v: pointer to type atomic64_unchecked_t
14623+ *
14624+ * Atomically adds @i to @v and returns @i + *@v
14625+ */
14626+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14627+{
14628+ alternative_atomic64(add_return_unchecked,
14629+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14630+ ASM_NO_INPUT_CLOBBER("memory"));
14631+ return i;
14632+}
14633+
14634 /*
14635 * Other variants with different arithmetic operators:
14636 */
14637@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14638 return a;
14639 }
14640
14641+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14642+{
14643+ long long a;
14644+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14645+ "S" (v) : "memory", "ecx");
14646+ return a;
14647+}
14648+
14649 static inline long long atomic64_dec_return(atomic64_t *v)
14650 {
14651 long long a;
14652@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14653 }
14654
14655 /**
14656+ * atomic64_add_unchecked - add integer to atomic64 variable
14657+ * @i: integer value to add
14658+ * @v: pointer to type atomic64_unchecked_t
14659+ *
14660+ * Atomically adds @i to @v.
14661+ */
14662+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14663+{
14664+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14665+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14666+ ASM_NO_INPUT_CLOBBER("memory"));
14667+ return i;
14668+}
14669+
14670+/**
14671 * atomic64_sub - subtract the atomic64 variable
14672 * @i: integer value to subtract
14673 * @v: pointer to type atomic64_t
14674diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14675index 0e1cbfc..5623683 100644
14676--- a/arch/x86/include/asm/atomic64_64.h
14677+++ b/arch/x86/include/asm/atomic64_64.h
14678@@ -18,7 +18,19 @@
14679 */
14680 static inline long atomic64_read(const atomic64_t *v)
14681 {
14682- return (*(volatile long *)&(v)->counter);
14683+ return (*(volatile const long *)&(v)->counter);
14684+}
14685+
14686+/**
14687+ * atomic64_read_unchecked - read atomic64 variable
14688+ * @v: pointer of type atomic64_unchecked_t
14689+ *
14690+ * Atomically reads the value of @v.
14691+ * Doesn't imply a read memory barrier.
14692+ */
14693+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
14694+{
14695+ return (*(volatile const long *)&(v)->counter);
14696 }
14697
14698 /**
14699@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14700 }
14701
14702 /**
14703+ * atomic64_set_unchecked - set atomic64 variable
14704+ * @v: pointer to type atomic64_unchecked_t
14705+ * @i: required value
14706+ *
14707+ * Atomically sets the value of @v to @i.
14708+ */
14709+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14710+{
14711+ v->counter = i;
14712+}
14713+
14714+/**
14715 * atomic64_add - add integer to atomic64 variable
14716 * @i: integer value to add
14717 * @v: pointer to type atomic64_t
14718@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14719 */
14720 static inline void atomic64_add(long i, atomic64_t *v)
14721 {
14722+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14723+
14724+#ifdef CONFIG_PAX_REFCOUNT
14725+ "jno 0f\n"
14726+ LOCK_PREFIX "subq %1,%0\n"
14727+ "int $4\n0:\n"
14728+ _ASM_EXTABLE(0b, 0b)
14729+#endif
14730+
14731+ : "=m" (v->counter)
14732+ : "er" (i), "m" (v->counter));
14733+}
14734+
14735+/**
14736+ * atomic64_add_unchecked - add integer to atomic64 variable
14737+ * @i: integer value to add
14738+ * @v: pointer to type atomic64_unchecked_t
14739+ *
14740+ * Atomically adds @i to @v.
14741+ */
14742+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14743+{
14744 asm volatile(LOCK_PREFIX "addq %1,%0"
14745 : "=m" (v->counter)
14746 : "er" (i), "m" (v->counter));
14747@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14748 */
14749 static inline void atomic64_sub(long i, atomic64_t *v)
14750 {
14751- asm volatile(LOCK_PREFIX "subq %1,%0"
14752+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14753+
14754+#ifdef CONFIG_PAX_REFCOUNT
14755+ "jno 0f\n"
14756+ LOCK_PREFIX "addq %1,%0\n"
14757+ "int $4\n0:\n"
14758+ _ASM_EXTABLE(0b, 0b)
14759+#endif
14760+
14761+ : "=m" (v->counter)
14762+ : "er" (i), "m" (v->counter));
14763+}
14764+
14765+/**
14766+ * atomic64_sub_unchecked - subtract the atomic64 variable
14767+ * @i: integer value to subtract
14768+ * @v: pointer to type atomic64_unchecked_t
14769+ *
14770+ * Atomically subtracts @i from @v.
14771+ */
14772+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14773+{
14774+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14775 : "=m" (v->counter)
14776 : "er" (i), "m" (v->counter));
14777 }
14778@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14779 {
14780 unsigned char c;
14781
14782- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14783+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14784+
14785+#ifdef CONFIG_PAX_REFCOUNT
14786+ "jno 0f\n"
14787+ LOCK_PREFIX "addq %2,%0\n"
14788+ "int $4\n0:\n"
14789+ _ASM_EXTABLE(0b, 0b)
14790+#endif
14791+
14792+ "sete %1\n"
14793 : "=m" (v->counter), "=qm" (c)
14794 : "er" (i), "m" (v->counter) : "memory");
14795 return c;
14796@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14797 */
14798 static inline void atomic64_inc(atomic64_t *v)
14799 {
14800+ asm volatile(LOCK_PREFIX "incq %0\n"
14801+
14802+#ifdef CONFIG_PAX_REFCOUNT
14803+ "jno 0f\n"
14804+ LOCK_PREFIX "decq %0\n"
14805+ "int $4\n0:\n"
14806+ _ASM_EXTABLE(0b, 0b)
14807+#endif
14808+
14809+ : "=m" (v->counter)
14810+ : "m" (v->counter));
14811+}
14812+
14813+/**
14814+ * atomic64_inc_unchecked - increment atomic64 variable
14815+ * @v: pointer to type atomic64_unchecked_t
14816+ *
14817+ * Atomically increments @v by 1.
14818+ */
14819+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14820+{
14821 asm volatile(LOCK_PREFIX "incq %0"
14822 : "=m" (v->counter)
14823 : "m" (v->counter));
14824@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
14825 */
14826 static inline void atomic64_dec(atomic64_t *v)
14827 {
14828- asm volatile(LOCK_PREFIX "decq %0"
14829+ asm volatile(LOCK_PREFIX "decq %0\n"
14830+
14831+#ifdef CONFIG_PAX_REFCOUNT
14832+ "jno 0f\n"
14833+ LOCK_PREFIX "incq %0\n"
14834+ "int $4\n0:\n"
14835+ _ASM_EXTABLE(0b, 0b)
14836+#endif
14837+
14838+ : "=m" (v->counter)
14839+ : "m" (v->counter));
14840+}
14841+
14842+/**
14843+ * atomic64_dec_unchecked - decrement atomic64 variable
14844+ * @v: pointer to type atomic64_t
14845+ *
14846+ * Atomically decrements @v by 1.
14847+ */
14848+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
14849+{
14850+ asm volatile(LOCK_PREFIX "decq %0\n"
14851 : "=m" (v->counter)
14852 : "m" (v->counter));
14853 }
14854@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
14855 {
14856 unsigned char c;
14857
14858- asm volatile(LOCK_PREFIX "decq %0; sete %1"
14859+ asm volatile(LOCK_PREFIX "decq %0\n"
14860+
14861+#ifdef CONFIG_PAX_REFCOUNT
14862+ "jno 0f\n"
14863+ LOCK_PREFIX "incq %0\n"
14864+ "int $4\n0:\n"
14865+ _ASM_EXTABLE(0b, 0b)
14866+#endif
14867+
14868+ "sete %1\n"
14869 : "=m" (v->counter), "=qm" (c)
14870 : "m" (v->counter) : "memory");
14871 return c != 0;
14872@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
14873 {
14874 unsigned char c;
14875
14876- asm volatile(LOCK_PREFIX "incq %0; sete %1"
14877+ asm volatile(LOCK_PREFIX "incq %0\n"
14878+
14879+#ifdef CONFIG_PAX_REFCOUNT
14880+ "jno 0f\n"
14881+ LOCK_PREFIX "decq %0\n"
14882+ "int $4\n0:\n"
14883+ _ASM_EXTABLE(0b, 0b)
14884+#endif
14885+
14886+ "sete %1\n"
14887 : "=m" (v->counter), "=qm" (c)
14888 : "m" (v->counter) : "memory");
14889 return c != 0;
14890@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14891 {
14892 unsigned char c;
14893
14894- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
14895+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
14896+
14897+#ifdef CONFIG_PAX_REFCOUNT
14898+ "jno 0f\n"
14899+ LOCK_PREFIX "subq %2,%0\n"
14900+ "int $4\n0:\n"
14901+ _ASM_EXTABLE(0b, 0b)
14902+#endif
14903+
14904+ "sets %1\n"
14905 : "=m" (v->counter), "=qm" (c)
14906 : "er" (i), "m" (v->counter) : "memory");
14907 return c;
14908@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14909 */
14910 static inline long atomic64_add_return(long i, atomic64_t *v)
14911 {
14912+ return i + xadd_check_overflow(&v->counter, i);
14913+}
14914+
14915+/**
14916+ * atomic64_add_return_unchecked - add and return
14917+ * @i: integer value to add
14918+ * @v: pointer to type atomic64_unchecked_t
14919+ *
14920+ * Atomically adds @i to @v and returns @i + @v
14921+ */
14922+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
14923+{
14924 return i + xadd(&v->counter, i);
14925 }
14926
14927@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
14928 }
14929
14930 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
14931+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14932+{
14933+ return atomic64_add_return_unchecked(1, v);
14934+}
14935 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
14936
14937 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14938@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14939 return cmpxchg(&v->counter, old, new);
14940 }
14941
14942+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
14943+{
14944+ return cmpxchg(&v->counter, old, new);
14945+}
14946+
14947 static inline long atomic64_xchg(atomic64_t *v, long new)
14948 {
14949 return xchg(&v->counter, new);
14950@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
14951 */
14952 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
14953 {
14954- long c, old;
14955+ long c, old, new;
14956 c = atomic64_read(v);
14957 for (;;) {
14958- if (unlikely(c == (u)))
14959+ if (unlikely(c == u))
14960 break;
14961- old = atomic64_cmpxchg((v), c, c + (a));
14962+
14963+ asm volatile("add %2,%0\n"
14964+
14965+#ifdef CONFIG_PAX_REFCOUNT
14966+ "jno 0f\n"
14967+ "sub %2,%0\n"
14968+ "int $4\n0:\n"
14969+ _ASM_EXTABLE(0b, 0b)
14970+#endif
14971+
14972+ : "=r" (new)
14973+ : "0" (c), "ir" (a));
14974+
14975+ old = atomic64_cmpxchg(v, c, new);
14976 if (likely(old == c))
14977 break;
14978 c = old;
14979 }
14980- return c != (u);
14981+ return c != u;
14982 }
14983
14984 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
14985diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
14986index 6dfd019..28e188d 100644
14987--- a/arch/x86/include/asm/bitops.h
14988+++ b/arch/x86/include/asm/bitops.h
14989@@ -40,7 +40,7 @@
14990 * a mask operation on a byte.
14991 */
14992 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
14993-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
14994+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
14995 #define CONST_MASK(nr) (1 << ((nr) & 7))
14996
14997 /**
14998@@ -486,7 +486,7 @@ static inline int fls(int x)
14999 * at position 64.
15000 */
15001 #ifdef CONFIG_X86_64
15002-static __always_inline int fls64(__u64 x)
15003+static __always_inline long fls64(__u64 x)
15004 {
15005 int bitpos = -1;
15006 /*
15007diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15008index 4fa687a..60f2d39 100644
15009--- a/arch/x86/include/asm/boot.h
15010+++ b/arch/x86/include/asm/boot.h
15011@@ -6,10 +6,15 @@
15012 #include <uapi/asm/boot.h>
15013
15014 /* Physical address where kernel should be loaded. */
15015-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15016+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15017 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15018 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15019
15020+#ifndef __ASSEMBLY__
15021+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15022+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15023+#endif
15024+
15025 /* Minimum kernel alignment, as a power of two */
15026 #ifdef CONFIG_X86_64
15027 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15028diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15029index 48f99f1..d78ebf9 100644
15030--- a/arch/x86/include/asm/cache.h
15031+++ b/arch/x86/include/asm/cache.h
15032@@ -5,12 +5,13 @@
15033
15034 /* L1 cache line size */
15035 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15036-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15037+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15038
15039 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15040+#define __read_only __attribute__((__section__(".data..read_only")))
15041
15042 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15043-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15044+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15045
15046 #ifdef CONFIG_X86_VSMP
15047 #ifdef CONFIG_SMP
15048diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15049index 9863ee3..4a1f8e1 100644
15050--- a/arch/x86/include/asm/cacheflush.h
15051+++ b/arch/x86/include/asm/cacheflush.h
15052@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15053 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15054
15055 if (pg_flags == _PGMT_DEFAULT)
15056- return -1;
15057+ return ~0UL;
15058 else if (pg_flags == _PGMT_WC)
15059 return _PAGE_CACHE_WC;
15060 else if (pg_flags == _PGMT_UC_MINUS)
15061diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15062index 46fc474..b02b0f9 100644
15063--- a/arch/x86/include/asm/checksum_32.h
15064+++ b/arch/x86/include/asm/checksum_32.h
15065@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15066 int len, __wsum sum,
15067 int *src_err_ptr, int *dst_err_ptr);
15068
15069+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15070+ int len, __wsum sum,
15071+ int *src_err_ptr, int *dst_err_ptr);
15072+
15073+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15074+ int len, __wsum sum,
15075+ int *src_err_ptr, int *dst_err_ptr);
15076+
15077 /*
15078 * Note: when you get a NULL pointer exception here this means someone
15079 * passed in an incorrect kernel address to one of these functions.
15080@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15081 int *err_ptr)
15082 {
15083 might_sleep();
15084- return csum_partial_copy_generic((__force void *)src, dst,
15085+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
15086 len, sum, err_ptr, NULL);
15087 }
15088
15089@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15090 {
15091 might_sleep();
15092 if (access_ok(VERIFY_WRITE, dst, len))
15093- return csum_partial_copy_generic(src, (__force void *)dst,
15094+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
15095 len, sum, NULL, err_ptr);
15096
15097 if (len)
15098diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15099index d47786a..ce1b05d 100644
15100--- a/arch/x86/include/asm/cmpxchg.h
15101+++ b/arch/x86/include/asm/cmpxchg.h
15102@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15103 __compiletime_error("Bad argument size for cmpxchg");
15104 extern void __xadd_wrong_size(void)
15105 __compiletime_error("Bad argument size for xadd");
15106+extern void __xadd_check_overflow_wrong_size(void)
15107+ __compiletime_error("Bad argument size for xadd_check_overflow");
15108 extern void __add_wrong_size(void)
15109 __compiletime_error("Bad argument size for add");
15110+extern void __add_check_overflow_wrong_size(void)
15111+ __compiletime_error("Bad argument size for add_check_overflow");
15112
15113 /*
15114 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15115@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
15116 __ret; \
15117 })
15118
15119+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15120+ ({ \
15121+ __typeof__ (*(ptr)) __ret = (arg); \
15122+ switch (sizeof(*(ptr))) { \
15123+ case __X86_CASE_L: \
15124+ asm volatile (lock #op "l %0, %1\n" \
15125+ "jno 0f\n" \
15126+ "mov %0,%1\n" \
15127+ "int $4\n0:\n" \
15128+ _ASM_EXTABLE(0b, 0b) \
15129+ : "+r" (__ret), "+m" (*(ptr)) \
15130+ : : "memory", "cc"); \
15131+ break; \
15132+ case __X86_CASE_Q: \
15133+ asm volatile (lock #op "q %q0, %1\n" \
15134+ "jno 0f\n" \
15135+ "mov %0,%1\n" \
15136+ "int $4\n0:\n" \
15137+ _ASM_EXTABLE(0b, 0b) \
15138+ : "+r" (__ret), "+m" (*(ptr)) \
15139+ : : "memory", "cc"); \
15140+ break; \
15141+ default: \
15142+ __ ## op ## _check_overflow_wrong_size(); \
15143+ } \
15144+ __ret; \
15145+ })
15146+
15147 /*
15148 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15149 * Since this is generally used to protect other memory information, we
15150@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
15151 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15152 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15153
15154+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15155+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15156+
15157 #define __add(ptr, inc, lock) \
15158 ({ \
15159 __typeof__ (*(ptr)) __ret = (inc); \
15160diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15161index 59c6c40..5e0b22c 100644
15162--- a/arch/x86/include/asm/compat.h
15163+++ b/arch/x86/include/asm/compat.h
15164@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15165 typedef u32 compat_uint_t;
15166 typedef u32 compat_ulong_t;
15167 typedef u64 __attribute__((aligned(4))) compat_u64;
15168-typedef u32 compat_uptr_t;
15169+typedef u32 __user compat_uptr_t;
15170
15171 struct compat_timespec {
15172 compat_time_t tv_sec;
15173diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
15174index e99ac27..10d834e 100644
15175--- a/arch/x86/include/asm/cpufeature.h
15176+++ b/arch/x86/include/asm/cpufeature.h
15177@@ -203,7 +203,7 @@
15178 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
15179 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
15180 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
15181-
15182+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
15183
15184 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
15185 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
15186@@ -211,7 +211,7 @@
15187 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
15188 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
15189 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
15190-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
15191+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
15192 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
15193 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
15194 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
15195@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
15196 #undef cpu_has_centaur_mcr
15197 #define cpu_has_centaur_mcr 0
15198
15199+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
15200 #endif /* CONFIG_X86_64 */
15201
15202 #if __GNUC__ >= 4
15203@@ -394,7 +395,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15204 ".section .discard,\"aw\",@progbits\n"
15205 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15206 ".previous\n"
15207- ".section .altinstr_replacement,\"ax\"\n"
15208+ ".section .altinstr_replacement,\"a\"\n"
15209 "3: movb $1,%0\n"
15210 "4:\n"
15211 ".previous\n"
15212diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
15213index 8bf1c06..b6ae785 100644
15214--- a/arch/x86/include/asm/desc.h
15215+++ b/arch/x86/include/asm/desc.h
15216@@ -4,6 +4,7 @@
15217 #include <asm/desc_defs.h>
15218 #include <asm/ldt.h>
15219 #include <asm/mmu.h>
15220+#include <asm/pgtable.h>
15221
15222 #include <linux/smp.h>
15223 #include <linux/percpu.h>
15224@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15225
15226 desc->type = (info->read_exec_only ^ 1) << 1;
15227 desc->type |= info->contents << 2;
15228+ desc->type |= info->seg_not_present ^ 1;
15229
15230 desc->s = 1;
15231 desc->dpl = 0x3;
15232@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15233 }
15234
15235 extern struct desc_ptr idt_descr;
15236-extern gate_desc idt_table[];
15237 extern struct desc_ptr nmi_idt_descr;
15238-extern gate_desc nmi_idt_table[];
15239-
15240-struct gdt_page {
15241- struct desc_struct gdt[GDT_ENTRIES];
15242-} __attribute__((aligned(PAGE_SIZE)));
15243-
15244-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
15245+extern gate_desc idt_table[256];
15246+extern gate_desc nmi_idt_table[256];
15247
15248+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
15249 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
15250 {
15251- return per_cpu(gdt_page, cpu).gdt;
15252+ return cpu_gdt_table[cpu];
15253 }
15254
15255 #ifdef CONFIG_X86_64
15256@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15257 unsigned long base, unsigned dpl, unsigned flags,
15258 unsigned short seg)
15259 {
15260- gate->a = (seg << 16) | (base & 0xffff);
15261- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15262+ gate->gate.offset_low = base;
15263+ gate->gate.seg = seg;
15264+ gate->gate.reserved = 0;
15265+ gate->gate.type = type;
15266+ gate->gate.s = 0;
15267+ gate->gate.dpl = dpl;
15268+ gate->gate.p = 1;
15269+ gate->gate.offset_high = base >> 16;
15270 }
15271
15272 #endif
15273@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15274
15275 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15276 {
15277+ pax_open_kernel();
15278 memcpy(&idt[entry], gate, sizeof(*gate));
15279+ pax_close_kernel();
15280 }
15281
15282 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15283 {
15284+ pax_open_kernel();
15285 memcpy(&ldt[entry], desc, 8);
15286+ pax_close_kernel();
15287 }
15288
15289 static inline void
15290@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15291 default: size = sizeof(*gdt); break;
15292 }
15293
15294+ pax_open_kernel();
15295 memcpy(&gdt[entry], desc, size);
15296+ pax_close_kernel();
15297 }
15298
15299 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15300@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15301
15302 static inline void native_load_tr_desc(void)
15303 {
15304+ pax_open_kernel();
15305 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15306+ pax_close_kernel();
15307 }
15308
15309 static inline void native_load_gdt(const struct desc_ptr *dtr)
15310@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15311 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15312 unsigned int i;
15313
15314+ pax_open_kernel();
15315 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15316 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15317+ pax_close_kernel();
15318 }
15319
15320 #define _LDT_empty(info) \
15321@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15322 preempt_enable();
15323 }
15324
15325-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15326+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15327 {
15328 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15329 }
15330@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15331 }
15332
15333 #ifdef CONFIG_X86_64
15334-static inline void set_nmi_gate(int gate, void *addr)
15335+static inline void set_nmi_gate(int gate, const void *addr)
15336 {
15337 gate_desc s;
15338
15339@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
15340 }
15341 #endif
15342
15343-static inline void _set_gate(int gate, unsigned type, void *addr,
15344+static inline void _set_gate(int gate, unsigned type, const void *addr,
15345 unsigned dpl, unsigned ist, unsigned seg)
15346 {
15347 gate_desc s;
15348@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15349 * Pentium F0 0F bugfix can have resulted in the mapped
15350 * IDT being write-protected.
15351 */
15352-static inline void set_intr_gate(unsigned int n, void *addr)
15353+static inline void set_intr_gate(unsigned int n, const void *addr)
15354 {
15355 BUG_ON((unsigned)n > 0xFF);
15356 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15357@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
15358 /*
15359 * This routine sets up an interrupt gate at directory privilege level 3.
15360 */
15361-static inline void set_system_intr_gate(unsigned int n, void *addr)
15362+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15363 {
15364 BUG_ON((unsigned)n > 0xFF);
15365 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15366 }
15367
15368-static inline void set_system_trap_gate(unsigned int n, void *addr)
15369+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15370 {
15371 BUG_ON((unsigned)n > 0xFF);
15372 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15373 }
15374
15375-static inline void set_trap_gate(unsigned int n, void *addr)
15376+static inline void set_trap_gate(unsigned int n, const void *addr)
15377 {
15378 BUG_ON((unsigned)n > 0xFF);
15379 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15380@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15381 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15382 {
15383 BUG_ON((unsigned)n > 0xFF);
15384- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15385+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15386 }
15387
15388-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15389+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15390 {
15391 BUG_ON((unsigned)n > 0xFF);
15392 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15393 }
15394
15395-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15396+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15397 {
15398 BUG_ON((unsigned)n > 0xFF);
15399 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15400 }
15401
15402+#ifdef CONFIG_X86_32
15403+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15404+{
15405+ struct desc_struct d;
15406+
15407+ if (likely(limit))
15408+ limit = (limit - 1UL) >> PAGE_SHIFT;
15409+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15410+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15411+}
15412+#endif
15413+
15414 #endif /* _ASM_X86_DESC_H */
15415diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15416index 278441f..b95a174 100644
15417--- a/arch/x86/include/asm/desc_defs.h
15418+++ b/arch/x86/include/asm/desc_defs.h
15419@@ -31,6 +31,12 @@ struct desc_struct {
15420 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15421 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15422 };
15423+ struct {
15424+ u16 offset_low;
15425+ u16 seg;
15426+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15427+ unsigned offset_high: 16;
15428+ } gate;
15429 };
15430 } __attribute__((packed));
15431
15432diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15433index ced283a..ffe04cc 100644
15434--- a/arch/x86/include/asm/div64.h
15435+++ b/arch/x86/include/asm/div64.h
15436@@ -39,7 +39,7 @@
15437 __mod; \
15438 })
15439
15440-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15441+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15442 {
15443 union {
15444 u64 v64;
15445diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15446index 9c999c1..3860cb8 100644
15447--- a/arch/x86/include/asm/elf.h
15448+++ b/arch/x86/include/asm/elf.h
15449@@ -243,7 +243,25 @@ extern int force_personality32;
15450 the loader. We need to make sure that it is out of the way of the program
15451 that it will "exec", and that there is sufficient room for the brk. */
15452
15453+#ifdef CONFIG_PAX_SEGMEXEC
15454+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15455+#else
15456 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15457+#endif
15458+
15459+#ifdef CONFIG_PAX_ASLR
15460+#ifdef CONFIG_X86_32
15461+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15462+
15463+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15464+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15465+#else
15466+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15467+
15468+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15469+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15470+#endif
15471+#endif
15472
15473 /* This yields a mask that user programs can use to figure out what
15474 instruction set this CPU supports. This could be done in user space,
15475@@ -296,16 +314,12 @@ do { \
15476
15477 #define ARCH_DLINFO \
15478 do { \
15479- if (vdso_enabled) \
15480- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15481- (unsigned long)current->mm->context.vdso); \
15482+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15483 } while (0)
15484
15485 #define ARCH_DLINFO_X32 \
15486 do { \
15487- if (vdso_enabled) \
15488- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15489- (unsigned long)current->mm->context.vdso); \
15490+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15491 } while (0)
15492
15493 #define AT_SYSINFO 32
15494@@ -320,7 +334,7 @@ else \
15495
15496 #endif /* !CONFIG_X86_32 */
15497
15498-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15499+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15500
15501 #define VDSO_ENTRY \
15502 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15503@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15504 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15505 #define compat_arch_setup_additional_pages syscall32_setup_pages
15506
15507-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15508-#define arch_randomize_brk arch_randomize_brk
15509-
15510 /*
15511 * True on X86_32 or when emulating IA32 on X86_64
15512 */
15513diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15514index 75ce3f4..882e801 100644
15515--- a/arch/x86/include/asm/emergency-restart.h
15516+++ b/arch/x86/include/asm/emergency-restart.h
15517@@ -13,6 +13,6 @@ enum reboot_type {
15518
15519 extern enum reboot_type reboot_type;
15520
15521-extern void machine_emergency_restart(void);
15522+extern void machine_emergency_restart(void) __noreturn;
15523
15524 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15525diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15526index e25cc33..7d3ec01 100644
15527--- a/arch/x86/include/asm/fpu-internal.h
15528+++ b/arch/x86/include/asm/fpu-internal.h
15529@@ -126,8 +126,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15530 #define user_insn(insn, output, input...) \
15531 ({ \
15532 int err; \
15533+ pax_open_userland(); \
15534 asm volatile(ASM_STAC "\n" \
15535- "1:" #insn "\n\t" \
15536+ "1:" \
15537+ __copyuser_seg \
15538+ #insn "\n\t" \
15539 "2: " ASM_CLAC "\n" \
15540 ".section .fixup,\"ax\"\n" \
15541 "3: movl $-1,%[err]\n" \
15542@@ -136,6 +139,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15543 _ASM_EXTABLE(1b, 3b) \
15544 : [err] "=r" (err), output \
15545 : "0"(0), input); \
15546+ pax_close_userland(); \
15547 err; \
15548 })
15549
15550@@ -300,7 +304,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
15551 "emms\n\t" /* clear stack tags */
15552 "fildl %P[addr]", /* set F?P to defined value */
15553 X86_FEATURE_FXSAVE_LEAK,
15554- [addr] "m" (tsk->thread.fpu.has_fpu));
15555+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
15556
15557 return fpu_restore_checking(&tsk->thread.fpu);
15558 }
15559diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
15560index be27ba1..04a8801 100644
15561--- a/arch/x86/include/asm/futex.h
15562+++ b/arch/x86/include/asm/futex.h
15563@@ -12,6 +12,7 @@
15564 #include <asm/smap.h>
15565
15566 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15567+ typecheck(u32 __user *, uaddr); \
15568 asm volatile("\t" ASM_STAC "\n" \
15569 "1:\t" insn "\n" \
15570 "2:\t" ASM_CLAC "\n" \
15571@@ -20,15 +21,16 @@
15572 "\tjmp\t2b\n" \
15573 "\t.previous\n" \
15574 _ASM_EXTABLE(1b, 3b) \
15575- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
15576+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
15577 : "i" (-EFAULT), "0" (oparg), "1" (0))
15578
15579 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
15580+ typecheck(u32 __user *, uaddr); \
15581 asm volatile("\t" ASM_STAC "\n" \
15582 "1:\tmovl %2, %0\n" \
15583 "\tmovl\t%0, %3\n" \
15584 "\t" insn "\n" \
15585- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
15586+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
15587 "\tjnz\t1b\n" \
15588 "3:\t" ASM_CLAC "\n" \
15589 "\t.section .fixup,\"ax\"\n" \
15590@@ -38,7 +40,7 @@
15591 _ASM_EXTABLE(1b, 4b) \
15592 _ASM_EXTABLE(2b, 4b) \
15593 : "=&a" (oldval), "=&r" (ret), \
15594- "+m" (*uaddr), "=&r" (tem) \
15595+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
15596 : "r" (oparg), "i" (-EFAULT), "1" (0))
15597
15598 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15599@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15600
15601 pagefault_disable();
15602
15603+ pax_open_userland();
15604 switch (op) {
15605 case FUTEX_OP_SET:
15606- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
15607+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
15608 break;
15609 case FUTEX_OP_ADD:
15610- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
15611+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
15612 uaddr, oparg);
15613 break;
15614 case FUTEX_OP_OR:
15615@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15616 default:
15617 ret = -ENOSYS;
15618 }
15619+ pax_close_userland();
15620
15621 pagefault_enable();
15622
15623@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
15624 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
15625 return -EFAULT;
15626
15627+ pax_open_userland();
15628 asm volatile("\t" ASM_STAC "\n"
15629- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
15630+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
15631 "2:\t" ASM_CLAC "\n"
15632 "\t.section .fixup, \"ax\"\n"
15633 "3:\tmov %3, %0\n"
15634 "\tjmp 2b\n"
15635 "\t.previous\n"
15636 _ASM_EXTABLE(1b, 3b)
15637- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
15638+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
15639 : "i" (-EFAULT), "r" (newval), "1" (oldval)
15640 : "memory"
15641 );
15642+ pax_close_userland();
15643
15644 *uval = oldval;
15645 return ret;
15646diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
15647index 1da97ef..9c2ebff 100644
15648--- a/arch/x86/include/asm/hw_irq.h
15649+++ b/arch/x86/include/asm/hw_irq.h
15650@@ -148,8 +148,8 @@ extern void setup_ioapic_dest(void);
15651 extern void enable_IO_APIC(void);
15652
15653 /* Statistics */
15654-extern atomic_t irq_err_count;
15655-extern atomic_t irq_mis_count;
15656+extern atomic_unchecked_t irq_err_count;
15657+extern atomic_unchecked_t irq_mis_count;
15658
15659 /* EISA */
15660 extern void eisa_set_level_irq(unsigned int irq);
15661diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
15662index a203659..9889f1c 100644
15663--- a/arch/x86/include/asm/i8259.h
15664+++ b/arch/x86/include/asm/i8259.h
15665@@ -62,7 +62,7 @@ struct legacy_pic {
15666 void (*init)(int auto_eoi);
15667 int (*irq_pending)(unsigned int irq);
15668 void (*make_irq)(unsigned int irq);
15669-};
15670+} __do_const;
15671
15672 extern struct legacy_pic *legacy_pic;
15673 extern struct legacy_pic null_legacy_pic;
15674diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
15675index d8e8eef..1765f78 100644
15676--- a/arch/x86/include/asm/io.h
15677+++ b/arch/x86/include/asm/io.h
15678@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
15679 "m" (*(volatile type __force *)addr) barrier); }
15680
15681 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
15682-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
15683-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
15684+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
15685+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
15686
15687 build_mmio_read(__readb, "b", unsigned char, "=q", )
15688-build_mmio_read(__readw, "w", unsigned short, "=r", )
15689-build_mmio_read(__readl, "l", unsigned int, "=r", )
15690+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
15691+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
15692
15693 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
15694 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
15695@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
15696 return ioremap_nocache(offset, size);
15697 }
15698
15699-extern void iounmap(volatile void __iomem *addr);
15700+extern void iounmap(const volatile void __iomem *addr);
15701
15702 extern void set_iounmap_nonlazy(void);
15703
15704@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
15705
15706 #include <linux/vmalloc.h>
15707
15708+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
15709+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
15710+{
15711+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15712+}
15713+
15714+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
15715+{
15716+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15717+}
15718+
15719 /*
15720 * Convert a virtual cached pointer to an uncached pointer
15721 */
15722diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
15723index bba3cf8..06bc8da 100644
15724--- a/arch/x86/include/asm/irqflags.h
15725+++ b/arch/x86/include/asm/irqflags.h
15726@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
15727 sti; \
15728 sysexit
15729
15730+#define GET_CR0_INTO_RDI mov %cr0, %rdi
15731+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
15732+#define GET_CR3_INTO_RDI mov %cr3, %rdi
15733+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
15734+
15735 #else
15736 #define INTERRUPT_RETURN iret
15737 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
15738diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
15739index 5a6d287..f815789 100644
15740--- a/arch/x86/include/asm/kprobes.h
15741+++ b/arch/x86/include/asm/kprobes.h
15742@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
15743 #define RELATIVEJUMP_SIZE 5
15744 #define RELATIVECALL_OPCODE 0xe8
15745 #define RELATIVE_ADDR_SIZE 4
15746-#define MAX_STACK_SIZE 64
15747-#define MIN_STACK_SIZE(ADDR) \
15748- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
15749- THREAD_SIZE - (unsigned long)(ADDR))) \
15750- ? (MAX_STACK_SIZE) \
15751- : (((unsigned long)current_thread_info()) + \
15752- THREAD_SIZE - (unsigned long)(ADDR)))
15753+#define MAX_STACK_SIZE 64UL
15754+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
15755
15756 #define flush_insn_slot(p) do { } while (0)
15757
15758diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
15759index 2d89e39..baee879 100644
15760--- a/arch/x86/include/asm/local.h
15761+++ b/arch/x86/include/asm/local.h
15762@@ -10,33 +10,97 @@ typedef struct {
15763 atomic_long_t a;
15764 } local_t;
15765
15766+typedef struct {
15767+ atomic_long_unchecked_t a;
15768+} local_unchecked_t;
15769+
15770 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
15771
15772 #define local_read(l) atomic_long_read(&(l)->a)
15773+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
15774 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
15775+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
15776
15777 static inline void local_inc(local_t *l)
15778 {
15779- asm volatile(_ASM_INC "%0"
15780+ asm volatile(_ASM_INC "%0\n"
15781+
15782+#ifdef CONFIG_PAX_REFCOUNT
15783+ "jno 0f\n"
15784+ _ASM_DEC "%0\n"
15785+ "int $4\n0:\n"
15786+ _ASM_EXTABLE(0b, 0b)
15787+#endif
15788+
15789+ : "+m" (l->a.counter));
15790+}
15791+
15792+static inline void local_inc_unchecked(local_unchecked_t *l)
15793+{
15794+ asm volatile(_ASM_INC "%0\n"
15795 : "+m" (l->a.counter));
15796 }
15797
15798 static inline void local_dec(local_t *l)
15799 {
15800- asm volatile(_ASM_DEC "%0"
15801+ asm volatile(_ASM_DEC "%0\n"
15802+
15803+#ifdef CONFIG_PAX_REFCOUNT
15804+ "jno 0f\n"
15805+ _ASM_INC "%0\n"
15806+ "int $4\n0:\n"
15807+ _ASM_EXTABLE(0b, 0b)
15808+#endif
15809+
15810+ : "+m" (l->a.counter));
15811+}
15812+
15813+static inline void local_dec_unchecked(local_unchecked_t *l)
15814+{
15815+ asm volatile(_ASM_DEC "%0\n"
15816 : "+m" (l->a.counter));
15817 }
15818
15819 static inline void local_add(long i, local_t *l)
15820 {
15821- asm volatile(_ASM_ADD "%1,%0"
15822+ asm volatile(_ASM_ADD "%1,%0\n"
15823+
15824+#ifdef CONFIG_PAX_REFCOUNT
15825+ "jno 0f\n"
15826+ _ASM_SUB "%1,%0\n"
15827+ "int $4\n0:\n"
15828+ _ASM_EXTABLE(0b, 0b)
15829+#endif
15830+
15831+ : "+m" (l->a.counter)
15832+ : "ir" (i));
15833+}
15834+
15835+static inline void local_add_unchecked(long i, local_unchecked_t *l)
15836+{
15837+ asm volatile(_ASM_ADD "%1,%0\n"
15838 : "+m" (l->a.counter)
15839 : "ir" (i));
15840 }
15841
15842 static inline void local_sub(long i, local_t *l)
15843 {
15844- asm volatile(_ASM_SUB "%1,%0"
15845+ asm volatile(_ASM_SUB "%1,%0\n"
15846+
15847+#ifdef CONFIG_PAX_REFCOUNT
15848+ "jno 0f\n"
15849+ _ASM_ADD "%1,%0\n"
15850+ "int $4\n0:\n"
15851+ _ASM_EXTABLE(0b, 0b)
15852+#endif
15853+
15854+ : "+m" (l->a.counter)
15855+ : "ir" (i));
15856+}
15857+
15858+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
15859+{
15860+ asm volatile(_ASM_SUB "%1,%0\n"
15861 : "+m" (l->a.counter)
15862 : "ir" (i));
15863 }
15864@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
15865 {
15866 unsigned char c;
15867
15868- asm volatile(_ASM_SUB "%2,%0; sete %1"
15869+ asm volatile(_ASM_SUB "%2,%0\n"
15870+
15871+#ifdef CONFIG_PAX_REFCOUNT
15872+ "jno 0f\n"
15873+ _ASM_ADD "%2,%0\n"
15874+ "int $4\n0:\n"
15875+ _ASM_EXTABLE(0b, 0b)
15876+#endif
15877+
15878+ "sete %1\n"
15879 : "+m" (l->a.counter), "=qm" (c)
15880 : "ir" (i) : "memory");
15881 return c;
15882@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
15883 {
15884 unsigned char c;
15885
15886- asm volatile(_ASM_DEC "%0; sete %1"
15887+ asm volatile(_ASM_DEC "%0\n"
15888+
15889+#ifdef CONFIG_PAX_REFCOUNT
15890+ "jno 0f\n"
15891+ _ASM_INC "%0\n"
15892+ "int $4\n0:\n"
15893+ _ASM_EXTABLE(0b, 0b)
15894+#endif
15895+
15896+ "sete %1\n"
15897 : "+m" (l->a.counter), "=qm" (c)
15898 : : "memory");
15899 return c != 0;
15900@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
15901 {
15902 unsigned char c;
15903
15904- asm volatile(_ASM_INC "%0; sete %1"
15905+ asm volatile(_ASM_INC "%0\n"
15906+
15907+#ifdef CONFIG_PAX_REFCOUNT
15908+ "jno 0f\n"
15909+ _ASM_DEC "%0\n"
15910+ "int $4\n0:\n"
15911+ _ASM_EXTABLE(0b, 0b)
15912+#endif
15913+
15914+ "sete %1\n"
15915 : "+m" (l->a.counter), "=qm" (c)
15916 : : "memory");
15917 return c != 0;
15918@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
15919 {
15920 unsigned char c;
15921
15922- asm volatile(_ASM_ADD "%2,%0; sets %1"
15923+ asm volatile(_ASM_ADD "%2,%0\n"
15924+
15925+#ifdef CONFIG_PAX_REFCOUNT
15926+ "jno 0f\n"
15927+ _ASM_SUB "%2,%0\n"
15928+ "int $4\n0:\n"
15929+ _ASM_EXTABLE(0b, 0b)
15930+#endif
15931+
15932+ "sets %1\n"
15933 : "+m" (l->a.counter), "=qm" (c)
15934 : "ir" (i) : "memory");
15935 return c;
15936@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
15937 static inline long local_add_return(long i, local_t *l)
15938 {
15939 long __i = i;
15940+ asm volatile(_ASM_XADD "%0, %1\n"
15941+
15942+#ifdef CONFIG_PAX_REFCOUNT
15943+ "jno 0f\n"
15944+ _ASM_MOV "%0,%1\n"
15945+ "int $4\n0:\n"
15946+ _ASM_EXTABLE(0b, 0b)
15947+#endif
15948+
15949+ : "+r" (i), "+m" (l->a.counter)
15950+ : : "memory");
15951+ return i + __i;
15952+}
15953+
15954+/**
15955+ * local_add_return_unchecked - add and return
15956+ * @i: integer value to add
15957+ * @l: pointer to type local_unchecked_t
15958+ *
15959+ * Atomically adds @i to @l and returns @i + @l
15960+ */
15961+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
15962+{
15963+ long __i = i;
15964 asm volatile(_ASM_XADD "%0, %1;"
15965 : "+r" (i), "+m" (l->a.counter)
15966 : : "memory");
15967@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
15968
15969 #define local_cmpxchg(l, o, n) \
15970 (cmpxchg_local(&((l)->a.counter), (o), (n)))
15971+#define local_cmpxchg_unchecked(l, o, n) \
15972+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
15973 /* Always has a lock prefix */
15974 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
15975
15976diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
15977new file mode 100644
15978index 0000000..2bfd3ba
15979--- /dev/null
15980+++ b/arch/x86/include/asm/mman.h
15981@@ -0,0 +1,15 @@
15982+#ifndef _X86_MMAN_H
15983+#define _X86_MMAN_H
15984+
15985+#include <uapi/asm/mman.h>
15986+
15987+#ifdef __KERNEL__
15988+#ifndef __ASSEMBLY__
15989+#ifdef CONFIG_X86_32
15990+#define arch_mmap_check i386_mmap_check
15991+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
15992+#endif
15993+#endif
15994+#endif
15995+
15996+#endif /* X86_MMAN_H */
15997diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
15998index 5f55e69..e20bfb1 100644
15999--- a/arch/x86/include/asm/mmu.h
16000+++ b/arch/x86/include/asm/mmu.h
16001@@ -9,7 +9,7 @@
16002 * we put the segment information here.
16003 */
16004 typedef struct {
16005- void *ldt;
16006+ struct desc_struct *ldt;
16007 int size;
16008
16009 #ifdef CONFIG_X86_64
16010@@ -18,7 +18,19 @@ typedef struct {
16011 #endif
16012
16013 struct mutex lock;
16014- void *vdso;
16015+ unsigned long vdso;
16016+
16017+#ifdef CONFIG_X86_32
16018+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16019+ unsigned long user_cs_base;
16020+ unsigned long user_cs_limit;
16021+
16022+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16023+ cpumask_t cpu_user_cs_mask;
16024+#endif
16025+
16026+#endif
16027+#endif
16028 } mm_context_t;
16029
16030 #ifdef CONFIG_SMP
16031diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16032index cdbf367..4c73c9e 100644
16033--- a/arch/x86/include/asm/mmu_context.h
16034+++ b/arch/x86/include/asm/mmu_context.h
16035@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16036
16037 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16038 {
16039+
16040+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16041+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
16042+ unsigned int i;
16043+ pgd_t *pgd;
16044+
16045+ pax_open_kernel();
16046+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
16047+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16048+ set_pgd_batched(pgd+i, native_make_pgd(0));
16049+ pax_close_kernel();
16050+ }
16051+#endif
16052+
16053 #ifdef CONFIG_SMP
16054 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16055 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16056@@ -34,16 +48,55 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16057 struct task_struct *tsk)
16058 {
16059 unsigned cpu = smp_processor_id();
16060+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16061+ int tlbstate = TLBSTATE_OK;
16062+#endif
16063
16064 if (likely(prev != next)) {
16065 #ifdef CONFIG_SMP
16066+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16067+ tlbstate = this_cpu_read(cpu_tlbstate.state);
16068+#endif
16069 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16070 this_cpu_write(cpu_tlbstate.active_mm, next);
16071 #endif
16072 cpumask_set_cpu(cpu, mm_cpumask(next));
16073
16074 /* Re-load page tables */
16075+#ifdef CONFIG_PAX_PER_CPU_PGD
16076+ pax_open_kernel();
16077+
16078+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16079+ if (static_cpu_has(X86_FEATURE_PCID))
16080+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16081+ else
16082+#endif
16083+
16084+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16085+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16086+ pax_close_kernel();
16087+ 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));
16088+
16089+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16090+ if (static_cpu_has(X86_FEATURE_PCID)) {
16091+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16092+ unsigned long descriptor[2];
16093+ descriptor[0] = PCID_USER;
16094+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16095+ } else {
16096+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16097+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16098+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16099+ else
16100+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16101+ }
16102+ } else
16103+#endif
16104+
16105+ load_cr3(get_cpu_pgd(cpu, kernel));
16106+#else
16107 load_cr3(next->pgd);
16108+#endif
16109
16110 /* stop flush ipis for the previous mm */
16111 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16112@@ -53,9 +106,63 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16113 */
16114 if (unlikely(prev->context.ldt != next->context.ldt))
16115 load_LDT_nolock(&next->context);
16116- }
16117+
16118+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16119+ if (!(__supported_pte_mask & _PAGE_NX)) {
16120+ smp_mb__before_clear_bit();
16121+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16122+ smp_mb__after_clear_bit();
16123+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16124+ }
16125+#endif
16126+
16127+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16128+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16129+ prev->context.user_cs_limit != next->context.user_cs_limit))
16130+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16131 #ifdef CONFIG_SMP
16132+ else if (unlikely(tlbstate != TLBSTATE_OK))
16133+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16134+#endif
16135+#endif
16136+
16137+ }
16138 else {
16139+
16140+#ifdef CONFIG_PAX_PER_CPU_PGD
16141+ pax_open_kernel();
16142+
16143+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16144+ if (static_cpu_has(X86_FEATURE_PCID))
16145+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16146+ else
16147+#endif
16148+
16149+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16150+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16151+ pax_close_kernel();
16152+ 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));
16153+
16154+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16155+ if (static_cpu_has(X86_FEATURE_PCID)) {
16156+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16157+ unsigned long descriptor[2];
16158+ descriptor[0] = PCID_USER;
16159+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16160+ } else {
16161+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16162+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16163+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16164+ else
16165+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16166+ }
16167+ } else
16168+#endif
16169+
16170+ load_cr3(get_cpu_pgd(cpu, kernel));
16171+#endif
16172+
16173+#ifdef CONFIG_SMP
16174 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16175 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
16176
16177@@ -64,11 +171,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16178 * tlb flush IPI delivery. We must reload CR3
16179 * to make sure to use no freed page tables.
16180 */
16181+
16182+#ifndef CONFIG_PAX_PER_CPU_PGD
16183 load_cr3(next->pgd);
16184+#endif
16185+
16186 load_LDT_nolock(&next->context);
16187+
16188+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
16189+ if (!(__supported_pte_mask & _PAGE_NX))
16190+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16191+#endif
16192+
16193+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16194+#ifdef CONFIG_PAX_PAGEEXEC
16195+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
16196+#endif
16197+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16198+#endif
16199+
16200 }
16201+#endif
16202 }
16203-#endif
16204 }
16205
16206 #define activate_mm(prev, next) \
16207diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
16208index e3b7819..b257c64 100644
16209--- a/arch/x86/include/asm/module.h
16210+++ b/arch/x86/include/asm/module.h
16211@@ -5,6 +5,7 @@
16212
16213 #ifdef CONFIG_X86_64
16214 /* X86_64 does not define MODULE_PROC_FAMILY */
16215+#define MODULE_PROC_FAMILY ""
16216 #elif defined CONFIG_M486
16217 #define MODULE_PROC_FAMILY "486 "
16218 #elif defined CONFIG_M586
16219@@ -57,8 +58,20 @@
16220 #error unknown processor family
16221 #endif
16222
16223-#ifdef CONFIG_X86_32
16224-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
16225+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
16226+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
16227+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
16228+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
16229+#else
16230+#define MODULE_PAX_KERNEXEC ""
16231 #endif
16232
16233+#ifdef CONFIG_PAX_MEMORY_UDEREF
16234+#define MODULE_PAX_UDEREF "UDEREF "
16235+#else
16236+#define MODULE_PAX_UDEREF ""
16237+#endif
16238+
16239+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16240+
16241 #endif /* _ASM_X86_MODULE_H */
16242diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16243index 86f9301..b365cda 100644
16244--- a/arch/x86/include/asm/nmi.h
16245+++ b/arch/x86/include/asm/nmi.h
16246@@ -40,11 +40,11 @@ struct nmiaction {
16247 nmi_handler_t handler;
16248 unsigned long flags;
16249 const char *name;
16250-};
16251+} __do_const;
16252
16253 #define register_nmi_handler(t, fn, fg, n, init...) \
16254 ({ \
16255- static struct nmiaction init fn##_na = { \
16256+ static const struct nmiaction init fn##_na = { \
16257 .handler = (fn), \
16258 .name = (n), \
16259 .flags = (fg), \
16260@@ -52,7 +52,7 @@ struct nmiaction {
16261 __register_nmi_handler((t), &fn##_na); \
16262 })
16263
16264-int __register_nmi_handler(unsigned int, struct nmiaction *);
16265+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16266
16267 void unregister_nmi_handler(unsigned int, const char *);
16268
16269diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16270index c878924..21f4889 100644
16271--- a/arch/x86/include/asm/page.h
16272+++ b/arch/x86/include/asm/page.h
16273@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16274 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16275
16276 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16277+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16278
16279 #define __boot_va(x) __va(x)
16280 #define __boot_pa(x) __pa(x)
16281diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16282index 0f1ddee..e2fc3d1 100644
16283--- a/arch/x86/include/asm/page_64.h
16284+++ b/arch/x86/include/asm/page_64.h
16285@@ -7,9 +7,9 @@
16286
16287 /* duplicated to the one in bootmem.h */
16288 extern unsigned long max_pfn;
16289-extern unsigned long phys_base;
16290+extern const unsigned long phys_base;
16291
16292-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16293+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16294 {
16295 unsigned long y = x - __START_KERNEL_map;
16296
16297diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16298index cfdc9ee..3f7b5d6 100644
16299--- a/arch/x86/include/asm/paravirt.h
16300+++ b/arch/x86/include/asm/paravirt.h
16301@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16302 return (pmd_t) { ret };
16303 }
16304
16305-static inline pmdval_t pmd_val(pmd_t pmd)
16306+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16307 {
16308 pmdval_t ret;
16309
16310@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16311 val);
16312 }
16313
16314+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16315+{
16316+ pgdval_t val = native_pgd_val(pgd);
16317+
16318+ if (sizeof(pgdval_t) > sizeof(long))
16319+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16320+ val, (u64)val >> 32);
16321+ else
16322+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16323+ val);
16324+}
16325+
16326 static inline void pgd_clear(pgd_t *pgdp)
16327 {
16328 set_pgd(pgdp, __pgd(0));
16329@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16330 pv_mmu_ops.set_fixmap(idx, phys, flags);
16331 }
16332
16333+#ifdef CONFIG_PAX_KERNEXEC
16334+static inline unsigned long pax_open_kernel(void)
16335+{
16336+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16337+}
16338+
16339+static inline unsigned long pax_close_kernel(void)
16340+{
16341+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16342+}
16343+#else
16344+static inline unsigned long pax_open_kernel(void) { return 0; }
16345+static inline unsigned long pax_close_kernel(void) { return 0; }
16346+#endif
16347+
16348 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16349
16350 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
16351@@ -926,7 +953,7 @@ extern void default_banner(void);
16352
16353 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16354 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16355-#define PARA_INDIRECT(addr) *%cs:addr
16356+#define PARA_INDIRECT(addr) *%ss:addr
16357 #endif
16358
16359 #define INTERRUPT_RETURN \
16360@@ -1001,6 +1028,21 @@ extern void default_banner(void);
16361 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16362 CLBR_NONE, \
16363 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16364+
16365+#define GET_CR0_INTO_RDI \
16366+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16367+ mov %rax,%rdi
16368+
16369+#define SET_RDI_INTO_CR0 \
16370+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16371+
16372+#define GET_CR3_INTO_RDI \
16373+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16374+ mov %rax,%rdi
16375+
16376+#define SET_RDI_INTO_CR3 \
16377+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16378+
16379 #endif /* CONFIG_X86_32 */
16380
16381 #endif /* __ASSEMBLY__ */
16382diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16383index 0db1fca..52310cc 100644
16384--- a/arch/x86/include/asm/paravirt_types.h
16385+++ b/arch/x86/include/asm/paravirt_types.h
16386@@ -84,7 +84,7 @@ struct pv_init_ops {
16387 */
16388 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16389 unsigned long addr, unsigned len);
16390-};
16391+} __no_const;
16392
16393
16394 struct pv_lazy_ops {
16395@@ -98,7 +98,7 @@ struct pv_time_ops {
16396 unsigned long long (*sched_clock)(void);
16397 unsigned long long (*steal_clock)(int cpu);
16398 unsigned long (*get_tsc_khz)(void);
16399-};
16400+} __no_const;
16401
16402 struct pv_cpu_ops {
16403 /* hooks for various privileged instructions */
16404@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16405
16406 void (*start_context_switch)(struct task_struct *prev);
16407 void (*end_context_switch)(struct task_struct *next);
16408-};
16409+} __no_const;
16410
16411 struct pv_irq_ops {
16412 /*
16413@@ -223,7 +223,7 @@ struct pv_apic_ops {
16414 unsigned long start_eip,
16415 unsigned long start_esp);
16416 #endif
16417-};
16418+} __no_const;
16419
16420 struct pv_mmu_ops {
16421 unsigned long (*read_cr2)(void);
16422@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16423 struct paravirt_callee_save make_pud;
16424
16425 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16426+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16427 #endif /* PAGETABLE_LEVELS == 4 */
16428 #endif /* PAGETABLE_LEVELS >= 3 */
16429
16430@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16431 an mfn. We can tell which is which from the index. */
16432 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16433 phys_addr_t phys, pgprot_t flags);
16434+
16435+#ifdef CONFIG_PAX_KERNEXEC
16436+ unsigned long (*pax_open_kernel)(void);
16437+ unsigned long (*pax_close_kernel)(void);
16438+#endif
16439+
16440 };
16441
16442 struct arch_spinlock;
16443@@ -334,7 +341,7 @@ struct pv_lock_ops {
16444 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
16445 int (*spin_trylock)(struct arch_spinlock *lock);
16446 void (*spin_unlock)(struct arch_spinlock *lock);
16447-};
16448+} __no_const;
16449
16450 /* This contains all the paravirt structures: we get a convenient
16451 * number for each function using the offset which we use to indicate
16452diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16453index b4389a4..7024269 100644
16454--- a/arch/x86/include/asm/pgalloc.h
16455+++ b/arch/x86/include/asm/pgalloc.h
16456@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16457 pmd_t *pmd, pte_t *pte)
16458 {
16459 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16460+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16461+}
16462+
16463+static inline void pmd_populate_user(struct mm_struct *mm,
16464+ pmd_t *pmd, pte_t *pte)
16465+{
16466+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16467 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16468 }
16469
16470@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16471
16472 #ifdef CONFIG_X86_PAE
16473 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16474+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16475+{
16476+ pud_populate(mm, pudp, pmd);
16477+}
16478 #else /* !CONFIG_X86_PAE */
16479 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16480 {
16481 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16482 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16483 }
16484+
16485+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16486+{
16487+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16488+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16489+}
16490 #endif /* CONFIG_X86_PAE */
16491
16492 #if PAGETABLE_LEVELS > 3
16493@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16494 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16495 }
16496
16497+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16498+{
16499+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16500+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16501+}
16502+
16503 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16504 {
16505 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16506diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16507index f2b489c..4f7e2e5 100644
16508--- a/arch/x86/include/asm/pgtable-2level.h
16509+++ b/arch/x86/include/asm/pgtable-2level.h
16510@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16511
16512 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16513 {
16514+ pax_open_kernel();
16515 *pmdp = pmd;
16516+ pax_close_kernel();
16517 }
16518
16519 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16520diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16521index 4cc9f2b..5fd9226 100644
16522--- a/arch/x86/include/asm/pgtable-3level.h
16523+++ b/arch/x86/include/asm/pgtable-3level.h
16524@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16525
16526 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16527 {
16528+ pax_open_kernel();
16529 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16530+ pax_close_kernel();
16531 }
16532
16533 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16534 {
16535+ pax_open_kernel();
16536 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16537+ pax_close_kernel();
16538 }
16539
16540 /*
16541diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16542index 1e67223..92a9585 100644
16543--- a/arch/x86/include/asm/pgtable.h
16544+++ b/arch/x86/include/asm/pgtable.h
16545@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16546
16547 #ifndef __PAGETABLE_PUD_FOLDED
16548 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
16549+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
16550 #define pgd_clear(pgd) native_pgd_clear(pgd)
16551 #endif
16552
16553@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16554
16555 #define arch_end_context_switch(prev) do {} while(0)
16556
16557+#define pax_open_kernel() native_pax_open_kernel()
16558+#define pax_close_kernel() native_pax_close_kernel()
16559 #endif /* CONFIG_PARAVIRT */
16560
16561+#define __HAVE_ARCH_PAX_OPEN_KERNEL
16562+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
16563+
16564+#ifdef CONFIG_PAX_KERNEXEC
16565+static inline unsigned long native_pax_open_kernel(void)
16566+{
16567+ unsigned long cr0;
16568+
16569+ preempt_disable();
16570+ barrier();
16571+ cr0 = read_cr0() ^ X86_CR0_WP;
16572+ BUG_ON(cr0 & X86_CR0_WP);
16573+ write_cr0(cr0);
16574+ return cr0 ^ X86_CR0_WP;
16575+}
16576+
16577+static inline unsigned long native_pax_close_kernel(void)
16578+{
16579+ unsigned long cr0;
16580+
16581+ cr0 = read_cr0() ^ X86_CR0_WP;
16582+ BUG_ON(!(cr0 & X86_CR0_WP));
16583+ write_cr0(cr0);
16584+ barrier();
16585+ preempt_enable_no_resched();
16586+ return cr0 ^ X86_CR0_WP;
16587+}
16588+#else
16589+static inline unsigned long native_pax_open_kernel(void) { return 0; }
16590+static inline unsigned long native_pax_close_kernel(void) { return 0; }
16591+#endif
16592+
16593 /*
16594 * The following only work if pte_present() is true.
16595 * Undefined behaviour if not..
16596 */
16597+static inline int pte_user(pte_t pte)
16598+{
16599+ return pte_val(pte) & _PAGE_USER;
16600+}
16601+
16602 static inline int pte_dirty(pte_t pte)
16603 {
16604 return pte_flags(pte) & _PAGE_DIRTY;
16605@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
16606 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
16607 }
16608
16609+static inline unsigned long pgd_pfn(pgd_t pgd)
16610+{
16611+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
16612+}
16613+
16614 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
16615
16616 static inline int pmd_large(pmd_t pte)
16617@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
16618 return pte_clear_flags(pte, _PAGE_RW);
16619 }
16620
16621+static inline pte_t pte_mkread(pte_t pte)
16622+{
16623+ return __pte(pte_val(pte) | _PAGE_USER);
16624+}
16625+
16626 static inline pte_t pte_mkexec(pte_t pte)
16627 {
16628- return pte_clear_flags(pte, _PAGE_NX);
16629+#ifdef CONFIG_X86_PAE
16630+ if (__supported_pte_mask & _PAGE_NX)
16631+ return pte_clear_flags(pte, _PAGE_NX);
16632+ else
16633+#endif
16634+ return pte_set_flags(pte, _PAGE_USER);
16635+}
16636+
16637+static inline pte_t pte_exprotect(pte_t pte)
16638+{
16639+#ifdef CONFIG_X86_PAE
16640+ if (__supported_pte_mask & _PAGE_NX)
16641+ return pte_set_flags(pte, _PAGE_NX);
16642+ else
16643+#endif
16644+ return pte_clear_flags(pte, _PAGE_USER);
16645 }
16646
16647 static inline pte_t pte_mkdirty(pte_t pte)
16648@@ -394,6 +459,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
16649 #endif
16650
16651 #ifndef __ASSEMBLY__
16652+
16653+#ifdef CONFIG_PAX_PER_CPU_PGD
16654+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
16655+enum cpu_pgd_type {kernel = 0, user = 1};
16656+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
16657+{
16658+ return cpu_pgd[cpu][type];
16659+}
16660+#endif
16661+
16662 #include <linux/mm_types.h>
16663 #include <linux/log2.h>
16664
16665@@ -529,7 +604,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
16666 * Currently stuck as a macro due to indirect forward reference to
16667 * linux/mmzone.h's __section_mem_map_addr() definition:
16668 */
16669-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
16670+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
16671
16672 /* Find an entry in the second-level page table.. */
16673 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
16674@@ -569,7 +644,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
16675 * Currently stuck as a macro due to indirect forward reference to
16676 * linux/mmzone.h's __section_mem_map_addr() definition:
16677 */
16678-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
16679+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
16680
16681 /* to find an entry in a page-table-directory. */
16682 static inline unsigned long pud_index(unsigned long address)
16683@@ -584,7 +659,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
16684
16685 static inline int pgd_bad(pgd_t pgd)
16686 {
16687- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
16688+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
16689 }
16690
16691 static inline int pgd_none(pgd_t pgd)
16692@@ -607,7 +682,12 @@ static inline int pgd_none(pgd_t pgd)
16693 * pgd_offset() returns a (pgd_t *)
16694 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
16695 */
16696-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
16697+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
16698+
16699+#ifdef CONFIG_PAX_PER_CPU_PGD
16700+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
16701+#endif
16702+
16703 /*
16704 * a shortcut which implies the use of the kernel's pgd, instead
16705 * of a process's
16706@@ -618,6 +698,23 @@ static inline int pgd_none(pgd_t pgd)
16707 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
16708 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
16709
16710+#ifdef CONFIG_X86_32
16711+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
16712+#else
16713+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
16714+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
16715+
16716+#ifdef CONFIG_PAX_MEMORY_UDEREF
16717+#ifdef __ASSEMBLY__
16718+#define pax_user_shadow_base pax_user_shadow_base(%rip)
16719+#else
16720+extern unsigned long pax_user_shadow_base;
16721+extern pgdval_t clone_pgd_mask;
16722+#endif
16723+#endif
16724+
16725+#endif
16726+
16727 #ifndef __ASSEMBLY__
16728
16729 extern int direct_gbpages;
16730@@ -784,11 +881,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
16731 * dst and src can be on the same page, but the range must not overlap,
16732 * and must not cross a page boundary.
16733 */
16734-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
16735+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
16736 {
16737- memcpy(dst, src, count * sizeof(pgd_t));
16738+ pax_open_kernel();
16739+ while (count--)
16740+ *dst++ = *src++;
16741+ pax_close_kernel();
16742 }
16743
16744+#ifdef CONFIG_PAX_PER_CPU_PGD
16745+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
16746+#endif
16747+
16748+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16749+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
16750+#else
16751+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
16752+#endif
16753+
16754 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
16755 static inline int page_level_shift(enum pg_level level)
16756 {
16757diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
16758index 9ee3221..b979c6b 100644
16759--- a/arch/x86/include/asm/pgtable_32.h
16760+++ b/arch/x86/include/asm/pgtable_32.h
16761@@ -25,9 +25,6 @@
16762 struct mm_struct;
16763 struct vm_area_struct;
16764
16765-extern pgd_t swapper_pg_dir[1024];
16766-extern pgd_t initial_page_table[1024];
16767-
16768 static inline void pgtable_cache_init(void) { }
16769 static inline void check_pgt_cache(void) { }
16770 void paging_init(void);
16771@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16772 # include <asm/pgtable-2level.h>
16773 #endif
16774
16775+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
16776+extern pgd_t initial_page_table[PTRS_PER_PGD];
16777+#ifdef CONFIG_X86_PAE
16778+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
16779+#endif
16780+
16781 #if defined(CONFIG_HIGHPTE)
16782 #define pte_offset_map(dir, address) \
16783 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
16784@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16785 /* Clear a kernel PTE and flush it from the TLB */
16786 #define kpte_clear_flush(ptep, vaddr) \
16787 do { \
16788+ pax_open_kernel(); \
16789 pte_clear(&init_mm, (vaddr), (ptep)); \
16790+ pax_close_kernel(); \
16791 __flush_tlb_one((vaddr)); \
16792 } while (0)
16793
16794 #endif /* !__ASSEMBLY__ */
16795
16796+#define HAVE_ARCH_UNMAPPED_AREA
16797+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
16798+
16799 /*
16800 * kern_addr_valid() is (1) for FLATMEM and (0) for
16801 * SPARSEMEM and DISCONTIGMEM
16802diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
16803index ed5903b..c7fe163 100644
16804--- a/arch/x86/include/asm/pgtable_32_types.h
16805+++ b/arch/x86/include/asm/pgtable_32_types.h
16806@@ -8,7 +8,7 @@
16807 */
16808 #ifdef CONFIG_X86_PAE
16809 # include <asm/pgtable-3level_types.h>
16810-# define PMD_SIZE (1UL << PMD_SHIFT)
16811+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
16812 # define PMD_MASK (~(PMD_SIZE - 1))
16813 #else
16814 # include <asm/pgtable-2level_types.h>
16815@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
16816 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
16817 #endif
16818
16819+#ifdef CONFIG_PAX_KERNEXEC
16820+#ifndef __ASSEMBLY__
16821+extern unsigned char MODULES_EXEC_VADDR[];
16822+extern unsigned char MODULES_EXEC_END[];
16823+#endif
16824+#include <asm/boot.h>
16825+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
16826+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
16827+#else
16828+#define ktla_ktva(addr) (addr)
16829+#define ktva_ktla(addr) (addr)
16830+#endif
16831+
16832 #define MODULES_VADDR VMALLOC_START
16833 #define MODULES_END VMALLOC_END
16834 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
16835diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
16836index e22c1db..23a625a 100644
16837--- a/arch/x86/include/asm/pgtable_64.h
16838+++ b/arch/x86/include/asm/pgtable_64.h
16839@@ -16,10 +16,14 @@
16840
16841 extern pud_t level3_kernel_pgt[512];
16842 extern pud_t level3_ident_pgt[512];
16843+extern pud_t level3_vmalloc_start_pgt[512];
16844+extern pud_t level3_vmalloc_end_pgt[512];
16845+extern pud_t level3_vmemmap_pgt[512];
16846+extern pud_t level2_vmemmap_pgt[512];
16847 extern pmd_t level2_kernel_pgt[512];
16848 extern pmd_t level2_fixmap_pgt[512];
16849-extern pmd_t level2_ident_pgt[512];
16850-extern pgd_t init_level4_pgt[];
16851+extern pmd_t level2_ident_pgt[512*2];
16852+extern pgd_t init_level4_pgt[512];
16853
16854 #define swapper_pg_dir init_level4_pgt
16855
16856@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16857
16858 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16859 {
16860+ pax_open_kernel();
16861 *pmdp = pmd;
16862+ pax_close_kernel();
16863 }
16864
16865 static inline void native_pmd_clear(pmd_t *pmd)
16866@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
16867
16868 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16869 {
16870+ pax_open_kernel();
16871 *pudp = pud;
16872+ pax_close_kernel();
16873 }
16874
16875 static inline void native_pud_clear(pud_t *pud)
16876@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
16877
16878 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
16879 {
16880+ pax_open_kernel();
16881+ *pgdp = pgd;
16882+ pax_close_kernel();
16883+}
16884+
16885+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16886+{
16887 *pgdp = pgd;
16888 }
16889
16890diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
16891index 2d88344..4679fc3 100644
16892--- a/arch/x86/include/asm/pgtable_64_types.h
16893+++ b/arch/x86/include/asm/pgtable_64_types.h
16894@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
16895 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
16896 #define MODULES_END _AC(0xffffffffff000000, UL)
16897 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
16898+#define MODULES_EXEC_VADDR MODULES_VADDR
16899+#define MODULES_EXEC_END MODULES_END
16900+
16901+#define ktla_ktva(addr) (addr)
16902+#define ktva_ktla(addr) (addr)
16903
16904 #define EARLY_DYNAMIC_PAGE_TABLES 64
16905
16906diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
16907index e642300..0ef8f31 100644
16908--- a/arch/x86/include/asm/pgtable_types.h
16909+++ b/arch/x86/include/asm/pgtable_types.h
16910@@ -16,13 +16,12 @@
16911 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
16912 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
16913 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
16914-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
16915+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
16916 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
16917 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
16918 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
16919-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
16920-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
16921-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
16922+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
16923+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
16924 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
16925
16926 /* If _PAGE_BIT_PRESENT is clear, we use these: */
16927@@ -40,7 +39,6 @@
16928 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
16929 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
16930 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
16931-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
16932 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
16933 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
16934 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
16935@@ -57,8 +55,10 @@
16936
16937 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
16938 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
16939-#else
16940+#elif defined(CONFIG_KMEMCHECK)
16941 #define _PAGE_NX (_AT(pteval_t, 0))
16942+#else
16943+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
16944 #endif
16945
16946 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
16947@@ -116,6 +116,9 @@
16948 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
16949 _PAGE_ACCESSED)
16950
16951+#define PAGE_READONLY_NOEXEC PAGE_READONLY
16952+#define PAGE_SHARED_NOEXEC PAGE_SHARED
16953+
16954 #define __PAGE_KERNEL_EXEC \
16955 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
16956 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
16957@@ -126,7 +129,7 @@
16958 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
16959 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
16960 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
16961-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
16962+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
16963 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
16964 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
16965 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
16966@@ -188,8 +191,8 @@
16967 * bits are combined, this will alow user to access the high address mapped
16968 * VDSO in the presence of CONFIG_COMPAT_VDSO
16969 */
16970-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
16971-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
16972+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16973+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16974 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
16975 #endif
16976
16977@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
16978 {
16979 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
16980 }
16981+#endif
16982
16983+#if PAGETABLE_LEVELS == 3
16984+#include <asm-generic/pgtable-nopud.h>
16985+#endif
16986+
16987+#if PAGETABLE_LEVELS == 2
16988+#include <asm-generic/pgtable-nopmd.h>
16989+#endif
16990+
16991+#ifndef __ASSEMBLY__
16992 #if PAGETABLE_LEVELS > 3
16993 typedef struct { pudval_t pud; } pud_t;
16994
16995@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
16996 return pud.pud;
16997 }
16998 #else
16999-#include <asm-generic/pgtable-nopud.h>
17000-
17001 static inline pudval_t native_pud_val(pud_t pud)
17002 {
17003 return native_pgd_val(pud.pgd);
17004@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17005 return pmd.pmd;
17006 }
17007 #else
17008-#include <asm-generic/pgtable-nopmd.h>
17009-
17010 static inline pmdval_t native_pmd_val(pmd_t pmd)
17011 {
17012 return native_pgd_val(pmd.pud.pgd);
17013@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
17014
17015 extern pteval_t __supported_pte_mask;
17016 extern void set_nx(void);
17017-extern int nx_enabled;
17018
17019 #define pgprot_writecombine pgprot_writecombine
17020 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17021diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17022index 22224b3..b3a2f90 100644
17023--- a/arch/x86/include/asm/processor.h
17024+++ b/arch/x86/include/asm/processor.h
17025@@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17026 : "memory");
17027 }
17028
17029+/* invpcid (%rdx),%rax */
17030+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17031+
17032+#define INVPCID_SINGLE_ADDRESS 0UL
17033+#define INVPCID_SINGLE_CONTEXT 1UL
17034+#define INVPCID_ALL_GLOBAL 2UL
17035+#define INVPCID_ALL_MONGLOBAL 3UL
17036+
17037+#define PCID_KERNEL 0UL
17038+#define PCID_USER 1UL
17039+#define PCID_NOFLUSH (1UL << 63)
17040+
17041 static inline void load_cr3(pgd_t *pgdir)
17042 {
17043- write_cr3(__pa(pgdir));
17044+ write_cr3(__pa(pgdir) | PCID_KERNEL);
17045 }
17046
17047 #ifdef CONFIG_X86_32
17048@@ -282,7 +294,7 @@ struct tss_struct {
17049
17050 } ____cacheline_aligned;
17051
17052-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17053+extern struct tss_struct init_tss[NR_CPUS];
17054
17055 /*
17056 * Save the original ist values for checking stack pointers during debugging
17057@@ -452,6 +464,7 @@ struct thread_struct {
17058 unsigned short ds;
17059 unsigned short fsindex;
17060 unsigned short gsindex;
17061+ unsigned short ss;
17062 #endif
17063 #ifdef CONFIG_X86_32
17064 unsigned long ip;
17065@@ -552,29 +565,8 @@ static inline void load_sp0(struct tss_struct *tss,
17066 extern unsigned long mmu_cr4_features;
17067 extern u32 *trampoline_cr4_features;
17068
17069-static inline void set_in_cr4(unsigned long mask)
17070-{
17071- unsigned long cr4;
17072-
17073- mmu_cr4_features |= mask;
17074- if (trampoline_cr4_features)
17075- *trampoline_cr4_features = mmu_cr4_features;
17076- cr4 = read_cr4();
17077- cr4 |= mask;
17078- write_cr4(cr4);
17079-}
17080-
17081-static inline void clear_in_cr4(unsigned long mask)
17082-{
17083- unsigned long cr4;
17084-
17085- mmu_cr4_features &= ~mask;
17086- if (trampoline_cr4_features)
17087- *trampoline_cr4_features = mmu_cr4_features;
17088- cr4 = read_cr4();
17089- cr4 &= ~mask;
17090- write_cr4(cr4);
17091-}
17092+extern void set_in_cr4(unsigned long mask);
17093+extern void clear_in_cr4(unsigned long mask);
17094
17095 typedef struct {
17096 unsigned long seg;
17097@@ -823,11 +815,18 @@ static inline void spin_lock_prefetch(const void *x)
17098 */
17099 #define TASK_SIZE PAGE_OFFSET
17100 #define TASK_SIZE_MAX TASK_SIZE
17101+
17102+#ifdef CONFIG_PAX_SEGMEXEC
17103+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
17104+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
17105+#else
17106 #define STACK_TOP TASK_SIZE
17107-#define STACK_TOP_MAX STACK_TOP
17108+#endif
17109+
17110+#define STACK_TOP_MAX TASK_SIZE
17111
17112 #define INIT_THREAD { \
17113- .sp0 = sizeof(init_stack) + (long)&init_stack, \
17114+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17115 .vm86_info = NULL, \
17116 .sysenter_cs = __KERNEL_CS, \
17117 .io_bitmap_ptr = NULL, \
17118@@ -841,7 +840,7 @@ static inline void spin_lock_prefetch(const void *x)
17119 */
17120 #define INIT_TSS { \
17121 .x86_tss = { \
17122- .sp0 = sizeof(init_stack) + (long)&init_stack, \
17123+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17124 .ss0 = __KERNEL_DS, \
17125 .ss1 = __KERNEL_CS, \
17126 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
17127@@ -852,11 +851,7 @@ static inline void spin_lock_prefetch(const void *x)
17128 extern unsigned long thread_saved_pc(struct task_struct *tsk);
17129
17130 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
17131-#define KSTK_TOP(info) \
17132-({ \
17133- unsigned long *__ptr = (unsigned long *)(info); \
17134- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
17135-})
17136+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
17137
17138 /*
17139 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
17140@@ -871,7 +866,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17141 #define task_pt_regs(task) \
17142 ({ \
17143 struct pt_regs *__regs__; \
17144- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
17145+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
17146 __regs__ - 1; \
17147 })
17148
17149@@ -881,13 +876,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17150 /*
17151 * User space process size. 47bits minus one guard page.
17152 */
17153-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
17154+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
17155
17156 /* This decides where the kernel will search for a free chunk of vm
17157 * space during mmap's.
17158 */
17159 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
17160- 0xc0000000 : 0xFFFFe000)
17161+ 0xc0000000 : 0xFFFFf000)
17162
17163 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
17164 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
17165@@ -898,11 +893,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17166 #define STACK_TOP_MAX TASK_SIZE_MAX
17167
17168 #define INIT_THREAD { \
17169- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17170+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17171 }
17172
17173 #define INIT_TSS { \
17174- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17175+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17176 }
17177
17178 /*
17179@@ -930,6 +925,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
17180 */
17181 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
17182
17183+#ifdef CONFIG_PAX_SEGMEXEC
17184+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
17185+#endif
17186+
17187 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
17188
17189 /* Get/set a process' ability to use the timestamp counter instruction */
17190@@ -942,7 +941,8 @@ extern int set_tsc_mode(unsigned int val);
17191 extern u16 amd_get_nb_id(int cpu);
17192
17193 struct aperfmperf {
17194- u64 aperf, mperf;
17195+ u64 aperf __intentional_overflow(0);
17196+ u64 mperf __intentional_overflow(0);
17197 };
17198
17199 static inline void get_aperfmperf(struct aperfmperf *am)
17200@@ -970,7 +970,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
17201 return ratio;
17202 }
17203
17204-extern unsigned long arch_align_stack(unsigned long sp);
17205+#define arch_align_stack(x) ((x) & ~0xfUL)
17206 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
17207
17208 void default_idle(void);
17209@@ -980,6 +980,6 @@ bool xen_set_default_idle(void);
17210 #define xen_set_default_idle 0
17211 #endif
17212
17213-void stop_this_cpu(void *dummy);
17214+void stop_this_cpu(void *dummy) __noreturn;
17215
17216 #endif /* _ASM_X86_PROCESSOR_H */
17217diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
17218index 942a086..6c26446 100644
17219--- a/arch/x86/include/asm/ptrace.h
17220+++ b/arch/x86/include/asm/ptrace.h
17221@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
17222 }
17223
17224 /*
17225- * user_mode_vm(regs) determines whether a register set came from user mode.
17226+ * user_mode(regs) determines whether a register set came from user mode.
17227 * This is true if V8086 mode was enabled OR if the register set was from
17228 * protected mode with RPL-3 CS value. This tricky test checks that with
17229 * one comparison. Many places in the kernel can bypass this full check
17230- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
17231+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
17232+ * be used.
17233 */
17234-static inline int user_mode(struct pt_regs *regs)
17235+static inline int user_mode_novm(struct pt_regs *regs)
17236 {
17237 #ifdef CONFIG_X86_32
17238 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17239 #else
17240- return !!(regs->cs & 3);
17241+ return !!(regs->cs & SEGMENT_RPL_MASK);
17242 #endif
17243 }
17244
17245-static inline int user_mode_vm(struct pt_regs *regs)
17246+static inline int user_mode(struct pt_regs *regs)
17247 {
17248 #ifdef CONFIG_X86_32
17249 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17250 USER_RPL;
17251 #else
17252- return user_mode(regs);
17253+ return user_mode_novm(regs);
17254 #endif
17255 }
17256
17257@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17258 #ifdef CONFIG_X86_64
17259 static inline bool user_64bit_mode(struct pt_regs *regs)
17260 {
17261+ unsigned long cs = regs->cs & 0xffff;
17262 #ifndef CONFIG_PARAVIRT
17263 /*
17264 * On non-paravirt systems, this is the only long mode CPL 3
17265 * selector. We do not allow long mode selectors in the LDT.
17266 */
17267- return regs->cs == __USER_CS;
17268+ return cs == __USER_CS;
17269 #else
17270 /* Headers are too twisted for this to go in paravirt.h. */
17271- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17272+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17273 #endif
17274 }
17275
17276@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17277 * Traps from the kernel do not save sp and ss.
17278 * Use the helper function to retrieve sp.
17279 */
17280- if (offset == offsetof(struct pt_regs, sp) &&
17281- regs->cs == __KERNEL_CS)
17282- return kernel_stack_pointer(regs);
17283+ if (offset == offsetof(struct pt_regs, sp)) {
17284+ unsigned long cs = regs->cs & 0xffff;
17285+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17286+ return kernel_stack_pointer(regs);
17287+ }
17288 #endif
17289 return *(unsigned long *)((unsigned long)regs + offset);
17290 }
17291diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17292index 9c6b890..5305f53 100644
17293--- a/arch/x86/include/asm/realmode.h
17294+++ b/arch/x86/include/asm/realmode.h
17295@@ -22,16 +22,14 @@ struct real_mode_header {
17296 #endif
17297 /* APM/BIOS reboot */
17298 u32 machine_real_restart_asm;
17299-#ifdef CONFIG_X86_64
17300 u32 machine_real_restart_seg;
17301-#endif
17302 };
17303
17304 /* This must match data at trampoline_32/64.S */
17305 struct trampoline_header {
17306 #ifdef CONFIG_X86_32
17307 u32 start;
17308- u16 gdt_pad;
17309+ u16 boot_cs;
17310 u16 gdt_limit;
17311 u32 gdt_base;
17312 #else
17313diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17314index a82c4f1..ac45053 100644
17315--- a/arch/x86/include/asm/reboot.h
17316+++ b/arch/x86/include/asm/reboot.h
17317@@ -6,13 +6,13 @@
17318 struct pt_regs;
17319
17320 struct machine_ops {
17321- void (*restart)(char *cmd);
17322- void (*halt)(void);
17323- void (*power_off)(void);
17324+ void (* __noreturn restart)(char *cmd);
17325+ void (* __noreturn halt)(void);
17326+ void (* __noreturn power_off)(void);
17327 void (*shutdown)(void);
17328 void (*crash_shutdown)(struct pt_regs *);
17329- void (*emergency_restart)(void);
17330-};
17331+ void (* __noreturn emergency_restart)(void);
17332+} __no_const;
17333
17334 extern struct machine_ops machine_ops;
17335
17336diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17337index cad82c9..2e5c5c1 100644
17338--- a/arch/x86/include/asm/rwsem.h
17339+++ b/arch/x86/include/asm/rwsem.h
17340@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17341 {
17342 asm volatile("# beginning down_read\n\t"
17343 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17344+
17345+#ifdef CONFIG_PAX_REFCOUNT
17346+ "jno 0f\n"
17347+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17348+ "int $4\n0:\n"
17349+ _ASM_EXTABLE(0b, 0b)
17350+#endif
17351+
17352 /* adds 0x00000001 */
17353 " jns 1f\n"
17354 " call call_rwsem_down_read_failed\n"
17355@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17356 "1:\n\t"
17357 " mov %1,%2\n\t"
17358 " add %3,%2\n\t"
17359+
17360+#ifdef CONFIG_PAX_REFCOUNT
17361+ "jno 0f\n"
17362+ "sub %3,%2\n"
17363+ "int $4\n0:\n"
17364+ _ASM_EXTABLE(0b, 0b)
17365+#endif
17366+
17367 " jle 2f\n\t"
17368 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17369 " jnz 1b\n\t"
17370@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17371 long tmp;
17372 asm volatile("# beginning down_write\n\t"
17373 LOCK_PREFIX " xadd %1,(%2)\n\t"
17374+
17375+#ifdef CONFIG_PAX_REFCOUNT
17376+ "jno 0f\n"
17377+ "mov %1,(%2)\n"
17378+ "int $4\n0:\n"
17379+ _ASM_EXTABLE(0b, 0b)
17380+#endif
17381+
17382 /* adds 0xffff0001, returns the old value */
17383 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17384 /* was the active mask 0 before? */
17385@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17386 long tmp;
17387 asm volatile("# beginning __up_read\n\t"
17388 LOCK_PREFIX " xadd %1,(%2)\n\t"
17389+
17390+#ifdef CONFIG_PAX_REFCOUNT
17391+ "jno 0f\n"
17392+ "mov %1,(%2)\n"
17393+ "int $4\n0:\n"
17394+ _ASM_EXTABLE(0b, 0b)
17395+#endif
17396+
17397 /* subtracts 1, returns the old value */
17398 " jns 1f\n\t"
17399 " call call_rwsem_wake\n" /* expects old value in %edx */
17400@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17401 long tmp;
17402 asm volatile("# beginning __up_write\n\t"
17403 LOCK_PREFIX " xadd %1,(%2)\n\t"
17404+
17405+#ifdef CONFIG_PAX_REFCOUNT
17406+ "jno 0f\n"
17407+ "mov %1,(%2)\n"
17408+ "int $4\n0:\n"
17409+ _ASM_EXTABLE(0b, 0b)
17410+#endif
17411+
17412 /* subtracts 0xffff0001, returns the old value */
17413 " jns 1f\n\t"
17414 " call call_rwsem_wake\n" /* expects old value in %edx */
17415@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17416 {
17417 asm volatile("# beginning __downgrade_write\n\t"
17418 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17419+
17420+#ifdef CONFIG_PAX_REFCOUNT
17421+ "jno 0f\n"
17422+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17423+ "int $4\n0:\n"
17424+ _ASM_EXTABLE(0b, 0b)
17425+#endif
17426+
17427 /*
17428 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17429 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17430@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17431 */
17432 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17433 {
17434- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17435+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17436+
17437+#ifdef CONFIG_PAX_REFCOUNT
17438+ "jno 0f\n"
17439+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17440+ "int $4\n0:\n"
17441+ _ASM_EXTABLE(0b, 0b)
17442+#endif
17443+
17444 : "+m" (sem->count)
17445 : "er" (delta));
17446 }
17447@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17448 */
17449 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17450 {
17451- return delta + xadd(&sem->count, delta);
17452+ return delta + xadd_check_overflow(&sem->count, delta);
17453 }
17454
17455 #endif /* __KERNEL__ */
17456diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17457index c48a950..bc40804 100644
17458--- a/arch/x86/include/asm/segment.h
17459+++ b/arch/x86/include/asm/segment.h
17460@@ -64,10 +64,15 @@
17461 * 26 - ESPFIX small SS
17462 * 27 - per-cpu [ offset to per-cpu data area ]
17463 * 28 - stack_canary-20 [ for stack protector ]
17464- * 29 - unused
17465- * 30 - unused
17466+ * 29 - PCI BIOS CS
17467+ * 30 - PCI BIOS DS
17468 * 31 - TSS for double fault handler
17469 */
17470+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17471+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17472+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17473+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17474+
17475 #define GDT_ENTRY_TLS_MIN 6
17476 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17477
17478@@ -79,6 +84,8 @@
17479
17480 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17481
17482+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17483+
17484 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17485
17486 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17487@@ -104,6 +111,12 @@
17488 #define __KERNEL_STACK_CANARY 0
17489 #endif
17490
17491+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17492+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17493+
17494+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17495+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17496+
17497 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17498
17499 /*
17500@@ -141,7 +154,7 @@
17501 */
17502
17503 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17504-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17505+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17506
17507
17508 #else
17509@@ -165,6 +178,8 @@
17510 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17511 #define __USER32_DS __USER_DS
17512
17513+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17514+
17515 #define GDT_ENTRY_TSS 8 /* needs two entries */
17516 #define GDT_ENTRY_LDT 10 /* needs two entries */
17517 #define GDT_ENTRY_TLS_MIN 12
17518@@ -173,6 +188,8 @@
17519 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17520 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17521
17522+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17523+
17524 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17525 #define FS_TLS 0
17526 #define GS_TLS 1
17527@@ -180,12 +197,14 @@
17528 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17529 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17530
17531-#define GDT_ENTRIES 16
17532+#define GDT_ENTRIES 17
17533
17534 #endif
17535
17536 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17537+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17538 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17539+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17540 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17541 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17542 #ifndef CONFIG_PARAVIRT
17543@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17544 {
17545 unsigned long __limit;
17546 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17547- return __limit + 1;
17548+ return __limit;
17549 }
17550
17551 #endif /* !__ASSEMBLY__ */
17552diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
17553index 8d3120f..352b440 100644
17554--- a/arch/x86/include/asm/smap.h
17555+++ b/arch/x86/include/asm/smap.h
17556@@ -25,11 +25,40 @@
17557
17558 #include <asm/alternative-asm.h>
17559
17560+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17561+#define ASM_PAX_OPEN_USERLAND \
17562+ 661: jmp 663f; \
17563+ .pushsection .altinstr_replacement, "a" ; \
17564+ 662: pushq %rax; nop; \
17565+ .popsection ; \
17566+ .pushsection .altinstructions, "a" ; \
17567+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17568+ .popsection ; \
17569+ call __pax_open_userland; \
17570+ popq %rax; \
17571+ 663:
17572+
17573+#define ASM_PAX_CLOSE_USERLAND \
17574+ 661: jmp 663f; \
17575+ .pushsection .altinstr_replacement, "a" ; \
17576+ 662: pushq %rax; nop; \
17577+ .popsection; \
17578+ .pushsection .altinstructions, "a" ; \
17579+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17580+ .popsection; \
17581+ call __pax_close_userland; \
17582+ popq %rax; \
17583+ 663:
17584+#else
17585+#define ASM_PAX_OPEN_USERLAND
17586+#define ASM_PAX_CLOSE_USERLAND
17587+#endif
17588+
17589 #ifdef CONFIG_X86_SMAP
17590
17591 #define ASM_CLAC \
17592 661: ASM_NOP3 ; \
17593- .pushsection .altinstr_replacement, "ax" ; \
17594+ .pushsection .altinstr_replacement, "a" ; \
17595 662: __ASM_CLAC ; \
17596 .popsection ; \
17597 .pushsection .altinstructions, "a" ; \
17598@@ -38,7 +67,7 @@
17599
17600 #define ASM_STAC \
17601 661: ASM_NOP3 ; \
17602- .pushsection .altinstr_replacement, "ax" ; \
17603+ .pushsection .altinstr_replacement, "a" ; \
17604 662: __ASM_STAC ; \
17605 .popsection ; \
17606 .pushsection .altinstructions, "a" ; \
17607@@ -56,6 +85,37 @@
17608
17609 #include <asm/alternative.h>
17610
17611+#define __HAVE_ARCH_PAX_OPEN_USERLAND
17612+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
17613+
17614+extern void __pax_open_userland(void);
17615+static __always_inline unsigned long pax_open_userland(void)
17616+{
17617+
17618+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17619+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
17620+ :
17621+ : [open] "i" (__pax_open_userland)
17622+ : "memory", "rax");
17623+#endif
17624+
17625+ return 0;
17626+}
17627+
17628+extern void __pax_close_userland(void);
17629+static __always_inline unsigned long pax_close_userland(void)
17630+{
17631+
17632+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17633+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
17634+ :
17635+ : [close] "i" (__pax_close_userland)
17636+ : "memory", "rax");
17637+#endif
17638+
17639+ return 0;
17640+}
17641+
17642 #ifdef CONFIG_X86_SMAP
17643
17644 static __always_inline void clac(void)
17645diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
17646index b073aae..39f9bdd 100644
17647--- a/arch/x86/include/asm/smp.h
17648+++ b/arch/x86/include/asm/smp.h
17649@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
17650 /* cpus sharing the last level cache: */
17651 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
17652 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
17653-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
17654+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
17655
17656 static inline struct cpumask *cpu_sibling_mask(int cpu)
17657 {
17658@@ -79,7 +79,7 @@ struct smp_ops {
17659
17660 void (*send_call_func_ipi)(const struct cpumask *mask);
17661 void (*send_call_func_single_ipi)(int cpu);
17662-};
17663+} __no_const;
17664
17665 /* Globals due to paravirt */
17666 extern void set_cpu_sibling_map(int cpu);
17667@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
17668 extern int safe_smp_processor_id(void);
17669
17670 #elif defined(CONFIG_X86_64_SMP)
17671-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17672-
17673-#define stack_smp_processor_id() \
17674-({ \
17675- struct thread_info *ti; \
17676- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
17677- ti->cpu; \
17678-})
17679+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17680+#define stack_smp_processor_id() raw_smp_processor_id()
17681 #define safe_smp_processor_id() smp_processor_id()
17682
17683 #endif
17684diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
17685index 33692ea..350a534 100644
17686--- a/arch/x86/include/asm/spinlock.h
17687+++ b/arch/x86/include/asm/spinlock.h
17688@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
17689 static inline void arch_read_lock(arch_rwlock_t *rw)
17690 {
17691 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
17692+
17693+#ifdef CONFIG_PAX_REFCOUNT
17694+ "jno 0f\n"
17695+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
17696+ "int $4\n0:\n"
17697+ _ASM_EXTABLE(0b, 0b)
17698+#endif
17699+
17700 "jns 1f\n"
17701 "call __read_lock_failed\n\t"
17702 "1:\n"
17703@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
17704 static inline void arch_write_lock(arch_rwlock_t *rw)
17705 {
17706 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
17707+
17708+#ifdef CONFIG_PAX_REFCOUNT
17709+ "jno 0f\n"
17710+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
17711+ "int $4\n0:\n"
17712+ _ASM_EXTABLE(0b, 0b)
17713+#endif
17714+
17715 "jz 1f\n"
17716 "call __write_lock_failed\n\t"
17717 "1:\n"
17718@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
17719
17720 static inline void arch_read_unlock(arch_rwlock_t *rw)
17721 {
17722- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
17723+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
17724+
17725+#ifdef CONFIG_PAX_REFCOUNT
17726+ "jno 0f\n"
17727+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
17728+ "int $4\n0:\n"
17729+ _ASM_EXTABLE(0b, 0b)
17730+#endif
17731+
17732 :"+m" (rw->lock) : : "memory");
17733 }
17734
17735 static inline void arch_write_unlock(arch_rwlock_t *rw)
17736 {
17737- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
17738+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
17739+
17740+#ifdef CONFIG_PAX_REFCOUNT
17741+ "jno 0f\n"
17742+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
17743+ "int $4\n0:\n"
17744+ _ASM_EXTABLE(0b, 0b)
17745+#endif
17746+
17747 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
17748 }
17749
17750diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
17751index 6a99859..03cb807 100644
17752--- a/arch/x86/include/asm/stackprotector.h
17753+++ b/arch/x86/include/asm/stackprotector.h
17754@@ -47,7 +47,7 @@
17755 * head_32 for boot CPU and setup_per_cpu_areas() for others.
17756 */
17757 #define GDT_STACK_CANARY_INIT \
17758- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
17759+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
17760
17761 /*
17762 * Initialize the stackprotector canary value.
17763@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
17764
17765 static inline void load_stack_canary_segment(void)
17766 {
17767-#ifdef CONFIG_X86_32
17768+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17769 asm volatile ("mov %0, %%gs" : : "r" (0));
17770 #endif
17771 }
17772diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
17773index 70bbe39..4ae2bd4 100644
17774--- a/arch/x86/include/asm/stacktrace.h
17775+++ b/arch/x86/include/asm/stacktrace.h
17776@@ -11,28 +11,20 @@
17777
17778 extern int kstack_depth_to_print;
17779
17780-struct thread_info;
17781+struct task_struct;
17782 struct stacktrace_ops;
17783
17784-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
17785- unsigned long *stack,
17786- unsigned long bp,
17787- const struct stacktrace_ops *ops,
17788- void *data,
17789- unsigned long *end,
17790- int *graph);
17791+typedef unsigned long walk_stack_t(struct task_struct *task,
17792+ void *stack_start,
17793+ unsigned long *stack,
17794+ unsigned long bp,
17795+ const struct stacktrace_ops *ops,
17796+ void *data,
17797+ unsigned long *end,
17798+ int *graph);
17799
17800-extern unsigned long
17801-print_context_stack(struct thread_info *tinfo,
17802- unsigned long *stack, unsigned long bp,
17803- const struct stacktrace_ops *ops, void *data,
17804- unsigned long *end, int *graph);
17805-
17806-extern unsigned long
17807-print_context_stack_bp(struct thread_info *tinfo,
17808- unsigned long *stack, unsigned long bp,
17809- const struct stacktrace_ops *ops, void *data,
17810- unsigned long *end, int *graph);
17811+extern walk_stack_t print_context_stack;
17812+extern walk_stack_t print_context_stack_bp;
17813
17814 /* Generic stack tracer with callbacks */
17815
17816@@ -40,7 +32,7 @@ struct stacktrace_ops {
17817 void (*address)(void *data, unsigned long address, int reliable);
17818 /* On negative return stop dumping */
17819 int (*stack)(void *data, char *name);
17820- walk_stack_t walk_stack;
17821+ walk_stack_t *walk_stack;
17822 };
17823
17824 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
17825diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
17826index 4ec45b3..a4f0a8a 100644
17827--- a/arch/x86/include/asm/switch_to.h
17828+++ b/arch/x86/include/asm/switch_to.h
17829@@ -108,7 +108,7 @@ do { \
17830 "call __switch_to\n\t" \
17831 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
17832 __switch_canary \
17833- "movq %P[thread_info](%%rsi),%%r8\n\t" \
17834+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
17835 "movq %%rax,%%rdi\n\t" \
17836 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
17837 "jnz ret_from_fork\n\t" \
17838@@ -119,7 +119,7 @@ do { \
17839 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
17840 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
17841 [_tif_fork] "i" (_TIF_FORK), \
17842- [thread_info] "i" (offsetof(struct task_struct, stack)), \
17843+ [thread_info] "m" (current_tinfo), \
17844 [current_task] "m" (current_task) \
17845 __switch_canary_iparam \
17846 : "memory", "cc" __EXTRA_CLOBBER)
17847diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
17848index a1df6e8..e002940 100644
17849--- a/arch/x86/include/asm/thread_info.h
17850+++ b/arch/x86/include/asm/thread_info.h
17851@@ -10,6 +10,7 @@
17852 #include <linux/compiler.h>
17853 #include <asm/page.h>
17854 #include <asm/types.h>
17855+#include <asm/percpu.h>
17856
17857 /*
17858 * low level task data that entry.S needs immediate access to
17859@@ -23,7 +24,6 @@ struct exec_domain;
17860 #include <linux/atomic.h>
17861
17862 struct thread_info {
17863- struct task_struct *task; /* main task structure */
17864 struct exec_domain *exec_domain; /* execution domain */
17865 __u32 flags; /* low level flags */
17866 __u32 status; /* thread synchronous flags */
17867@@ -33,19 +33,13 @@ struct thread_info {
17868 mm_segment_t addr_limit;
17869 struct restart_block restart_block;
17870 void __user *sysenter_return;
17871-#ifdef CONFIG_X86_32
17872- unsigned long previous_esp; /* ESP of the previous stack in
17873- case of nested (IRQ) stacks
17874- */
17875- __u8 supervisor_stack[0];
17876-#endif
17877+ unsigned long lowest_stack;
17878 unsigned int sig_on_uaccess_error:1;
17879 unsigned int uaccess_err:1; /* uaccess failed */
17880 };
17881
17882-#define INIT_THREAD_INFO(tsk) \
17883+#define INIT_THREAD_INFO \
17884 { \
17885- .task = &tsk, \
17886 .exec_domain = &default_exec_domain, \
17887 .flags = 0, \
17888 .cpu = 0, \
17889@@ -56,7 +50,7 @@ struct thread_info {
17890 }, \
17891 }
17892
17893-#define init_thread_info (init_thread_union.thread_info)
17894+#define init_thread_info (init_thread_union.stack)
17895 #define init_stack (init_thread_union.stack)
17896
17897 #else /* !__ASSEMBLY__ */
17898@@ -97,6 +91,7 @@ struct thread_info {
17899 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
17900 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
17901 #define TIF_X32 30 /* 32-bit native x86-64 binary */
17902+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
17903
17904 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
17905 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
17906@@ -121,17 +116,18 @@ struct thread_info {
17907 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
17908 #define _TIF_ADDR32 (1 << TIF_ADDR32)
17909 #define _TIF_X32 (1 << TIF_X32)
17910+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
17911
17912 /* work to do in syscall_trace_enter() */
17913 #define _TIF_WORK_SYSCALL_ENTRY \
17914 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
17915 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
17916- _TIF_NOHZ)
17917+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17918
17919 /* work to do in syscall_trace_leave() */
17920 #define _TIF_WORK_SYSCALL_EXIT \
17921 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
17922- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
17923+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
17924
17925 /* work to do on interrupt/exception return */
17926 #define _TIF_WORK_MASK \
17927@@ -142,7 +138,7 @@ struct thread_info {
17928 /* work to do on any return to user space */
17929 #define _TIF_ALLWORK_MASK \
17930 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
17931- _TIF_NOHZ)
17932+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17933
17934 /* Only used for 64 bit */
17935 #define _TIF_DO_NOTIFY_MASK \
17936@@ -158,45 +154,40 @@ struct thread_info {
17937
17938 #define PREEMPT_ACTIVE 0x10000000
17939
17940-#ifdef CONFIG_X86_32
17941-
17942-#define STACK_WARN (THREAD_SIZE/8)
17943-/*
17944- * macros/functions for gaining access to the thread information structure
17945- *
17946- * preempt_count needs to be 1 initially, until the scheduler is functional.
17947- */
17948-#ifndef __ASSEMBLY__
17949-
17950-
17951-/* how to get the current stack pointer from C */
17952-register unsigned long current_stack_pointer asm("esp") __used;
17953-
17954-/* how to get the thread information struct from C */
17955-static inline struct thread_info *current_thread_info(void)
17956-{
17957- return (struct thread_info *)
17958- (current_stack_pointer & ~(THREAD_SIZE - 1));
17959-}
17960-
17961-#else /* !__ASSEMBLY__ */
17962-
17963+#ifdef __ASSEMBLY__
17964 /* how to get the thread information struct from ASM */
17965 #define GET_THREAD_INFO(reg) \
17966- movl $-THREAD_SIZE, reg; \
17967- andl %esp, reg
17968+ mov PER_CPU_VAR(current_tinfo), reg
17969
17970 /* use this one if reg already contains %esp */
17971-#define GET_THREAD_INFO_WITH_ESP(reg) \
17972- andl $-THREAD_SIZE, reg
17973+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
17974+#else
17975+/* how to get the thread information struct from C */
17976+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
17977+
17978+static __always_inline struct thread_info *current_thread_info(void)
17979+{
17980+ return this_cpu_read_stable(current_tinfo);
17981+}
17982+#endif
17983+
17984+#ifdef CONFIG_X86_32
17985+
17986+#define STACK_WARN (THREAD_SIZE/8)
17987+/*
17988+ * macros/functions for gaining access to the thread information structure
17989+ *
17990+ * preempt_count needs to be 1 initially, until the scheduler is functional.
17991+ */
17992+#ifndef __ASSEMBLY__
17993+
17994+/* how to get the current stack pointer from C */
17995+register unsigned long current_stack_pointer asm("esp") __used;
17996
17997 #endif
17998
17999 #else /* X86_32 */
18000
18001-#include <asm/percpu.h>
18002-#define KERNEL_STACK_OFFSET (5*8)
18003-
18004 /*
18005 * macros/functions for gaining access to the thread information structure
18006 * preempt_count needs to be 1 initially, until the scheduler is functional.
18007@@ -204,27 +195,8 @@ static inline struct thread_info *current_thread_info(void)
18008 #ifndef __ASSEMBLY__
18009 DECLARE_PER_CPU(unsigned long, kernel_stack);
18010
18011-static inline struct thread_info *current_thread_info(void)
18012-{
18013- struct thread_info *ti;
18014- ti = (void *)(this_cpu_read_stable(kernel_stack) +
18015- KERNEL_STACK_OFFSET - THREAD_SIZE);
18016- return ti;
18017-}
18018-
18019-#else /* !__ASSEMBLY__ */
18020-
18021-/* how to get the thread information struct from ASM */
18022-#define GET_THREAD_INFO(reg) \
18023- movq PER_CPU_VAR(kernel_stack),reg ; \
18024- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
18025-
18026-/*
18027- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
18028- * a certain register (to be used in assembler memory operands).
18029- */
18030-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
18031-
18032+/* how to get the current stack pointer from C */
18033+register unsigned long current_stack_pointer asm("rsp") __used;
18034 #endif
18035
18036 #endif /* !X86_32 */
18037@@ -283,5 +255,12 @@ static inline bool is_ia32_task(void)
18038 extern void arch_task_cache_init(void);
18039 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
18040 extern void arch_release_task_struct(struct task_struct *tsk);
18041+
18042+#define __HAVE_THREAD_FUNCTIONS
18043+#define task_thread_info(task) (&(task)->tinfo)
18044+#define task_stack_page(task) ((task)->stack)
18045+#define setup_thread_stack(p, org) do {} while (0)
18046+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
18047+
18048 #endif
18049 #endif /* _ASM_X86_THREAD_INFO_H */
18050diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
18051index 50a7fc0..45844c0 100644
18052--- a/arch/x86/include/asm/tlbflush.h
18053+++ b/arch/x86/include/asm/tlbflush.h
18054@@ -17,18 +17,44 @@
18055
18056 static inline void __native_flush_tlb(void)
18057 {
18058+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18059+ unsigned long descriptor[2];
18060+
18061+ descriptor[0] = PCID_KERNEL;
18062+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
18063+ return;
18064+ }
18065+
18066+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18067+ if (static_cpu_has(X86_FEATURE_PCID)) {
18068+ unsigned int cpu = raw_get_cpu();
18069+
18070+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18071+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18072+ raw_put_cpu_no_resched();
18073+ return;
18074+ }
18075+#endif
18076+
18077 native_write_cr3(native_read_cr3());
18078 }
18079
18080 static inline void __native_flush_tlb_global_irq_disabled(void)
18081 {
18082- unsigned long cr4;
18083+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18084+ unsigned long descriptor[2];
18085
18086- cr4 = native_read_cr4();
18087- /* clear PGE */
18088- native_write_cr4(cr4 & ~X86_CR4_PGE);
18089- /* write old PGE again and flush TLBs */
18090- native_write_cr4(cr4);
18091+ descriptor[0] = PCID_KERNEL;
18092+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
18093+ } else {
18094+ unsigned long cr4;
18095+
18096+ cr4 = native_read_cr4();
18097+ /* clear PGE */
18098+ native_write_cr4(cr4 & ~X86_CR4_PGE);
18099+ /* write old PGE again and flush TLBs */
18100+ native_write_cr4(cr4);
18101+ }
18102 }
18103
18104 static inline void __native_flush_tlb_global(void)
18105@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
18106
18107 static inline void __native_flush_tlb_single(unsigned long addr)
18108 {
18109+
18110+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18111+ unsigned long descriptor[2];
18112+
18113+ descriptor[0] = PCID_KERNEL;
18114+ descriptor[1] = addr;
18115+
18116+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18117+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
18118+ if (addr < TASK_SIZE_MAX)
18119+ descriptor[1] += pax_user_shadow_base;
18120+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18121+ }
18122+
18123+ descriptor[0] = PCID_USER;
18124+ descriptor[1] = addr;
18125+#endif
18126+
18127+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18128+ return;
18129+ }
18130+
18131+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18132+ if (static_cpu_has(X86_FEATURE_PCID)) {
18133+ unsigned int cpu = raw_get_cpu();
18134+
18135+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
18136+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18137+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18138+ raw_put_cpu_no_resched();
18139+
18140+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
18141+ addr += pax_user_shadow_base;
18142+ }
18143+#endif
18144+
18145 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18146 }
18147
18148diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
18149index 5ee2687..74590b9 100644
18150--- a/arch/x86/include/asm/uaccess.h
18151+++ b/arch/x86/include/asm/uaccess.h
18152@@ -7,6 +7,7 @@
18153 #include <linux/compiler.h>
18154 #include <linux/thread_info.h>
18155 #include <linux/string.h>
18156+#include <linux/sched.h>
18157 #include <asm/asm.h>
18158 #include <asm/page.h>
18159 #include <asm/smap.h>
18160@@ -29,7 +30,12 @@
18161
18162 #define get_ds() (KERNEL_DS)
18163 #define get_fs() (current_thread_info()->addr_limit)
18164+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18165+void __set_fs(mm_segment_t x);
18166+void set_fs(mm_segment_t x);
18167+#else
18168 #define set_fs(x) (current_thread_info()->addr_limit = (x))
18169+#endif
18170
18171 #define segment_eq(a, b) ((a).seg == (b).seg)
18172
18173@@ -77,8 +83,33 @@
18174 * checks that the pointer is in the user space range - after calling
18175 * this function, memory access functions may still return -EFAULT.
18176 */
18177-#define access_ok(type, addr, size) \
18178- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18179+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18180+#define access_ok(type, addr, size) \
18181+({ \
18182+ long __size = size; \
18183+ unsigned long __addr = (unsigned long)addr; \
18184+ unsigned long __addr_ao = __addr & PAGE_MASK; \
18185+ unsigned long __end_ao = __addr + __size - 1; \
18186+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
18187+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
18188+ while(__addr_ao <= __end_ao) { \
18189+ char __c_ao; \
18190+ __addr_ao += PAGE_SIZE; \
18191+ if (__size > PAGE_SIZE) \
18192+ cond_resched(); \
18193+ if (__get_user(__c_ao, (char __user *)__addr)) \
18194+ break; \
18195+ if (type != VERIFY_WRITE) { \
18196+ __addr = __addr_ao; \
18197+ continue; \
18198+ } \
18199+ if (__put_user(__c_ao, (char __user *)__addr)) \
18200+ break; \
18201+ __addr = __addr_ao; \
18202+ } \
18203+ } \
18204+ __ret_ao; \
18205+})
18206
18207 /*
18208 * The exception table consists of pairs of addresses relative to the
18209@@ -165,10 +196,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18210 register __inttype(*(ptr)) __val_gu asm("%edx"); \
18211 __chk_user_ptr(ptr); \
18212 might_fault(); \
18213+ pax_open_userland(); \
18214 asm volatile("call __get_user_%P3" \
18215 : "=a" (__ret_gu), "=r" (__val_gu) \
18216 : "0" (ptr), "i" (sizeof(*(ptr)))); \
18217 (x) = (__typeof__(*(ptr))) __val_gu; \
18218+ pax_close_userland(); \
18219 __ret_gu; \
18220 })
18221
18222@@ -176,13 +209,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18223 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
18224 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
18225
18226-
18227+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18228+#define __copyuser_seg "gs;"
18229+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
18230+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
18231+#else
18232+#define __copyuser_seg
18233+#define __COPYUSER_SET_ES
18234+#define __COPYUSER_RESTORE_ES
18235+#endif
18236
18237 #ifdef CONFIG_X86_32
18238 #define __put_user_asm_u64(x, addr, err, errret) \
18239 asm volatile(ASM_STAC "\n" \
18240- "1: movl %%eax,0(%2)\n" \
18241- "2: movl %%edx,4(%2)\n" \
18242+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18243+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18244 "3: " ASM_CLAC "\n" \
18245 ".section .fixup,\"ax\"\n" \
18246 "4: movl %3,%0\n" \
18247@@ -195,8 +236,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18248
18249 #define __put_user_asm_ex_u64(x, addr) \
18250 asm volatile(ASM_STAC "\n" \
18251- "1: movl %%eax,0(%1)\n" \
18252- "2: movl %%edx,4(%1)\n" \
18253+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18254+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18255 "3: " ASM_CLAC "\n" \
18256 _ASM_EXTABLE_EX(1b, 2b) \
18257 _ASM_EXTABLE_EX(2b, 3b) \
18258@@ -246,7 +287,8 @@ extern void __put_user_8(void);
18259 __typeof__(*(ptr)) __pu_val; \
18260 __chk_user_ptr(ptr); \
18261 might_fault(); \
18262- __pu_val = x; \
18263+ __pu_val = (x); \
18264+ pax_open_userland(); \
18265 switch (sizeof(*(ptr))) { \
18266 case 1: \
18267 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18268@@ -264,6 +306,7 @@ extern void __put_user_8(void);
18269 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18270 break; \
18271 } \
18272+ pax_close_userland(); \
18273 __ret_pu; \
18274 })
18275
18276@@ -344,8 +387,10 @@ do { \
18277 } while (0)
18278
18279 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18280+do { \
18281+ pax_open_userland(); \
18282 asm volatile(ASM_STAC "\n" \
18283- "1: mov"itype" %2,%"rtype"1\n" \
18284+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18285 "2: " ASM_CLAC "\n" \
18286 ".section .fixup,\"ax\"\n" \
18287 "3: mov %3,%0\n" \
18288@@ -353,8 +398,10 @@ do { \
18289 " jmp 2b\n" \
18290 ".previous\n" \
18291 _ASM_EXTABLE(1b, 3b) \
18292- : "=r" (err), ltype(x) \
18293- : "m" (__m(addr)), "i" (errret), "0" (err))
18294+ : "=r" (err), ltype (x) \
18295+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18296+ pax_close_userland(); \
18297+} while (0)
18298
18299 #define __get_user_size_ex(x, ptr, size) \
18300 do { \
18301@@ -378,7 +425,7 @@ do { \
18302 } while (0)
18303
18304 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18305- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18306+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18307 "2:\n" \
18308 _ASM_EXTABLE_EX(1b, 2b) \
18309 : ltype(x) : "m" (__m(addr)))
18310@@ -395,13 +442,24 @@ do { \
18311 int __gu_err; \
18312 unsigned long __gu_val; \
18313 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18314- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18315+ (x) = (__typeof__(*(ptr)))__gu_val; \
18316 __gu_err; \
18317 })
18318
18319 /* FIXME: this hack is definitely wrong -AK */
18320 struct __large_struct { unsigned long buf[100]; };
18321-#define __m(x) (*(struct __large_struct __user *)(x))
18322+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18323+#define ____m(x) \
18324+({ \
18325+ unsigned long ____x = (unsigned long)(x); \
18326+ if (____x < pax_user_shadow_base) \
18327+ ____x += pax_user_shadow_base; \
18328+ (typeof(x))____x; \
18329+})
18330+#else
18331+#define ____m(x) (x)
18332+#endif
18333+#define __m(x) (*(struct __large_struct __user *)____m(x))
18334
18335 /*
18336 * Tell gcc we read from memory instead of writing: this is because
18337@@ -409,8 +467,10 @@ struct __large_struct { unsigned long buf[100]; };
18338 * aliasing issues.
18339 */
18340 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18341+do { \
18342+ pax_open_userland(); \
18343 asm volatile(ASM_STAC "\n" \
18344- "1: mov"itype" %"rtype"1,%2\n" \
18345+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18346 "2: " ASM_CLAC "\n" \
18347 ".section .fixup,\"ax\"\n" \
18348 "3: mov %3,%0\n" \
18349@@ -418,10 +478,12 @@ struct __large_struct { unsigned long buf[100]; };
18350 ".previous\n" \
18351 _ASM_EXTABLE(1b, 3b) \
18352 : "=r"(err) \
18353- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18354+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18355+ pax_close_userland(); \
18356+} while (0)
18357
18358 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18359- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18360+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18361 "2:\n" \
18362 _ASM_EXTABLE_EX(1b, 2b) \
18363 : : ltype(x), "m" (__m(addr)))
18364@@ -431,11 +493,13 @@ struct __large_struct { unsigned long buf[100]; };
18365 */
18366 #define uaccess_try do { \
18367 current_thread_info()->uaccess_err = 0; \
18368+ pax_open_userland(); \
18369 stac(); \
18370 barrier();
18371
18372 #define uaccess_catch(err) \
18373 clac(); \
18374+ pax_close_userland(); \
18375 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18376 } while (0)
18377
18378@@ -460,8 +524,12 @@ struct __large_struct { unsigned long buf[100]; };
18379 * On error, the variable @x is set to zero.
18380 */
18381
18382+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18383+#define __get_user(x, ptr) get_user((x), (ptr))
18384+#else
18385 #define __get_user(x, ptr) \
18386 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18387+#endif
18388
18389 /**
18390 * __put_user: - Write a simple value into user space, with less checking.
18391@@ -483,8 +551,12 @@ struct __large_struct { unsigned long buf[100]; };
18392 * Returns zero on success, or -EFAULT on error.
18393 */
18394
18395+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18396+#define __put_user(x, ptr) put_user((x), (ptr))
18397+#else
18398 #define __put_user(x, ptr) \
18399 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18400+#endif
18401
18402 #define __get_user_unaligned __get_user
18403 #define __put_user_unaligned __put_user
18404@@ -502,7 +574,7 @@ struct __large_struct { unsigned long buf[100]; };
18405 #define get_user_ex(x, ptr) do { \
18406 unsigned long __gue_val; \
18407 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18408- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18409+ (x) = (__typeof__(*(ptr)))__gue_val; \
18410 } while (0)
18411
18412 #define put_user_try uaccess_try
18413@@ -519,8 +591,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
18414 extern __must_check long strlen_user(const char __user *str);
18415 extern __must_check long strnlen_user(const char __user *str, long n);
18416
18417-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
18418-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
18419+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18420+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18421
18422 /*
18423 * movsl can be slow when source and dest are not both 8-byte aligned
18424diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18425index 7f760a9..04b1c65 100644
18426--- a/arch/x86/include/asm/uaccess_32.h
18427+++ b/arch/x86/include/asm/uaccess_32.h
18428@@ -11,15 +11,15 @@
18429 #include <asm/page.h>
18430
18431 unsigned long __must_check __copy_to_user_ll
18432- (void __user *to, const void *from, unsigned long n);
18433+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
18434 unsigned long __must_check __copy_from_user_ll
18435- (void *to, const void __user *from, unsigned long n);
18436+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18437 unsigned long __must_check __copy_from_user_ll_nozero
18438- (void *to, const void __user *from, unsigned long n);
18439+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18440 unsigned long __must_check __copy_from_user_ll_nocache
18441- (void *to, const void __user *from, unsigned long n);
18442+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18443 unsigned long __must_check __copy_from_user_ll_nocache_nozero
18444- (void *to, const void __user *from, unsigned long n);
18445+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18446
18447 /**
18448 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
18449@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18450 static __always_inline unsigned long __must_check
18451 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18452 {
18453+ if ((long)n < 0)
18454+ return n;
18455+
18456+ check_object_size(from, n, true);
18457+
18458 if (__builtin_constant_p(n)) {
18459 unsigned long ret;
18460
18461@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18462 __copy_to_user(void __user *to, const void *from, unsigned long n)
18463 {
18464 might_fault();
18465+
18466 return __copy_to_user_inatomic(to, from, n);
18467 }
18468
18469 static __always_inline unsigned long
18470 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18471 {
18472+ if ((long)n < 0)
18473+ return n;
18474+
18475 /* Avoid zeroing the tail if the copy fails..
18476 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18477 * but as the zeroing behaviour is only significant when n is not
18478@@ -137,6 +146,12 @@ static __always_inline unsigned long
18479 __copy_from_user(void *to, const void __user *from, unsigned long n)
18480 {
18481 might_fault();
18482+
18483+ if ((long)n < 0)
18484+ return n;
18485+
18486+ check_object_size(to, n, false);
18487+
18488 if (__builtin_constant_p(n)) {
18489 unsigned long ret;
18490
18491@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18492 const void __user *from, unsigned long n)
18493 {
18494 might_fault();
18495+
18496+ if ((long)n < 0)
18497+ return n;
18498+
18499 if (__builtin_constant_p(n)) {
18500 unsigned long ret;
18501
18502@@ -181,15 +200,19 @@ static __always_inline unsigned long
18503 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18504 unsigned long n)
18505 {
18506- return __copy_from_user_ll_nocache_nozero(to, from, n);
18507+ if ((long)n < 0)
18508+ return n;
18509+
18510+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18511 }
18512
18513-unsigned long __must_check copy_to_user(void __user *to,
18514- const void *from, unsigned long n);
18515-unsigned long __must_check _copy_from_user(void *to,
18516- const void __user *from,
18517- unsigned long n);
18518-
18519+extern void copy_to_user_overflow(void)
18520+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18521+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18522+#else
18523+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18524+#endif
18525+;
18526
18527 extern void copy_from_user_overflow(void)
18528 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18529@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18530 #endif
18531 ;
18532
18533-static inline unsigned long __must_check copy_from_user(void *to,
18534- const void __user *from,
18535- unsigned long n)
18536+/**
18537+ * copy_to_user: - Copy a block of data into user space.
18538+ * @to: Destination address, in user space.
18539+ * @from: Source address, in kernel space.
18540+ * @n: Number of bytes to copy.
18541+ *
18542+ * Context: User context only. This function may sleep.
18543+ *
18544+ * Copy data from kernel space to user space.
18545+ *
18546+ * Returns number of bytes that could not be copied.
18547+ * On success, this will be zero.
18548+ */
18549+static inline unsigned long __must_check
18550+copy_to_user(void __user *to, const void *from, unsigned long n)
18551 {
18552- int sz = __compiletime_object_size(to);
18553+ size_t sz = __compiletime_object_size(from);
18554
18555- if (likely(sz == -1 || sz >= n))
18556- n = _copy_from_user(to, from, n);
18557- else
18558+ if (unlikely(sz != (size_t)-1 && sz < n))
18559+ copy_to_user_overflow();
18560+ else if (access_ok(VERIFY_WRITE, to, n))
18561+ n = __copy_to_user(to, from, n);
18562+ return n;
18563+}
18564+
18565+/**
18566+ * copy_from_user: - Copy a block of data from user space.
18567+ * @to: Destination address, in kernel space.
18568+ * @from: Source address, in user space.
18569+ * @n: Number of bytes to copy.
18570+ *
18571+ * Context: User context only. This function may sleep.
18572+ *
18573+ * Copy data from user space to kernel space.
18574+ *
18575+ * Returns number of bytes that could not be copied.
18576+ * On success, this will be zero.
18577+ *
18578+ * If some data could not be copied, this function will pad the copied
18579+ * data to the requested size using zero bytes.
18580+ */
18581+static inline unsigned long __must_check
18582+copy_from_user(void *to, const void __user *from, unsigned long n)
18583+{
18584+ size_t sz = __compiletime_object_size(to);
18585+
18586+ check_object_size(to, n, false);
18587+
18588+ if (unlikely(sz != (size_t)-1 && sz < n))
18589 copy_from_user_overflow();
18590-
18591+ else if (access_ok(VERIFY_READ, from, n))
18592+ n = __copy_from_user(to, from, n);
18593+ else if ((long)n > 0)
18594+ memset(to, 0, n);
18595 return n;
18596 }
18597
18598diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
18599index 142810c..1dbe82f 100644
18600--- a/arch/x86/include/asm/uaccess_64.h
18601+++ b/arch/x86/include/asm/uaccess_64.h
18602@@ -10,6 +10,9 @@
18603 #include <asm/alternative.h>
18604 #include <asm/cpufeature.h>
18605 #include <asm/page.h>
18606+#include <asm/pgtable.h>
18607+
18608+#define set_fs(x) (current_thread_info()->addr_limit = (x))
18609
18610 /*
18611 * Copy To/From Userspace
18612@@ -17,13 +20,13 @@
18613
18614 /* Handles exceptions in both to and from, but doesn't do access_ok */
18615 __must_check unsigned long
18616-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
18617+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
18618 __must_check unsigned long
18619-copy_user_generic_string(void *to, const void *from, unsigned len);
18620+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
18621 __must_check unsigned long
18622-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
18623+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
18624
18625-static __always_inline __must_check unsigned long
18626+static __always_inline __must_check __size_overflow(3) unsigned long
18627 copy_user_generic(void *to, const void *from, unsigned len)
18628 {
18629 unsigned ret;
18630@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
18631 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
18632 "=d" (len)),
18633 "1" (to), "2" (from), "3" (len)
18634- : "memory", "rcx", "r8", "r9", "r10", "r11");
18635+ : "memory", "rcx", "r8", "r9", "r11");
18636 return ret;
18637 }
18638
18639+static __always_inline __must_check unsigned long
18640+__copy_to_user(void __user *to, const void *from, unsigned long len);
18641+static __always_inline __must_check unsigned long
18642+__copy_from_user(void *to, const void __user *from, unsigned long len);
18643 __must_check unsigned long
18644-_copy_to_user(void __user *to, const void *from, unsigned len);
18645-__must_check unsigned long
18646-_copy_from_user(void *to, const void __user *from, unsigned len);
18647-__must_check unsigned long
18648-copy_in_user(void __user *to, const void __user *from, unsigned len);
18649+copy_in_user(void __user *to, const void __user *from, unsigned long len);
18650+
18651+extern void copy_to_user_overflow(void)
18652+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18653+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18654+#else
18655+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18656+#endif
18657+;
18658+
18659+extern void copy_from_user_overflow(void)
18660+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18661+ __compiletime_error("copy_from_user() buffer size is not provably correct")
18662+#else
18663+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
18664+#endif
18665+;
18666
18667 static inline unsigned long __must_check copy_from_user(void *to,
18668 const void __user *from,
18669 unsigned long n)
18670 {
18671- int sz = __compiletime_object_size(to);
18672-
18673 might_fault();
18674- if (likely(sz == -1 || sz >= n))
18675- n = _copy_from_user(to, from, n);
18676-#ifdef CONFIG_DEBUG_VM
18677- else
18678- WARN(1, "Buffer overflow detected!\n");
18679-#endif
18680+
18681+ check_object_size(to, n, false);
18682+
18683+ if (access_ok(VERIFY_READ, from, n))
18684+ n = __copy_from_user(to, from, n);
18685+ else if (n < INT_MAX)
18686+ memset(to, 0, n);
18687 return n;
18688 }
18689
18690 static __always_inline __must_check
18691-int copy_to_user(void __user *dst, const void *src, unsigned size)
18692+int copy_to_user(void __user *dst, const void *src, unsigned long size)
18693 {
18694 might_fault();
18695
18696- return _copy_to_user(dst, src, size);
18697+ if (access_ok(VERIFY_WRITE, dst, size))
18698+ size = __copy_to_user(dst, src, size);
18699+ return size;
18700 }
18701
18702 static __always_inline __must_check
18703-int __copy_from_user(void *dst, const void __user *src, unsigned size)
18704+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
18705 {
18706- int ret = 0;
18707+ size_t sz = __compiletime_object_size(dst);
18708+ unsigned ret = 0;
18709
18710 might_fault();
18711+
18712+ if (size > INT_MAX)
18713+ return size;
18714+
18715+ check_object_size(dst, size, false);
18716+
18717+#ifdef CONFIG_PAX_MEMORY_UDEREF
18718+ if (!__access_ok(VERIFY_READ, src, size))
18719+ return size;
18720+#endif
18721+
18722+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18723+ copy_from_user_overflow();
18724+ return size;
18725+ }
18726+
18727 if (!__builtin_constant_p(size))
18728- return copy_user_generic(dst, (__force void *)src, size);
18729+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18730 switch (size) {
18731- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
18732+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
18733 ret, "b", "b", "=q", 1);
18734 return ret;
18735- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
18736+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
18737 ret, "w", "w", "=r", 2);
18738 return ret;
18739- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
18740+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
18741 ret, "l", "k", "=r", 4);
18742 return ret;
18743- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
18744+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18745 ret, "q", "", "=r", 8);
18746 return ret;
18747 case 10:
18748- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18749+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18750 ret, "q", "", "=r", 10);
18751 if (unlikely(ret))
18752 return ret;
18753 __get_user_asm(*(u16 *)(8 + (char *)dst),
18754- (u16 __user *)(8 + (char __user *)src),
18755+ (const u16 __user *)(8 + (const char __user *)src),
18756 ret, "w", "w", "=r", 2);
18757 return ret;
18758 case 16:
18759- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18760+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18761 ret, "q", "", "=r", 16);
18762 if (unlikely(ret))
18763 return ret;
18764 __get_user_asm(*(u64 *)(8 + (char *)dst),
18765- (u64 __user *)(8 + (char __user *)src),
18766+ (const u64 __user *)(8 + (const char __user *)src),
18767 ret, "q", "", "=r", 8);
18768 return ret;
18769 default:
18770- return copy_user_generic(dst, (__force void *)src, size);
18771+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18772 }
18773 }
18774
18775 static __always_inline __must_check
18776-int __copy_to_user(void __user *dst, const void *src, unsigned size)
18777+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
18778 {
18779- int ret = 0;
18780+ size_t sz = __compiletime_object_size(src);
18781+ unsigned ret = 0;
18782
18783 might_fault();
18784+
18785+ if (size > INT_MAX)
18786+ return size;
18787+
18788+ check_object_size(src, size, true);
18789+
18790+#ifdef CONFIG_PAX_MEMORY_UDEREF
18791+ if (!__access_ok(VERIFY_WRITE, dst, size))
18792+ return size;
18793+#endif
18794+
18795+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18796+ copy_to_user_overflow();
18797+ return size;
18798+ }
18799+
18800 if (!__builtin_constant_p(size))
18801- return copy_user_generic((__force void *)dst, src, size);
18802+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18803 switch (size) {
18804- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
18805+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
18806 ret, "b", "b", "iq", 1);
18807 return ret;
18808- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
18809+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
18810 ret, "w", "w", "ir", 2);
18811 return ret;
18812- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
18813+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
18814 ret, "l", "k", "ir", 4);
18815 return ret;
18816- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
18817+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18818 ret, "q", "", "er", 8);
18819 return ret;
18820 case 10:
18821- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18822+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18823 ret, "q", "", "er", 10);
18824 if (unlikely(ret))
18825 return ret;
18826 asm("":::"memory");
18827- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
18828+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
18829 ret, "w", "w", "ir", 2);
18830 return ret;
18831 case 16:
18832- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18833+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18834 ret, "q", "", "er", 16);
18835 if (unlikely(ret))
18836 return ret;
18837 asm("":::"memory");
18838- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
18839+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
18840 ret, "q", "", "er", 8);
18841 return ret;
18842 default:
18843- return copy_user_generic((__force void *)dst, src, size);
18844+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18845 }
18846 }
18847
18848 static __always_inline __must_check
18849-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18850+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
18851 {
18852- int ret = 0;
18853+ unsigned ret = 0;
18854
18855 might_fault();
18856+
18857+ if (size > INT_MAX)
18858+ return size;
18859+
18860+#ifdef CONFIG_PAX_MEMORY_UDEREF
18861+ if (!__access_ok(VERIFY_READ, src, size))
18862+ return size;
18863+ if (!__access_ok(VERIFY_WRITE, dst, size))
18864+ return size;
18865+#endif
18866+
18867 if (!__builtin_constant_p(size))
18868- return copy_user_generic((__force void *)dst,
18869- (__force void *)src, size);
18870+ return copy_user_generic((__force_kernel void *)____m(dst),
18871+ (__force_kernel const void *)____m(src), size);
18872 switch (size) {
18873 case 1: {
18874 u8 tmp;
18875- __get_user_asm(tmp, (u8 __user *)src,
18876+ __get_user_asm(tmp, (const u8 __user *)src,
18877 ret, "b", "b", "=q", 1);
18878 if (likely(!ret))
18879 __put_user_asm(tmp, (u8 __user *)dst,
18880@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18881 }
18882 case 2: {
18883 u16 tmp;
18884- __get_user_asm(tmp, (u16 __user *)src,
18885+ __get_user_asm(tmp, (const u16 __user *)src,
18886 ret, "w", "w", "=r", 2);
18887 if (likely(!ret))
18888 __put_user_asm(tmp, (u16 __user *)dst,
18889@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18890
18891 case 4: {
18892 u32 tmp;
18893- __get_user_asm(tmp, (u32 __user *)src,
18894+ __get_user_asm(tmp, (const u32 __user *)src,
18895 ret, "l", "k", "=r", 4);
18896 if (likely(!ret))
18897 __put_user_asm(tmp, (u32 __user *)dst,
18898@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18899 }
18900 case 8: {
18901 u64 tmp;
18902- __get_user_asm(tmp, (u64 __user *)src,
18903+ __get_user_asm(tmp, (const u64 __user *)src,
18904 ret, "q", "", "=r", 8);
18905 if (likely(!ret))
18906 __put_user_asm(tmp, (u64 __user *)dst,
18907@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18908 return ret;
18909 }
18910 default:
18911- return copy_user_generic((__force void *)dst,
18912- (__force void *)src, size);
18913+ return copy_user_generic((__force_kernel void *)____m(dst),
18914+ (__force_kernel const void *)____m(src), size);
18915 }
18916 }
18917
18918-static __must_check __always_inline int
18919-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
18920+static __must_check __always_inline unsigned long
18921+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
18922 {
18923- return copy_user_generic(dst, (__force const void *)src, size);
18924+ if (size > INT_MAX)
18925+ return size;
18926+
18927+#ifdef CONFIG_PAX_MEMORY_UDEREF
18928+ if (!__access_ok(VERIFY_READ, src, size))
18929+ return size;
18930+#endif
18931+
18932+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18933 }
18934
18935-static __must_check __always_inline int
18936-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
18937+static __must_check __always_inline unsigned long
18938+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
18939 {
18940- return copy_user_generic((__force void *)dst, src, size);
18941+ if (size > INT_MAX)
18942+ return size;
18943+
18944+#ifdef CONFIG_PAX_MEMORY_UDEREF
18945+ if (!__access_ok(VERIFY_WRITE, dst, size))
18946+ return size;
18947+#endif
18948+
18949+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18950 }
18951
18952-extern long __copy_user_nocache(void *dst, const void __user *src,
18953- unsigned size, int zerorest);
18954+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
18955+ unsigned long size, int zerorest) __size_overflow(3);
18956
18957-static inline int
18958-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
18959+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
18960 {
18961 might_sleep();
18962+
18963+ if (size > INT_MAX)
18964+ return size;
18965+
18966+#ifdef CONFIG_PAX_MEMORY_UDEREF
18967+ if (!__access_ok(VERIFY_READ, src, size))
18968+ return size;
18969+#endif
18970+
18971 return __copy_user_nocache(dst, src, size, 1);
18972 }
18973
18974-static inline int
18975-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18976- unsigned size)
18977+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18978+ unsigned long size)
18979 {
18980+ if (size > INT_MAX)
18981+ return size;
18982+
18983+#ifdef CONFIG_PAX_MEMORY_UDEREF
18984+ if (!__access_ok(VERIFY_READ, src, size))
18985+ return size;
18986+#endif
18987+
18988 return __copy_user_nocache(dst, src, size, 0);
18989 }
18990
18991-unsigned long
18992-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
18993+extern unsigned long
18994+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
18995
18996 #endif /* _ASM_X86_UACCESS_64_H */
18997diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
18998index 5b238981..77fdd78 100644
18999--- a/arch/x86/include/asm/word-at-a-time.h
19000+++ b/arch/x86/include/asm/word-at-a-time.h
19001@@ -11,7 +11,7 @@
19002 * and shift, for example.
19003 */
19004 struct word_at_a_time {
19005- const unsigned long one_bits, high_bits;
19006+ unsigned long one_bits, high_bits;
19007 };
19008
19009 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
19010diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
19011index d8d9922..bf6cecb 100644
19012--- a/arch/x86/include/asm/x86_init.h
19013+++ b/arch/x86/include/asm/x86_init.h
19014@@ -129,7 +129,7 @@ struct x86_init_ops {
19015 struct x86_init_timers timers;
19016 struct x86_init_iommu iommu;
19017 struct x86_init_pci pci;
19018-};
19019+} __no_const;
19020
19021 /**
19022 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
19023@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
19024 void (*setup_percpu_clockev)(void);
19025 void (*early_percpu_clock_init)(void);
19026 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
19027-};
19028+} __no_const;
19029
19030 /**
19031 * struct x86_platform_ops - platform specific runtime functions
19032@@ -166,7 +166,7 @@ struct x86_platform_ops {
19033 void (*save_sched_clock_state)(void);
19034 void (*restore_sched_clock_state)(void);
19035 void (*apic_post_init)(void);
19036-};
19037+} __no_const;
19038
19039 struct pci_dev;
19040 struct msi_msg;
19041@@ -180,7 +180,7 @@ struct x86_msi_ops {
19042 void (*teardown_msi_irqs)(struct pci_dev *dev);
19043 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
19044 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
19045-};
19046+} __no_const;
19047
19048 struct IO_APIC_route_entry;
19049 struct io_apic_irq_attr;
19050@@ -201,7 +201,7 @@ struct x86_io_apic_ops {
19051 unsigned int destination, int vector,
19052 struct io_apic_irq_attr *attr);
19053 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
19054-};
19055+} __no_const;
19056
19057 extern struct x86_init_ops x86_init;
19058 extern struct x86_cpuinit_ops x86_cpuinit;
19059diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
19060index 0415cda..3b22adc 100644
19061--- a/arch/x86/include/asm/xsave.h
19062+++ b/arch/x86/include/asm/xsave.h
19063@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19064 if (unlikely(err))
19065 return -EFAULT;
19066
19067+ pax_open_userland();
19068 __asm__ __volatile__(ASM_STAC "\n"
19069- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
19070+ "1:"
19071+ __copyuser_seg
19072+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
19073 "2: " ASM_CLAC "\n"
19074 ".section .fixup,\"ax\"\n"
19075 "3: movl $-1,%[err]\n"
19076@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19077 : [err] "=r" (err)
19078 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
19079 : "memory");
19080+ pax_close_userland();
19081 return err;
19082 }
19083
19084 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19085 {
19086 int err;
19087- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
19088+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
19089 u32 lmask = mask;
19090 u32 hmask = mask >> 32;
19091
19092+ pax_open_userland();
19093 __asm__ __volatile__(ASM_STAC "\n"
19094- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19095+ "1:"
19096+ __copyuser_seg
19097+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19098 "2: " ASM_CLAC "\n"
19099 ".section .fixup,\"ax\"\n"
19100 "3: movl $-1,%[err]\n"
19101@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19102 : [err] "=r" (err)
19103 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
19104 : "memory"); /* memory required? */
19105+ pax_close_userland();
19106 return err;
19107 }
19108
19109diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
19110index bbae024..e1528f9 100644
19111--- a/arch/x86/include/uapi/asm/e820.h
19112+++ b/arch/x86/include/uapi/asm/e820.h
19113@@ -63,7 +63,7 @@ struct e820map {
19114 #define ISA_START_ADDRESS 0xa0000
19115 #define ISA_END_ADDRESS 0x100000
19116
19117-#define BIOS_BEGIN 0x000a0000
19118+#define BIOS_BEGIN 0x000c0000
19119 #define BIOS_END 0x00100000
19120
19121 #define BIOS_ROM_BASE 0xffe00000
19122diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
19123index 7bd3bd3..5dac791 100644
19124--- a/arch/x86/kernel/Makefile
19125+++ b/arch/x86/kernel/Makefile
19126@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
19127 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
19128 obj-$(CONFIG_IRQ_WORK) += irq_work.o
19129 obj-y += probe_roms.o
19130-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
19131+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
19132 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
19133 obj-y += syscall_$(BITS).o
19134 obj-$(CONFIG_X86_64) += vsyscall_64.o
19135diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
19136index 230c8ea..f915130 100644
19137--- a/arch/x86/kernel/acpi/boot.c
19138+++ b/arch/x86/kernel/acpi/boot.c
19139@@ -1361,7 +1361,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
19140 * If your system is blacklisted here, but you find that acpi=force
19141 * works for you, please contact linux-acpi@vger.kernel.org
19142 */
19143-static struct dmi_system_id __initdata acpi_dmi_table[] = {
19144+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
19145 /*
19146 * Boxes that need ACPI disabled
19147 */
19148@@ -1436,7 +1436,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
19149 };
19150
19151 /* second table for DMI checks that should run after early-quirks */
19152-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
19153+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
19154 /*
19155 * HP laptops which use a DSDT reporting as HP/SB400/10000,
19156 * which includes some code which overrides all temperature
19157diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
19158index ec94e11..7fbbec0 100644
19159--- a/arch/x86/kernel/acpi/sleep.c
19160+++ b/arch/x86/kernel/acpi/sleep.c
19161@@ -88,8 +88,12 @@ int acpi_suspend_lowlevel(void)
19162 #else /* CONFIG_64BIT */
19163 #ifdef CONFIG_SMP
19164 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
19165+
19166+ pax_open_kernel();
19167 early_gdt_descr.address =
19168 (unsigned long)get_cpu_gdt_table(smp_processor_id());
19169+ pax_close_kernel();
19170+
19171 initial_gs = per_cpu_offset(smp_processor_id());
19172 #endif
19173 initial_code = (unsigned long)wakeup_long64;
19174diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
19175index d1daa66..59fecba 100644
19176--- a/arch/x86/kernel/acpi/wakeup_32.S
19177+++ b/arch/x86/kernel/acpi/wakeup_32.S
19178@@ -29,13 +29,11 @@ wakeup_pmode_return:
19179 # and restore the stack ... but you need gdt for this to work
19180 movl saved_context_esp, %esp
19181
19182- movl %cs:saved_magic, %eax
19183- cmpl $0x12345678, %eax
19184+ cmpl $0x12345678, saved_magic
19185 jne bogus_magic
19186
19187 # jump to place where we left off
19188- movl saved_eip, %eax
19189- jmp *%eax
19190+ jmp *(saved_eip)
19191
19192 bogus_magic:
19193 jmp bogus_magic
19194diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
19195index c15cf9a..0e63558 100644
19196--- a/arch/x86/kernel/alternative.c
19197+++ b/arch/x86/kernel/alternative.c
19198@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
19199 */
19200 for (a = start; a < end; a++) {
19201 instr = (u8 *)&a->instr_offset + a->instr_offset;
19202+
19203+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19204+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19205+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
19206+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19207+#endif
19208+
19209 replacement = (u8 *)&a->repl_offset + a->repl_offset;
19210 BUG_ON(a->replacementlen > a->instrlen);
19211 BUG_ON(a->instrlen > sizeof(insnbuf));
19212@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
19213 for (poff = start; poff < end; poff++) {
19214 u8 *ptr = (u8 *)poff + *poff;
19215
19216+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19217+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19218+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19219+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19220+#endif
19221+
19222 if (!*poff || ptr < text || ptr >= text_end)
19223 continue;
19224 /* turn DS segment override prefix into lock prefix */
19225- if (*ptr == 0x3e)
19226+ if (*ktla_ktva(ptr) == 0x3e)
19227 text_poke(ptr, ((unsigned char []){0xf0}), 1);
19228 }
19229 mutex_unlock(&text_mutex);
19230@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
19231 for (poff = start; poff < end; poff++) {
19232 u8 *ptr = (u8 *)poff + *poff;
19233
19234+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19235+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19236+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19237+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19238+#endif
19239+
19240 if (!*poff || ptr < text || ptr >= text_end)
19241 continue;
19242 /* turn lock prefix into DS segment override prefix */
19243- if (*ptr == 0xf0)
19244+ if (*ktla_ktva(ptr) == 0xf0)
19245 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19246 }
19247 mutex_unlock(&text_mutex);
19248@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19249
19250 BUG_ON(p->len > MAX_PATCH_LEN);
19251 /* prep the buffer with the original instructions */
19252- memcpy(insnbuf, p->instr, p->len);
19253+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19254 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19255 (unsigned long)p->instr, p->len);
19256
19257@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
19258 if (!uniproc_patched || num_possible_cpus() == 1)
19259 free_init_pages("SMP alternatives",
19260 (unsigned long)__smp_locks,
19261- (unsigned long)__smp_locks_end);
19262+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19263 #endif
19264
19265 apply_paravirt(__parainstructions, __parainstructions_end);
19266@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
19267 * instructions. And on the local CPU you need to be protected again NMI or MCE
19268 * handlers seeing an inconsistent instruction while you patch.
19269 */
19270-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19271+void *__kprobes text_poke_early(void *addr, const void *opcode,
19272 size_t len)
19273 {
19274 unsigned long flags;
19275 local_irq_save(flags);
19276- memcpy(addr, opcode, len);
19277+
19278+ pax_open_kernel();
19279+ memcpy(ktla_ktva(addr), opcode, len);
19280 sync_core();
19281+ pax_close_kernel();
19282+
19283 local_irq_restore(flags);
19284 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19285 that causes hangs on some VIA CPUs. */
19286@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19287 */
19288 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19289 {
19290- unsigned long flags;
19291- char *vaddr;
19292+ unsigned char *vaddr = ktla_ktva(addr);
19293 struct page *pages[2];
19294- int i;
19295+ size_t i;
19296
19297 if (!core_kernel_text((unsigned long)addr)) {
19298- pages[0] = vmalloc_to_page(addr);
19299- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19300+ pages[0] = vmalloc_to_page(vaddr);
19301+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19302 } else {
19303- pages[0] = virt_to_page(addr);
19304+ pages[0] = virt_to_page(vaddr);
19305 WARN_ON(!PageReserved(pages[0]));
19306- pages[1] = virt_to_page(addr + PAGE_SIZE);
19307+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19308 }
19309 BUG_ON(!pages[0]);
19310- local_irq_save(flags);
19311- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19312- if (pages[1])
19313- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19314- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19315- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19316- clear_fixmap(FIX_TEXT_POKE0);
19317- if (pages[1])
19318- clear_fixmap(FIX_TEXT_POKE1);
19319- local_flush_tlb();
19320- sync_core();
19321- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19322- that causes hangs on some VIA CPUs. */
19323+ text_poke_early(addr, opcode, len);
19324 for (i = 0; i < len; i++)
19325- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19326- local_irq_restore(flags);
19327+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19328 return addr;
19329 }
19330
19331diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19332index 904611b..004dde6 100644
19333--- a/arch/x86/kernel/apic/apic.c
19334+++ b/arch/x86/kernel/apic/apic.c
19335@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
19336 /*
19337 * Debug level, exported for io_apic.c
19338 */
19339-unsigned int apic_verbosity;
19340+int apic_verbosity;
19341
19342 int pic_mode;
19343
19344@@ -1955,7 +1955,7 @@ void smp_error_interrupt(struct pt_regs *regs)
19345 apic_write(APIC_ESR, 0);
19346 v1 = apic_read(APIC_ESR);
19347 ack_APIC_irq();
19348- atomic_inc(&irq_err_count);
19349+ atomic_inc_unchecked(&irq_err_count);
19350
19351 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19352 smp_processor_id(), v0 , v1);
19353diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19354index 00c77cf..2dc6a2d 100644
19355--- a/arch/x86/kernel/apic/apic_flat_64.c
19356+++ b/arch/x86/kernel/apic/apic_flat_64.c
19357@@ -157,7 +157,7 @@ static int flat_probe(void)
19358 return 1;
19359 }
19360
19361-static struct apic apic_flat = {
19362+static struct apic apic_flat __read_only = {
19363 .name = "flat",
19364 .probe = flat_probe,
19365 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19366@@ -271,7 +271,7 @@ static int physflat_probe(void)
19367 return 0;
19368 }
19369
19370-static struct apic apic_physflat = {
19371+static struct apic apic_physflat __read_only = {
19372
19373 .name = "physical flat",
19374 .probe = physflat_probe,
19375diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19376index e145f28..2752888 100644
19377--- a/arch/x86/kernel/apic/apic_noop.c
19378+++ b/arch/x86/kernel/apic/apic_noop.c
19379@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19380 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19381 }
19382
19383-struct apic apic_noop = {
19384+struct apic apic_noop __read_only = {
19385 .name = "noop",
19386 .probe = noop_probe,
19387 .acpi_madt_oem_check = NULL,
19388diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19389index d50e364..543bee3 100644
19390--- a/arch/x86/kernel/apic/bigsmp_32.c
19391+++ b/arch/x86/kernel/apic/bigsmp_32.c
19392@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19393 return dmi_bigsmp;
19394 }
19395
19396-static struct apic apic_bigsmp = {
19397+static struct apic apic_bigsmp __read_only = {
19398
19399 .name = "bigsmp",
19400 .probe = probe_bigsmp,
19401diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19402index 0874799..a7a7892 100644
19403--- a/arch/x86/kernel/apic/es7000_32.c
19404+++ b/arch/x86/kernel/apic/es7000_32.c
19405@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19406 return ret && es7000_apic_is_cluster();
19407 }
19408
19409-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19410-static struct apic __refdata apic_es7000_cluster = {
19411+static struct apic apic_es7000_cluster __read_only = {
19412
19413 .name = "es7000",
19414 .probe = probe_es7000,
19415@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19416 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19417 };
19418
19419-static struct apic __refdata apic_es7000 = {
19420+static struct apic apic_es7000 __read_only = {
19421
19422 .name = "es7000",
19423 .probe = probe_es7000,
19424diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19425index 9ed796c..e930fe4 100644
19426--- a/arch/x86/kernel/apic/io_apic.c
19427+++ b/arch/x86/kernel/apic/io_apic.c
19428@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19429 }
19430 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19431
19432-void lock_vector_lock(void)
19433+void lock_vector_lock(void) __acquires(vector_lock)
19434 {
19435 /* Used to the online set of cpus does not change
19436 * during assign_irq_vector.
19437@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19438 raw_spin_lock(&vector_lock);
19439 }
19440
19441-void unlock_vector_lock(void)
19442+void unlock_vector_lock(void) __releases(vector_lock)
19443 {
19444 raw_spin_unlock(&vector_lock);
19445 }
19446@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
19447 ack_APIC_irq();
19448 }
19449
19450-atomic_t irq_mis_count;
19451+atomic_unchecked_t irq_mis_count;
19452
19453 #ifdef CONFIG_GENERIC_PENDING_IRQ
19454 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19455@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
19456 * at the cpu.
19457 */
19458 if (!(v & (1 << (i & 0x1f)))) {
19459- atomic_inc(&irq_mis_count);
19460+ atomic_inc_unchecked(&irq_mis_count);
19461
19462 eoi_ioapic_irq(irq, cfg);
19463 }
19464diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19465index d661ee9..791fd33 100644
19466--- a/arch/x86/kernel/apic/numaq_32.c
19467+++ b/arch/x86/kernel/apic/numaq_32.c
19468@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19469 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19470 }
19471
19472-/* Use __refdata to keep false positive warning calm. */
19473-static struct apic __refdata apic_numaq = {
19474+static struct apic apic_numaq __read_only = {
19475
19476 .name = "NUMAQ",
19477 .probe = probe_numaq,
19478diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19479index eb35ef9..f184a21 100644
19480--- a/arch/x86/kernel/apic/probe_32.c
19481+++ b/arch/x86/kernel/apic/probe_32.c
19482@@ -72,7 +72,7 @@ static int probe_default(void)
19483 return 1;
19484 }
19485
19486-static struct apic apic_default = {
19487+static struct apic apic_default __read_only = {
19488
19489 .name = "default",
19490 .probe = probe_default,
19491diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19492index 77c95c0..434f8a4 100644
19493--- a/arch/x86/kernel/apic/summit_32.c
19494+++ b/arch/x86/kernel/apic/summit_32.c
19495@@ -486,7 +486,7 @@ void setup_summit(void)
19496 }
19497 #endif
19498
19499-static struct apic apic_summit = {
19500+static struct apic apic_summit __read_only = {
19501
19502 .name = "summit",
19503 .probe = probe_summit,
19504diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19505index c88baa4..757aee1 100644
19506--- a/arch/x86/kernel/apic/x2apic_cluster.c
19507+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19508@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19509 return notifier_from_errno(err);
19510 }
19511
19512-static struct notifier_block __refdata x2apic_cpu_notifier = {
19513+static struct notifier_block x2apic_cpu_notifier = {
19514 .notifier_call = update_clusterinfo,
19515 };
19516
19517@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19518 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19519 }
19520
19521-static struct apic apic_x2apic_cluster = {
19522+static struct apic apic_x2apic_cluster __read_only = {
19523
19524 .name = "cluster x2apic",
19525 .probe = x2apic_cluster_probe,
19526diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19527index 562a76d..a003c0f 100644
19528--- a/arch/x86/kernel/apic/x2apic_phys.c
19529+++ b/arch/x86/kernel/apic/x2apic_phys.c
19530@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19531 return apic == &apic_x2apic_phys;
19532 }
19533
19534-static struct apic apic_x2apic_phys = {
19535+static struct apic apic_x2apic_phys __read_only = {
19536
19537 .name = "physical x2apic",
19538 .probe = x2apic_phys_probe,
19539diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19540index 794f6eb..67e1db2 100644
19541--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19542+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19543@@ -342,7 +342,7 @@ static int uv_probe(void)
19544 return apic == &apic_x2apic_uv_x;
19545 }
19546
19547-static struct apic __refdata apic_x2apic_uv_x = {
19548+static struct apic apic_x2apic_uv_x __read_only = {
19549
19550 .name = "UV large system",
19551 .probe = uv_probe,
19552diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
19553index 53a4e27..038760a 100644
19554--- a/arch/x86/kernel/apm_32.c
19555+++ b/arch/x86/kernel/apm_32.c
19556@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
19557 * This is for buggy BIOS's that refer to (real mode) segment 0x40
19558 * even though they are called in protected mode.
19559 */
19560-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
19561+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
19562 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
19563
19564 static const char driver_version[] = "1.16ac"; /* no spaces */
19565@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
19566 BUG_ON(cpu != 0);
19567 gdt = get_cpu_gdt_table(cpu);
19568 save_desc_40 = gdt[0x40 / 8];
19569+
19570+ pax_open_kernel();
19571 gdt[0x40 / 8] = bad_bios_desc;
19572+ pax_close_kernel();
19573
19574 apm_irq_save(flags);
19575 APM_DO_SAVE_SEGS;
19576@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
19577 &call->esi);
19578 APM_DO_RESTORE_SEGS;
19579 apm_irq_restore(flags);
19580+
19581+ pax_open_kernel();
19582 gdt[0x40 / 8] = save_desc_40;
19583+ pax_close_kernel();
19584+
19585 put_cpu();
19586
19587 return call->eax & 0xff;
19588@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
19589 BUG_ON(cpu != 0);
19590 gdt = get_cpu_gdt_table(cpu);
19591 save_desc_40 = gdt[0x40 / 8];
19592+
19593+ pax_open_kernel();
19594 gdt[0x40 / 8] = bad_bios_desc;
19595+ pax_close_kernel();
19596
19597 apm_irq_save(flags);
19598 APM_DO_SAVE_SEGS;
19599@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
19600 &call->eax);
19601 APM_DO_RESTORE_SEGS;
19602 apm_irq_restore(flags);
19603+
19604+ pax_open_kernel();
19605 gdt[0x40 / 8] = save_desc_40;
19606+ pax_close_kernel();
19607+
19608 put_cpu();
19609 return error;
19610 }
19611@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
19612 * code to that CPU.
19613 */
19614 gdt = get_cpu_gdt_table(0);
19615+
19616+ pax_open_kernel();
19617 set_desc_base(&gdt[APM_CS >> 3],
19618 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
19619 set_desc_base(&gdt[APM_CS_16 >> 3],
19620 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
19621 set_desc_base(&gdt[APM_DS >> 3],
19622 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
19623+ pax_close_kernel();
19624
19625 proc_create("apm", 0, NULL, &apm_file_ops);
19626
19627diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
19628index 2861082..6d4718e 100644
19629--- a/arch/x86/kernel/asm-offsets.c
19630+++ b/arch/x86/kernel/asm-offsets.c
19631@@ -33,6 +33,8 @@ void common(void) {
19632 OFFSET(TI_status, thread_info, status);
19633 OFFSET(TI_addr_limit, thread_info, addr_limit);
19634 OFFSET(TI_preempt_count, thread_info, preempt_count);
19635+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
19636+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
19637
19638 BLANK();
19639 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
19640@@ -53,8 +55,26 @@ void common(void) {
19641 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
19642 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
19643 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
19644+
19645+#ifdef CONFIG_PAX_KERNEXEC
19646+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
19647 #endif
19648
19649+#ifdef CONFIG_PAX_MEMORY_UDEREF
19650+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
19651+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
19652+#ifdef CONFIG_X86_64
19653+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
19654+#endif
19655+#endif
19656+
19657+#endif
19658+
19659+ BLANK();
19660+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
19661+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
19662+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
19663+
19664 #ifdef CONFIG_XEN
19665 BLANK();
19666 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
19667diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
19668index e7c798b..2b2019b 100644
19669--- a/arch/x86/kernel/asm-offsets_64.c
19670+++ b/arch/x86/kernel/asm-offsets_64.c
19671@@ -77,6 +77,7 @@ int main(void)
19672 BLANK();
19673 #undef ENTRY
19674
19675+ DEFINE(TSS_size, sizeof(struct tss_struct));
19676 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
19677 BLANK();
19678
19679diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
19680index b0684e4..22ccfd7 100644
19681--- a/arch/x86/kernel/cpu/Makefile
19682+++ b/arch/x86/kernel/cpu/Makefile
19683@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
19684 CFLAGS_REMOVE_perf_event.o = -pg
19685 endif
19686
19687-# Make sure load_percpu_segment has no stackprotector
19688-nostackp := $(call cc-option, -fno-stack-protector)
19689-CFLAGS_common.o := $(nostackp)
19690-
19691 obj-y := intel_cacheinfo.o scattered.o topology.o
19692 obj-y += proc.o capflags.o powerflags.o common.o
19693 obj-y += rdrand.o
19694diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
19695index 5013a48..0782c53 100644
19696--- a/arch/x86/kernel/cpu/amd.c
19697+++ b/arch/x86/kernel/cpu/amd.c
19698@@ -744,7 +744,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
19699 unsigned int size)
19700 {
19701 /* AMD errata T13 (order #21922) */
19702- if ((c->x86 == 6)) {
19703+ if (c->x86 == 6) {
19704 /* Duron Rev A0 */
19705 if (c->x86_model == 3 && c->x86_mask == 0)
19706 size = 64;
19707diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
19708index 22018f7..df77e23 100644
19709--- a/arch/x86/kernel/cpu/common.c
19710+++ b/arch/x86/kernel/cpu/common.c
19711@@ -88,60 +88,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
19712
19713 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
19714
19715-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
19716-#ifdef CONFIG_X86_64
19717- /*
19718- * We need valid kernel segments for data and code in long mode too
19719- * IRET will check the segment types kkeil 2000/10/28
19720- * Also sysret mandates a special GDT layout
19721- *
19722- * TLS descriptors are currently at a different place compared to i386.
19723- * Hopefully nobody expects them at a fixed place (Wine?)
19724- */
19725- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
19726- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
19727- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
19728- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
19729- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
19730- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
19731-#else
19732- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
19733- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19734- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
19735- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
19736- /*
19737- * Segments used for calling PnP BIOS have byte granularity.
19738- * They code segments and data segments have fixed 64k limits,
19739- * the transfer segment sizes are set at run time.
19740- */
19741- /* 32-bit code */
19742- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19743- /* 16-bit code */
19744- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19745- /* 16-bit data */
19746- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
19747- /* 16-bit data */
19748- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
19749- /* 16-bit data */
19750- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
19751- /*
19752- * The APM segments have byte granularity and their bases
19753- * are set at run time. All have 64k limits.
19754- */
19755- /* 32-bit code */
19756- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19757- /* 16-bit code */
19758- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19759- /* data */
19760- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
19761-
19762- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19763- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19764- GDT_STACK_CANARY_INIT
19765-#endif
19766-} };
19767-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
19768-
19769 static int __init x86_xsave_setup(char *s)
19770 {
19771 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
19772@@ -288,6 +234,57 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
19773 set_in_cr4(X86_CR4_SMAP);
19774 }
19775
19776+#ifdef CONFIG_X86_64
19777+static __init int setup_disable_pcid(char *arg)
19778+{
19779+ setup_clear_cpu_cap(X86_FEATURE_PCID);
19780+
19781+#ifdef CONFIG_PAX_MEMORY_UDEREF
19782+ if (clone_pgd_mask != ~(pgdval_t)0UL)
19783+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19784+#endif
19785+
19786+ return 1;
19787+}
19788+__setup("nopcid", setup_disable_pcid);
19789+
19790+static void setup_pcid(struct cpuinfo_x86 *c)
19791+{
19792+ if (!cpu_has(c, X86_FEATURE_PCID)) {
19793+
19794+#ifdef CONFIG_PAX_MEMORY_UDEREF
19795+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
19796+ pax_open_kernel();
19797+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19798+ pax_close_kernel();
19799+ printk("PAX: slow and weak UDEREF enabled\n");
19800+ } else
19801+ printk("PAX: UDEREF disabled\n");
19802+#endif
19803+
19804+ return;
19805+ }
19806+
19807+ printk("PAX: PCID detected\n");
19808+ set_in_cr4(X86_CR4_PCIDE);
19809+
19810+#ifdef CONFIG_PAX_MEMORY_UDEREF
19811+ pax_open_kernel();
19812+ clone_pgd_mask = ~(pgdval_t)0UL;
19813+ pax_close_kernel();
19814+ if (pax_user_shadow_base)
19815+ printk("PAX: weak UDEREF enabled\n");
19816+ else {
19817+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
19818+ printk("PAX: strong UDEREF enabled\n");
19819+ }
19820+#endif
19821+
19822+ if (cpu_has(c, X86_FEATURE_INVPCID))
19823+ printk("PAX: INVPCID detected\n");
19824+}
19825+#endif
19826+
19827 /*
19828 * Some CPU features depend on higher CPUID levels, which may not always
19829 * be available due to CPUID level capping or broken virtualization
19830@@ -386,7 +383,7 @@ void switch_to_new_gdt(int cpu)
19831 {
19832 struct desc_ptr gdt_descr;
19833
19834- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
19835+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19836 gdt_descr.size = GDT_SIZE - 1;
19837 load_gdt(&gdt_descr);
19838 /* Reload the per-cpu base */
19839@@ -874,6 +871,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
19840 setup_smep(c);
19841 setup_smap(c);
19842
19843+#ifdef CONFIG_X86_64
19844+ setup_pcid(c);
19845+#endif
19846+
19847 /*
19848 * The vendor-specific functions might have changed features.
19849 * Now we do "generic changes."
19850@@ -882,6 +883,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
19851 /* Filter out anything that depends on CPUID levels we don't have */
19852 filter_cpuid_features(c, true);
19853
19854+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19855+ setup_clear_cpu_cap(X86_FEATURE_SEP);
19856+#endif
19857+
19858 /* If the model name is still unset, do table lookup. */
19859 if (!c->x86_model_id[0]) {
19860 const char *p;
19861@@ -1069,10 +1074,12 @@ static __init int setup_disablecpuid(char *arg)
19862 }
19863 __setup("clearcpuid=", setup_disablecpuid);
19864
19865+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
19866+EXPORT_PER_CPU_SYMBOL(current_tinfo);
19867+
19868 #ifdef CONFIG_X86_64
19869 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19870-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
19871- (unsigned long) nmi_idt_table };
19872+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
19873
19874 DEFINE_PER_CPU_FIRST(union irq_stack_union,
19875 irq_stack_union) __aligned(PAGE_SIZE);
19876@@ -1086,7 +1093,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
19877 EXPORT_PER_CPU_SYMBOL(current_task);
19878
19879 DEFINE_PER_CPU(unsigned long, kernel_stack) =
19880- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
19881+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
19882 EXPORT_PER_CPU_SYMBOL(kernel_stack);
19883
19884 DEFINE_PER_CPU(char *, irq_stack_ptr) =
19885@@ -1231,7 +1238,7 @@ void __cpuinit cpu_init(void)
19886 load_ucode_ap();
19887
19888 cpu = stack_smp_processor_id();
19889- t = &per_cpu(init_tss, cpu);
19890+ t = init_tss + cpu;
19891 oist = &per_cpu(orig_ist, cpu);
19892
19893 #ifdef CONFIG_NUMA
19894@@ -1257,7 +1264,7 @@ void __cpuinit cpu_init(void)
19895 switch_to_new_gdt(cpu);
19896 loadsegment(fs, 0);
19897
19898- load_idt((const struct desc_ptr *)&idt_descr);
19899+ load_idt(&idt_descr);
19900
19901 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
19902 syscall_init();
19903@@ -1266,7 +1273,6 @@ void __cpuinit cpu_init(void)
19904 wrmsrl(MSR_KERNEL_GS_BASE, 0);
19905 barrier();
19906
19907- x86_configure_nx();
19908 enable_x2apic();
19909
19910 /*
19911@@ -1318,7 +1324,7 @@ void __cpuinit cpu_init(void)
19912 {
19913 int cpu = smp_processor_id();
19914 struct task_struct *curr = current;
19915- struct tss_struct *t = &per_cpu(init_tss, cpu);
19916+ struct tss_struct *t = init_tss + cpu;
19917 struct thread_struct *thread = &curr->thread;
19918
19919 show_ucode_info_early();
19920diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
19921index 7c6f7d5..8cac382 100644
19922--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
19923+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
19924@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
19925 };
19926
19927 #ifdef CONFIG_AMD_NB
19928+static struct attribute *default_attrs_amd_nb[] = {
19929+ &type.attr,
19930+ &level.attr,
19931+ &coherency_line_size.attr,
19932+ &physical_line_partition.attr,
19933+ &ways_of_associativity.attr,
19934+ &number_of_sets.attr,
19935+ &size.attr,
19936+ &shared_cpu_map.attr,
19937+ &shared_cpu_list.attr,
19938+ NULL,
19939+ NULL,
19940+ NULL,
19941+ NULL
19942+};
19943+
19944 static struct attribute ** __cpuinit amd_l3_attrs(void)
19945 {
19946 static struct attribute **attrs;
19947@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
19948
19949 n = ARRAY_SIZE(default_attrs);
19950
19951- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
19952- n += 2;
19953-
19954- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
19955- n += 1;
19956-
19957- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
19958- if (attrs == NULL)
19959- return attrs = default_attrs;
19960-
19961- for (n = 0; default_attrs[n]; n++)
19962- attrs[n] = default_attrs[n];
19963+ attrs = default_attrs_amd_nb;
19964
19965 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
19966 attrs[n++] = &cache_disable_0.attr;
19967@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
19968 .default_attrs = default_attrs,
19969 };
19970
19971+#ifdef CONFIG_AMD_NB
19972+static struct kobj_type ktype_cache_amd_nb = {
19973+ .sysfs_ops = &sysfs_ops,
19974+ .default_attrs = default_attrs_amd_nb,
19975+};
19976+#endif
19977+
19978 static struct kobj_type ktype_percpu_entry = {
19979 .sysfs_ops = &sysfs_ops,
19980 };
19981@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
19982 return retval;
19983 }
19984
19985+#ifdef CONFIG_AMD_NB
19986+ amd_l3_attrs();
19987+#endif
19988+
19989 for (i = 0; i < num_cache_leaves; i++) {
19990+ struct kobj_type *ktype;
19991+
19992 this_object = INDEX_KOBJECT_PTR(cpu, i);
19993 this_object->cpu = cpu;
19994 this_object->index = i;
19995
19996 this_leaf = CPUID4_INFO_IDX(cpu, i);
19997
19998- ktype_cache.default_attrs = default_attrs;
19999+ ktype = &ktype_cache;
20000 #ifdef CONFIG_AMD_NB
20001 if (this_leaf->base.nb)
20002- ktype_cache.default_attrs = amd_l3_attrs();
20003+ ktype = &ktype_cache_amd_nb;
20004 #endif
20005 retval = kobject_init_and_add(&(this_object->kobj),
20006- &ktype_cache,
20007+ ktype,
20008 per_cpu(ici_cache_kobject, cpu),
20009 "index%1lu", i);
20010 if (unlikely(retval)) {
20011@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
20012 return NOTIFY_OK;
20013 }
20014
20015-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
20016+static struct notifier_block cacheinfo_cpu_notifier = {
20017 .notifier_call = cacheinfo_cpu_callback,
20018 };
20019
20020diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
20021index 9239504..b2471ce 100644
20022--- a/arch/x86/kernel/cpu/mcheck/mce.c
20023+++ b/arch/x86/kernel/cpu/mcheck/mce.c
20024@@ -45,6 +45,7 @@
20025 #include <asm/processor.h>
20026 #include <asm/mce.h>
20027 #include <asm/msr.h>
20028+#include <asm/local.h>
20029
20030 #include "mce-internal.h"
20031
20032@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
20033 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
20034 m->cs, m->ip);
20035
20036- if (m->cs == __KERNEL_CS)
20037+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
20038 print_symbol("{%s}", m->ip);
20039 pr_cont("\n");
20040 }
20041@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
20042
20043 #define PANIC_TIMEOUT 5 /* 5 seconds */
20044
20045-static atomic_t mce_paniced;
20046+static atomic_unchecked_t mce_paniced;
20047
20048 static int fake_panic;
20049-static atomic_t mce_fake_paniced;
20050+static atomic_unchecked_t mce_fake_paniced;
20051
20052 /* Panic in progress. Enable interrupts and wait for final IPI */
20053 static void wait_for_panic(void)
20054@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20055 /*
20056 * Make sure only one CPU runs in machine check panic
20057 */
20058- if (atomic_inc_return(&mce_paniced) > 1)
20059+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
20060 wait_for_panic();
20061 barrier();
20062
20063@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20064 console_verbose();
20065 } else {
20066 /* Don't log too much for fake panic */
20067- if (atomic_inc_return(&mce_fake_paniced) > 1)
20068+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
20069 return;
20070 }
20071 /* First print corrected ones that are still unlogged */
20072@@ -353,7 +354,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20073 if (!fake_panic) {
20074 if (panic_timeout == 0)
20075 panic_timeout = mca_cfg.panic_timeout;
20076- panic(msg);
20077+ panic("%s", msg);
20078 } else
20079 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
20080 }
20081@@ -683,7 +684,7 @@ static int mce_timed_out(u64 *t)
20082 * might have been modified by someone else.
20083 */
20084 rmb();
20085- if (atomic_read(&mce_paniced))
20086+ if (atomic_read_unchecked(&mce_paniced))
20087 wait_for_panic();
20088 if (!mca_cfg.monarch_timeout)
20089 goto out;
20090@@ -1654,7 +1655,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
20091 }
20092
20093 /* Call the installed machine check handler for this CPU setup. */
20094-void (*machine_check_vector)(struct pt_regs *, long error_code) =
20095+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
20096 unexpected_machine_check;
20097
20098 /*
20099@@ -1677,7 +1678,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
20100 return;
20101 }
20102
20103+ pax_open_kernel();
20104 machine_check_vector = do_machine_check;
20105+ pax_close_kernel();
20106
20107 __mcheck_cpu_init_generic();
20108 __mcheck_cpu_init_vendor(c);
20109@@ -1691,7 +1694,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
20110 */
20111
20112 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
20113-static int mce_chrdev_open_count; /* #times opened */
20114+static local_t mce_chrdev_open_count; /* #times opened */
20115 static int mce_chrdev_open_exclu; /* already open exclusive? */
20116
20117 static int mce_chrdev_open(struct inode *inode, struct file *file)
20118@@ -1699,7 +1702,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20119 spin_lock(&mce_chrdev_state_lock);
20120
20121 if (mce_chrdev_open_exclu ||
20122- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
20123+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
20124 spin_unlock(&mce_chrdev_state_lock);
20125
20126 return -EBUSY;
20127@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20128
20129 if (file->f_flags & O_EXCL)
20130 mce_chrdev_open_exclu = 1;
20131- mce_chrdev_open_count++;
20132+ local_inc(&mce_chrdev_open_count);
20133
20134 spin_unlock(&mce_chrdev_state_lock);
20135
20136@@ -1718,7 +1721,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
20137 {
20138 spin_lock(&mce_chrdev_state_lock);
20139
20140- mce_chrdev_open_count--;
20141+ local_dec(&mce_chrdev_open_count);
20142 mce_chrdev_open_exclu = 0;
20143
20144 spin_unlock(&mce_chrdev_state_lock);
20145@@ -2364,7 +2367,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
20146 return NOTIFY_OK;
20147 }
20148
20149-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
20150+static struct notifier_block mce_cpu_notifier = {
20151 .notifier_call = mce_cpu_callback,
20152 };
20153
20154@@ -2374,7 +2377,7 @@ static __init void mce_init_banks(void)
20155
20156 for (i = 0; i < mca_cfg.banks; i++) {
20157 struct mce_bank *b = &mce_banks[i];
20158- struct device_attribute *a = &b->attr;
20159+ device_attribute_no_const *a = &b->attr;
20160
20161 sysfs_attr_init(&a->attr);
20162 a->attr.name = b->attrname;
20163@@ -2442,7 +2445,7 @@ struct dentry *mce_get_debugfs_dir(void)
20164 static void mce_reset(void)
20165 {
20166 cpu_missing = 0;
20167- atomic_set(&mce_fake_paniced, 0);
20168+ atomic_set_unchecked(&mce_fake_paniced, 0);
20169 atomic_set(&mce_executing, 0);
20170 atomic_set(&mce_callin, 0);
20171 atomic_set(&global_nwo, 0);
20172diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
20173index 1c044b1..37a2a43 100644
20174--- a/arch/x86/kernel/cpu/mcheck/p5.c
20175+++ b/arch/x86/kernel/cpu/mcheck/p5.c
20176@@ -11,6 +11,7 @@
20177 #include <asm/processor.h>
20178 #include <asm/mce.h>
20179 #include <asm/msr.h>
20180+#include <asm/pgtable.h>
20181
20182 /* By default disabled */
20183 int mce_p5_enabled __read_mostly;
20184@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
20185 if (!cpu_has(c, X86_FEATURE_MCE))
20186 return;
20187
20188+ pax_open_kernel();
20189 machine_check_vector = pentium_machine_check;
20190+ pax_close_kernel();
20191 /* Make sure the vector pointer is visible before we enable MCEs: */
20192 wmb();
20193
20194diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
20195index 47a1870..8c019a7 100644
20196--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
20197+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
20198@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
20199 return notifier_from_errno(err);
20200 }
20201
20202-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
20203+static struct notifier_block thermal_throttle_cpu_notifier =
20204 {
20205 .notifier_call = thermal_throttle_cpu_callback,
20206 };
20207diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
20208index e9a701a..35317d6 100644
20209--- a/arch/x86/kernel/cpu/mcheck/winchip.c
20210+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
20211@@ -10,6 +10,7 @@
20212 #include <asm/processor.h>
20213 #include <asm/mce.h>
20214 #include <asm/msr.h>
20215+#include <asm/pgtable.h>
20216
20217 /* Machine check handler for WinChip C6: */
20218 static void winchip_machine_check(struct pt_regs *regs, long error_code)
20219@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
20220 {
20221 u32 lo, hi;
20222
20223+ pax_open_kernel();
20224 machine_check_vector = winchip_machine_check;
20225+ pax_close_kernel();
20226 /* Make sure the vector pointer is visible before we enable MCEs: */
20227 wmb();
20228
20229diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
20230index ca22b73..9987afe 100644
20231--- a/arch/x86/kernel/cpu/mtrr/main.c
20232+++ b/arch/x86/kernel/cpu/mtrr/main.c
20233@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
20234 u64 size_or_mask, size_and_mask;
20235 static bool mtrr_aps_delayed_init;
20236
20237-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
20238+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
20239
20240 const struct mtrr_ops *mtrr_if;
20241
20242diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
20243index df5e41f..816c719 100644
20244--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
20245+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
20246@@ -25,7 +25,7 @@ struct mtrr_ops {
20247 int (*validate_add_page)(unsigned long base, unsigned long size,
20248 unsigned int type);
20249 int (*have_wrcomb)(void);
20250-};
20251+} __do_const;
20252
20253 extern int generic_get_free_region(unsigned long base, unsigned long size,
20254 int replace_reg);
20255diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
20256index 1025f3c..824f677 100644
20257--- a/arch/x86/kernel/cpu/perf_event.c
20258+++ b/arch/x86/kernel/cpu/perf_event.c
20259@@ -1311,7 +1311,7 @@ static void __init pmu_check_apic(void)
20260 pr_info("no hardware sampling interrupt available.\n");
20261 }
20262
20263-static struct attribute_group x86_pmu_format_group = {
20264+static attribute_group_no_const x86_pmu_format_group = {
20265 .name = "format",
20266 .attrs = NULL,
20267 };
20268@@ -1410,7 +1410,7 @@ static struct attribute *events_attr[] = {
20269 NULL,
20270 };
20271
20272-static struct attribute_group x86_pmu_events_group = {
20273+static attribute_group_no_const x86_pmu_events_group = {
20274 .name = "events",
20275 .attrs = events_attr,
20276 };
20277@@ -1920,7 +1920,7 @@ static unsigned long get_segment_base(unsigned int segment)
20278 if (idx > GDT_ENTRIES)
20279 return 0;
20280
20281- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20282+ desc = get_cpu_gdt_table(smp_processor_id());
20283 }
20284
20285 return get_desc_base(desc + idx);
20286@@ -2010,7 +2010,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20287 break;
20288
20289 perf_callchain_store(entry, frame.return_address);
20290- fp = frame.next_frame;
20291+ fp = (const void __force_user *)frame.next_frame;
20292 }
20293 }
20294
20295diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20296index a9e2207..d70c83a 100644
20297--- a/arch/x86/kernel/cpu/perf_event_intel.c
20298+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20299@@ -2022,10 +2022,10 @@ __init int intel_pmu_init(void)
20300 * v2 and above have a perf capabilities MSR
20301 */
20302 if (version > 1) {
20303- u64 capabilities;
20304+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20305
20306- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20307- x86_pmu.intel_cap.capabilities = capabilities;
20308+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20309+ x86_pmu.intel_cap.capabilities = capabilities;
20310 }
20311
20312 intel_ds_init();
20313diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20314index 8aac56b..588fb13 100644
20315--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20316+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20317@@ -3093,7 +3093,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20318 static int __init uncore_type_init(struct intel_uncore_type *type)
20319 {
20320 struct intel_uncore_pmu *pmus;
20321- struct attribute_group *attr_group;
20322+ attribute_group_no_const *attr_group;
20323 struct attribute **attrs;
20324 int i, j;
20325
20326@@ -3518,7 +3518,7 @@ static int
20327 return NOTIFY_OK;
20328 }
20329
20330-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
20331+static struct notifier_block uncore_cpu_nb = {
20332 .notifier_call = uncore_cpu_notifier,
20333 /*
20334 * to migrate uncore events, our notifier should be executed
20335diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20336index f952891..4722ad4 100644
20337--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20338+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20339@@ -488,7 +488,7 @@ struct intel_uncore_box {
20340 struct uncore_event_desc {
20341 struct kobj_attribute attr;
20342 const char *config;
20343-};
20344+} __do_const;
20345
20346 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20347 { \
20348diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20349index 1e4dbcf..b9a34c2 100644
20350--- a/arch/x86/kernel/cpuid.c
20351+++ b/arch/x86/kernel/cpuid.c
20352@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
20353 return notifier_from_errno(err);
20354 }
20355
20356-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20357+static struct notifier_block cpuid_class_cpu_notifier =
20358 {
20359 .notifier_call = cpuid_class_cpu_callback,
20360 };
20361diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20362index 74467fe..18793d5 100644
20363--- a/arch/x86/kernel/crash.c
20364+++ b/arch/x86/kernel/crash.c
20365@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20366 {
20367 #ifdef CONFIG_X86_32
20368 struct pt_regs fixed_regs;
20369-#endif
20370
20371-#ifdef CONFIG_X86_32
20372- if (!user_mode_vm(regs)) {
20373+ if (!user_mode(regs)) {
20374 crash_fixup_ss_esp(&fixed_regs, regs);
20375 regs = &fixed_regs;
20376 }
20377diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20378index afa64ad..dce67dd 100644
20379--- a/arch/x86/kernel/crash_dump_64.c
20380+++ b/arch/x86/kernel/crash_dump_64.c
20381@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20382 return -ENOMEM;
20383
20384 if (userbuf) {
20385- if (copy_to_user(buf, vaddr + offset, csize)) {
20386+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20387 iounmap(vaddr);
20388 return -EFAULT;
20389 }
20390diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
20391index 155a13f..1672b9b 100644
20392--- a/arch/x86/kernel/doublefault_32.c
20393+++ b/arch/x86/kernel/doublefault_32.c
20394@@ -11,7 +11,7 @@
20395
20396 #define DOUBLEFAULT_STACKSIZE (1024)
20397 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20398-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20399+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20400
20401 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20402
20403@@ -21,7 +21,7 @@ static void doublefault_fn(void)
20404 unsigned long gdt, tss;
20405
20406 native_store_gdt(&gdt_desc);
20407- gdt = gdt_desc.address;
20408+ gdt = (unsigned long)gdt_desc.address;
20409
20410 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20411
20412@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20413 /* 0x2 bit is always set */
20414 .flags = X86_EFLAGS_SF | 0x2,
20415 .sp = STACK_START,
20416- .es = __USER_DS,
20417+ .es = __KERNEL_DS,
20418 .cs = __KERNEL_CS,
20419 .ss = __KERNEL_DS,
20420- .ds = __USER_DS,
20421+ .ds = __KERNEL_DS,
20422 .fs = __KERNEL_PERCPU,
20423
20424 .__cr3 = __pa_nodebug(swapper_pg_dir),
20425diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20426index deb6421..76bbc12 100644
20427--- a/arch/x86/kernel/dumpstack.c
20428+++ b/arch/x86/kernel/dumpstack.c
20429@@ -2,6 +2,9 @@
20430 * Copyright (C) 1991, 1992 Linus Torvalds
20431 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20432 */
20433+#ifdef CONFIG_GRKERNSEC_HIDESYM
20434+#define __INCLUDED_BY_HIDESYM 1
20435+#endif
20436 #include <linux/kallsyms.h>
20437 #include <linux/kprobes.h>
20438 #include <linux/uaccess.h>
20439@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20440 static void
20441 print_ftrace_graph_addr(unsigned long addr, void *data,
20442 const struct stacktrace_ops *ops,
20443- struct thread_info *tinfo, int *graph)
20444+ struct task_struct *task, int *graph)
20445 {
20446- struct task_struct *task;
20447 unsigned long ret_addr;
20448 int index;
20449
20450 if (addr != (unsigned long)return_to_handler)
20451 return;
20452
20453- task = tinfo->task;
20454 index = task->curr_ret_stack;
20455
20456 if (!task->ret_stack || index < *graph)
20457@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20458 static inline void
20459 print_ftrace_graph_addr(unsigned long addr, void *data,
20460 const struct stacktrace_ops *ops,
20461- struct thread_info *tinfo, int *graph)
20462+ struct task_struct *task, int *graph)
20463 { }
20464 #endif
20465
20466@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20467 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20468 */
20469
20470-static inline int valid_stack_ptr(struct thread_info *tinfo,
20471- void *p, unsigned int size, void *end)
20472+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20473 {
20474- void *t = tinfo;
20475 if (end) {
20476 if (p < end && p >= (end-THREAD_SIZE))
20477 return 1;
20478@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20479 }
20480
20481 unsigned long
20482-print_context_stack(struct thread_info *tinfo,
20483+print_context_stack(struct task_struct *task, void *stack_start,
20484 unsigned long *stack, unsigned long bp,
20485 const struct stacktrace_ops *ops, void *data,
20486 unsigned long *end, int *graph)
20487 {
20488 struct stack_frame *frame = (struct stack_frame *)bp;
20489
20490- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20491+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20492 unsigned long addr;
20493
20494 addr = *stack;
20495@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20496 } else {
20497 ops->address(data, addr, 0);
20498 }
20499- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20500+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20501 }
20502 stack++;
20503 }
20504@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20505 EXPORT_SYMBOL_GPL(print_context_stack);
20506
20507 unsigned long
20508-print_context_stack_bp(struct thread_info *tinfo,
20509+print_context_stack_bp(struct task_struct *task, void *stack_start,
20510 unsigned long *stack, unsigned long bp,
20511 const struct stacktrace_ops *ops, void *data,
20512 unsigned long *end, int *graph)
20513@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20514 struct stack_frame *frame = (struct stack_frame *)bp;
20515 unsigned long *ret_addr = &frame->return_address;
20516
20517- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20518+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20519 unsigned long addr = *ret_addr;
20520
20521 if (!__kernel_text_address(addr))
20522@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20523 ops->address(data, addr, 1);
20524 frame = frame->next_frame;
20525 ret_addr = &frame->return_address;
20526- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20527+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20528 }
20529
20530 return (unsigned long)frame;
20531@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20532 static void print_trace_address(void *data, unsigned long addr, int reliable)
20533 {
20534 touch_nmi_watchdog();
20535- printk(data);
20536+ printk("%s", (char *)data);
20537 printk_address(addr, reliable);
20538 }
20539
20540@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20541 }
20542 EXPORT_SYMBOL_GPL(oops_begin);
20543
20544+extern void gr_handle_kernel_exploit(void);
20545+
20546 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20547 {
20548 if (regs && kexec_should_crash(current))
20549@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20550 panic("Fatal exception in interrupt");
20551 if (panic_on_oops)
20552 panic("Fatal exception");
20553- do_exit(signr);
20554+
20555+ gr_handle_kernel_exploit();
20556+
20557+ do_group_exit(signr);
20558 }
20559
20560 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20561@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20562 print_modules();
20563 show_regs(regs);
20564 #ifdef CONFIG_X86_32
20565- if (user_mode_vm(regs)) {
20566+ if (user_mode(regs)) {
20567 sp = regs->sp;
20568 ss = regs->ss & 0xffff;
20569 } else {
20570@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20571 unsigned long flags = oops_begin();
20572 int sig = SIGSEGV;
20573
20574- if (!user_mode_vm(regs))
20575+ if (!user_mode(regs))
20576 report_bug(regs->ip, regs);
20577
20578 if (__die(str, regs, err))
20579diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20580index f2a1770..540657f 100644
20581--- a/arch/x86/kernel/dumpstack_32.c
20582+++ b/arch/x86/kernel/dumpstack_32.c
20583@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20584 bp = stack_frame(task, regs);
20585
20586 for (;;) {
20587- struct thread_info *context;
20588+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20589
20590- context = (struct thread_info *)
20591- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20592- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20593+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20594
20595- stack = (unsigned long *)context->previous_esp;
20596- if (!stack)
20597+ if (stack_start == task_stack_page(task))
20598 break;
20599+ stack = *(unsigned long **)stack_start;
20600 if (ops->stack(data, "IRQ") < 0)
20601 break;
20602 touch_nmi_watchdog();
20603@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20604 int i;
20605
20606 show_regs_print_info(KERN_EMERG);
20607- __show_regs(regs, !user_mode_vm(regs));
20608+ __show_regs(regs, !user_mode(regs));
20609
20610 /*
20611 * When in-kernel, we also print out the stack and code at the
20612 * time of the fault..
20613 */
20614- if (!user_mode_vm(regs)) {
20615+ if (!user_mode(regs)) {
20616 unsigned int code_prologue = code_bytes * 43 / 64;
20617 unsigned int code_len = code_bytes;
20618 unsigned char c;
20619 u8 *ip;
20620+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20621
20622 pr_emerg("Stack:\n");
20623 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20624
20625 pr_emerg("Code:");
20626
20627- ip = (u8 *)regs->ip - code_prologue;
20628+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20629 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20630 /* try starting at IP */
20631- ip = (u8 *)regs->ip;
20632+ ip = (u8 *)regs->ip + cs_base;
20633 code_len = code_len - code_prologue + 1;
20634 }
20635 for (i = 0; i < code_len; i++, ip++) {
20636@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20637 pr_cont(" Bad EIP value.");
20638 break;
20639 }
20640- if (ip == (u8 *)regs->ip)
20641+ if (ip == (u8 *)regs->ip + cs_base)
20642 pr_cont(" <%02x>", c);
20643 else
20644 pr_cont(" %02x", c);
20645@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20646 {
20647 unsigned short ud2;
20648
20649+ ip = ktla_ktva(ip);
20650 if (ip < PAGE_OFFSET)
20651 return 0;
20652 if (probe_kernel_address((unsigned short *)ip, ud2))
20653@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20654
20655 return ud2 == 0x0b0f;
20656 }
20657+
20658+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20659+void pax_check_alloca(unsigned long size)
20660+{
20661+ unsigned long sp = (unsigned long)&sp, stack_left;
20662+
20663+ /* all kernel stacks are of the same size */
20664+ stack_left = sp & (THREAD_SIZE - 1);
20665+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20666+}
20667+EXPORT_SYMBOL(pax_check_alloca);
20668+#endif
20669diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20670index addb207..99635fa 100644
20671--- a/arch/x86/kernel/dumpstack_64.c
20672+++ b/arch/x86/kernel/dumpstack_64.c
20673@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20674 unsigned long *irq_stack_end =
20675 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20676 unsigned used = 0;
20677- struct thread_info *tinfo;
20678 int graph = 0;
20679 unsigned long dummy;
20680+ void *stack_start;
20681
20682 if (!task)
20683 task = current;
20684@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20685 * current stack address. If the stacks consist of nested
20686 * exceptions
20687 */
20688- tinfo = task_thread_info(task);
20689 for (;;) {
20690 char *id;
20691 unsigned long *estack_end;
20692+
20693 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20694 &used, &id);
20695
20696@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20697 if (ops->stack(data, id) < 0)
20698 break;
20699
20700- bp = ops->walk_stack(tinfo, stack, bp, ops,
20701+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20702 data, estack_end, &graph);
20703 ops->stack(data, "<EOE>");
20704 /*
20705@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20706 * second-to-last pointer (index -2 to end) in the
20707 * exception stack:
20708 */
20709+ if ((u16)estack_end[-1] != __KERNEL_DS)
20710+ goto out;
20711 stack = (unsigned long *) estack_end[-2];
20712 continue;
20713 }
20714@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20715 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20716 if (ops->stack(data, "IRQ") < 0)
20717 break;
20718- bp = ops->walk_stack(tinfo, stack, bp,
20719+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20720 ops, data, irq_stack_end, &graph);
20721 /*
20722 * We link to the next stack (which would be
20723@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20724 /*
20725 * This handles the process stack:
20726 */
20727- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20728+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20729+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20730+out:
20731 put_cpu();
20732 }
20733 EXPORT_SYMBOL(dump_trace);
20734@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20735
20736 return ud2 == 0x0b0f;
20737 }
20738+
20739+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20740+void pax_check_alloca(unsigned long size)
20741+{
20742+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20743+ unsigned cpu, used;
20744+ char *id;
20745+
20746+ /* check the process stack first */
20747+ stack_start = (unsigned long)task_stack_page(current);
20748+ stack_end = stack_start + THREAD_SIZE;
20749+ if (likely(stack_start <= sp && sp < stack_end)) {
20750+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20751+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20752+ return;
20753+ }
20754+
20755+ cpu = get_cpu();
20756+
20757+ /* check the irq stacks */
20758+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20759+ stack_start = stack_end - IRQ_STACK_SIZE;
20760+ if (stack_start <= sp && sp < stack_end) {
20761+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20762+ put_cpu();
20763+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20764+ return;
20765+ }
20766+
20767+ /* check the exception stacks */
20768+ used = 0;
20769+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20770+ stack_start = stack_end - EXCEPTION_STKSZ;
20771+ if (stack_end && stack_start <= sp && sp < stack_end) {
20772+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20773+ put_cpu();
20774+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20775+ return;
20776+ }
20777+
20778+ put_cpu();
20779+
20780+ /* unknown stack */
20781+ BUG();
20782+}
20783+EXPORT_SYMBOL(pax_check_alloca);
20784+#endif
20785diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20786index d32abea..74daf4f 100644
20787--- a/arch/x86/kernel/e820.c
20788+++ b/arch/x86/kernel/e820.c
20789@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20790
20791 static void early_panic(char *msg)
20792 {
20793- early_printk(msg);
20794- panic(msg);
20795+ early_printk("%s", msg);
20796+ panic("%s", msg);
20797 }
20798
20799 static int userdef __initdata;
20800diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20801index d15f575..d692043 100644
20802--- a/arch/x86/kernel/early_printk.c
20803+++ b/arch/x86/kernel/early_printk.c
20804@@ -7,6 +7,7 @@
20805 #include <linux/pci_regs.h>
20806 #include <linux/pci_ids.h>
20807 #include <linux/errno.h>
20808+#include <linux/sched.h>
20809 #include <asm/io.h>
20810 #include <asm/processor.h>
20811 #include <asm/fcntl.h>
20812diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20813index 8f3e2de..6b71e39 100644
20814--- a/arch/x86/kernel/entry_32.S
20815+++ b/arch/x86/kernel/entry_32.S
20816@@ -177,13 +177,153 @@
20817 /*CFI_REL_OFFSET gs, PT_GS*/
20818 .endm
20819 .macro SET_KERNEL_GS reg
20820+
20821+#ifdef CONFIG_CC_STACKPROTECTOR
20822 movl $(__KERNEL_STACK_CANARY), \reg
20823+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20824+ movl $(__USER_DS), \reg
20825+#else
20826+ xorl \reg, \reg
20827+#endif
20828+
20829 movl \reg, %gs
20830 .endm
20831
20832 #endif /* CONFIG_X86_32_LAZY_GS */
20833
20834-.macro SAVE_ALL
20835+.macro pax_enter_kernel
20836+#ifdef CONFIG_PAX_KERNEXEC
20837+ call pax_enter_kernel
20838+#endif
20839+.endm
20840+
20841+.macro pax_exit_kernel
20842+#ifdef CONFIG_PAX_KERNEXEC
20843+ call pax_exit_kernel
20844+#endif
20845+.endm
20846+
20847+#ifdef CONFIG_PAX_KERNEXEC
20848+ENTRY(pax_enter_kernel)
20849+#ifdef CONFIG_PARAVIRT
20850+ pushl %eax
20851+ pushl %ecx
20852+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20853+ mov %eax, %esi
20854+#else
20855+ mov %cr0, %esi
20856+#endif
20857+ bts $16, %esi
20858+ jnc 1f
20859+ mov %cs, %esi
20860+ cmp $__KERNEL_CS, %esi
20861+ jz 3f
20862+ ljmp $__KERNEL_CS, $3f
20863+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20864+2:
20865+#ifdef CONFIG_PARAVIRT
20866+ mov %esi, %eax
20867+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20868+#else
20869+ mov %esi, %cr0
20870+#endif
20871+3:
20872+#ifdef CONFIG_PARAVIRT
20873+ popl %ecx
20874+ popl %eax
20875+#endif
20876+ ret
20877+ENDPROC(pax_enter_kernel)
20878+
20879+ENTRY(pax_exit_kernel)
20880+#ifdef CONFIG_PARAVIRT
20881+ pushl %eax
20882+ pushl %ecx
20883+#endif
20884+ mov %cs, %esi
20885+ cmp $__KERNEXEC_KERNEL_CS, %esi
20886+ jnz 2f
20887+#ifdef CONFIG_PARAVIRT
20888+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20889+ mov %eax, %esi
20890+#else
20891+ mov %cr0, %esi
20892+#endif
20893+ btr $16, %esi
20894+ ljmp $__KERNEL_CS, $1f
20895+1:
20896+#ifdef CONFIG_PARAVIRT
20897+ mov %esi, %eax
20898+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20899+#else
20900+ mov %esi, %cr0
20901+#endif
20902+2:
20903+#ifdef CONFIG_PARAVIRT
20904+ popl %ecx
20905+ popl %eax
20906+#endif
20907+ ret
20908+ENDPROC(pax_exit_kernel)
20909+#endif
20910+
20911+ .macro pax_erase_kstack
20912+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20913+ call pax_erase_kstack
20914+#endif
20915+ .endm
20916+
20917+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20918+/*
20919+ * ebp: thread_info
20920+ */
20921+ENTRY(pax_erase_kstack)
20922+ pushl %edi
20923+ pushl %ecx
20924+ pushl %eax
20925+
20926+ mov TI_lowest_stack(%ebp), %edi
20927+ mov $-0xBEEF, %eax
20928+ std
20929+
20930+1: mov %edi, %ecx
20931+ and $THREAD_SIZE_asm - 1, %ecx
20932+ shr $2, %ecx
20933+ repne scasl
20934+ jecxz 2f
20935+
20936+ cmp $2*16, %ecx
20937+ jc 2f
20938+
20939+ mov $2*16, %ecx
20940+ repe scasl
20941+ jecxz 2f
20942+ jne 1b
20943+
20944+2: cld
20945+ mov %esp, %ecx
20946+ sub %edi, %ecx
20947+
20948+ cmp $THREAD_SIZE_asm, %ecx
20949+ jb 3f
20950+ ud2
20951+3:
20952+
20953+ shr $2, %ecx
20954+ rep stosl
20955+
20956+ mov TI_task_thread_sp0(%ebp), %edi
20957+ sub $128, %edi
20958+ mov %edi, TI_lowest_stack(%ebp)
20959+
20960+ popl %eax
20961+ popl %ecx
20962+ popl %edi
20963+ ret
20964+ENDPROC(pax_erase_kstack)
20965+#endif
20966+
20967+.macro __SAVE_ALL _DS
20968 cld
20969 PUSH_GS
20970 pushl_cfi %fs
20971@@ -206,7 +346,7 @@
20972 CFI_REL_OFFSET ecx, 0
20973 pushl_cfi %ebx
20974 CFI_REL_OFFSET ebx, 0
20975- movl $(__USER_DS), %edx
20976+ movl $\_DS, %edx
20977 movl %edx, %ds
20978 movl %edx, %es
20979 movl $(__KERNEL_PERCPU), %edx
20980@@ -214,6 +354,15 @@
20981 SET_KERNEL_GS %edx
20982 .endm
20983
20984+.macro SAVE_ALL
20985+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20986+ __SAVE_ALL __KERNEL_DS
20987+ pax_enter_kernel
20988+#else
20989+ __SAVE_ALL __USER_DS
20990+#endif
20991+.endm
20992+
20993 .macro RESTORE_INT_REGS
20994 popl_cfi %ebx
20995 CFI_RESTORE ebx
20996@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20997 popfl_cfi
20998 jmp syscall_exit
20999 CFI_ENDPROC
21000-END(ret_from_fork)
21001+ENDPROC(ret_from_fork)
21002
21003 ENTRY(ret_from_kernel_thread)
21004 CFI_STARTPROC
21005@@ -344,7 +493,15 @@ ret_from_intr:
21006 andl $SEGMENT_RPL_MASK, %eax
21007 #endif
21008 cmpl $USER_RPL, %eax
21009+
21010+#ifdef CONFIG_PAX_KERNEXEC
21011+ jae resume_userspace
21012+
21013+ pax_exit_kernel
21014+ jmp resume_kernel
21015+#else
21016 jb resume_kernel # not returning to v8086 or userspace
21017+#endif
21018
21019 ENTRY(resume_userspace)
21020 LOCKDEP_SYS_EXIT
21021@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
21022 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
21023 # int/exception return?
21024 jne work_pending
21025- jmp restore_all
21026-END(ret_from_exception)
21027+ jmp restore_all_pax
21028+ENDPROC(ret_from_exception)
21029
21030 #ifdef CONFIG_PREEMPT
21031 ENTRY(resume_kernel)
21032@@ -372,7 +529,7 @@ need_resched:
21033 jz restore_all
21034 call preempt_schedule_irq
21035 jmp need_resched
21036-END(resume_kernel)
21037+ENDPROC(resume_kernel)
21038 #endif
21039 CFI_ENDPROC
21040 /*
21041@@ -406,30 +563,45 @@ sysenter_past_esp:
21042 /*CFI_REL_OFFSET cs, 0*/
21043 /*
21044 * Push current_thread_info()->sysenter_return to the stack.
21045- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
21046- * pushed above; +8 corresponds to copy_thread's esp0 setting.
21047 */
21048- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
21049+ pushl_cfi $0
21050 CFI_REL_OFFSET eip, 0
21051
21052 pushl_cfi %eax
21053 SAVE_ALL
21054+ GET_THREAD_INFO(%ebp)
21055+ movl TI_sysenter_return(%ebp),%ebp
21056+ movl %ebp,PT_EIP(%esp)
21057 ENABLE_INTERRUPTS(CLBR_NONE)
21058
21059 /*
21060 * Load the potential sixth argument from user stack.
21061 * Careful about security.
21062 */
21063+ movl PT_OLDESP(%esp),%ebp
21064+
21065+#ifdef CONFIG_PAX_MEMORY_UDEREF
21066+ mov PT_OLDSS(%esp),%ds
21067+1: movl %ds:(%ebp),%ebp
21068+ push %ss
21069+ pop %ds
21070+#else
21071 cmpl $__PAGE_OFFSET-3,%ebp
21072 jae syscall_fault
21073 ASM_STAC
21074 1: movl (%ebp),%ebp
21075 ASM_CLAC
21076+#endif
21077+
21078 movl %ebp,PT_EBP(%esp)
21079 _ASM_EXTABLE(1b,syscall_fault)
21080
21081 GET_THREAD_INFO(%ebp)
21082
21083+#ifdef CONFIG_PAX_RANDKSTACK
21084+ pax_erase_kstack
21085+#endif
21086+
21087 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21088 jnz sysenter_audit
21089 sysenter_do_call:
21090@@ -444,12 +616,24 @@ sysenter_do_call:
21091 testl $_TIF_ALLWORK_MASK, %ecx
21092 jne sysexit_audit
21093 sysenter_exit:
21094+
21095+#ifdef CONFIG_PAX_RANDKSTACK
21096+ pushl_cfi %eax
21097+ movl %esp, %eax
21098+ call pax_randomize_kstack
21099+ popl_cfi %eax
21100+#endif
21101+
21102+ pax_erase_kstack
21103+
21104 /* if something modifies registers it must also disable sysexit */
21105 movl PT_EIP(%esp), %edx
21106 movl PT_OLDESP(%esp), %ecx
21107 xorl %ebp,%ebp
21108 TRACE_IRQS_ON
21109 1: mov PT_FS(%esp), %fs
21110+2: mov PT_DS(%esp), %ds
21111+3: mov PT_ES(%esp), %es
21112 PTGS_TO_GS
21113 ENABLE_INTERRUPTS_SYSEXIT
21114
21115@@ -466,6 +650,9 @@ sysenter_audit:
21116 movl %eax,%edx /* 2nd arg: syscall number */
21117 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
21118 call __audit_syscall_entry
21119+
21120+ pax_erase_kstack
21121+
21122 pushl_cfi %ebx
21123 movl PT_EAX(%esp),%eax /* reload syscall number */
21124 jmp sysenter_do_call
21125@@ -491,10 +678,16 @@ sysexit_audit:
21126
21127 CFI_ENDPROC
21128 .pushsection .fixup,"ax"
21129-2: movl $0,PT_FS(%esp)
21130+4: movl $0,PT_FS(%esp)
21131+ jmp 1b
21132+5: movl $0,PT_DS(%esp)
21133+ jmp 1b
21134+6: movl $0,PT_ES(%esp)
21135 jmp 1b
21136 .popsection
21137- _ASM_EXTABLE(1b,2b)
21138+ _ASM_EXTABLE(1b,4b)
21139+ _ASM_EXTABLE(2b,5b)
21140+ _ASM_EXTABLE(3b,6b)
21141 PTGS_TO_GS_EX
21142 ENDPROC(ia32_sysenter_target)
21143
21144@@ -509,6 +702,11 @@ ENTRY(system_call)
21145 pushl_cfi %eax # save orig_eax
21146 SAVE_ALL
21147 GET_THREAD_INFO(%ebp)
21148+
21149+#ifdef CONFIG_PAX_RANDKSTACK
21150+ pax_erase_kstack
21151+#endif
21152+
21153 # system call tracing in operation / emulation
21154 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21155 jnz syscall_trace_entry
21156@@ -527,6 +725,15 @@ syscall_exit:
21157 testl $_TIF_ALLWORK_MASK, %ecx # current->work
21158 jne syscall_exit_work
21159
21160+restore_all_pax:
21161+
21162+#ifdef CONFIG_PAX_RANDKSTACK
21163+ movl %esp, %eax
21164+ call pax_randomize_kstack
21165+#endif
21166+
21167+ pax_erase_kstack
21168+
21169 restore_all:
21170 TRACE_IRQS_IRET
21171 restore_all_notrace:
21172@@ -583,14 +790,34 @@ ldt_ss:
21173 * compensating for the offset by changing to the ESPFIX segment with
21174 * a base address that matches for the difference.
21175 */
21176-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
21177+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
21178 mov %esp, %edx /* load kernel esp */
21179 mov PT_OLDESP(%esp), %eax /* load userspace esp */
21180 mov %dx, %ax /* eax: new kernel esp */
21181 sub %eax, %edx /* offset (low word is 0) */
21182+#ifdef CONFIG_SMP
21183+ movl PER_CPU_VAR(cpu_number), %ebx
21184+ shll $PAGE_SHIFT_asm, %ebx
21185+ addl $cpu_gdt_table, %ebx
21186+#else
21187+ movl $cpu_gdt_table, %ebx
21188+#endif
21189 shr $16, %edx
21190- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
21191- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
21192+
21193+#ifdef CONFIG_PAX_KERNEXEC
21194+ mov %cr0, %esi
21195+ btr $16, %esi
21196+ mov %esi, %cr0
21197+#endif
21198+
21199+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
21200+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
21201+
21202+#ifdef CONFIG_PAX_KERNEXEC
21203+ bts $16, %esi
21204+ mov %esi, %cr0
21205+#endif
21206+
21207 pushl_cfi $__ESPFIX_SS
21208 pushl_cfi %eax /* new kernel esp */
21209 /* Disable interrupts, but do not irqtrace this section: we
21210@@ -619,20 +846,18 @@ work_resched:
21211 movl TI_flags(%ebp), %ecx
21212 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
21213 # than syscall tracing?
21214- jz restore_all
21215+ jz restore_all_pax
21216 testb $_TIF_NEED_RESCHED, %cl
21217 jnz work_resched
21218
21219 work_notifysig: # deal with pending signals and
21220 # notify-resume requests
21221+ movl %esp, %eax
21222 #ifdef CONFIG_VM86
21223 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
21224- movl %esp, %eax
21225 jne work_notifysig_v86 # returning to kernel-space or
21226 # vm86-space
21227 1:
21228-#else
21229- movl %esp, %eax
21230 #endif
21231 TRACE_IRQS_ON
21232 ENABLE_INTERRUPTS(CLBR_NONE)
21233@@ -653,7 +878,7 @@ work_notifysig_v86:
21234 movl %eax, %esp
21235 jmp 1b
21236 #endif
21237-END(work_pending)
21238+ENDPROC(work_pending)
21239
21240 # perform syscall exit tracing
21241 ALIGN
21242@@ -661,11 +886,14 @@ syscall_trace_entry:
21243 movl $-ENOSYS,PT_EAX(%esp)
21244 movl %esp, %eax
21245 call syscall_trace_enter
21246+
21247+ pax_erase_kstack
21248+
21249 /* What it returned is what we'll actually use. */
21250 cmpl $(NR_syscalls), %eax
21251 jnae syscall_call
21252 jmp syscall_exit
21253-END(syscall_trace_entry)
21254+ENDPROC(syscall_trace_entry)
21255
21256 # perform syscall exit tracing
21257 ALIGN
21258@@ -678,21 +906,25 @@ syscall_exit_work:
21259 movl %esp, %eax
21260 call syscall_trace_leave
21261 jmp resume_userspace
21262-END(syscall_exit_work)
21263+ENDPROC(syscall_exit_work)
21264 CFI_ENDPROC
21265
21266 RING0_INT_FRAME # can't unwind into user space anyway
21267 syscall_fault:
21268+#ifdef CONFIG_PAX_MEMORY_UDEREF
21269+ push %ss
21270+ pop %ds
21271+#endif
21272 ASM_CLAC
21273 GET_THREAD_INFO(%ebp)
21274 movl $-EFAULT,PT_EAX(%esp)
21275 jmp resume_userspace
21276-END(syscall_fault)
21277+ENDPROC(syscall_fault)
21278
21279 syscall_badsys:
21280 movl $-ENOSYS,PT_EAX(%esp)
21281 jmp resume_userspace
21282-END(syscall_badsys)
21283+ENDPROC(syscall_badsys)
21284 CFI_ENDPROC
21285 /*
21286 * End of kprobes section
21287@@ -708,8 +940,15 @@ END(syscall_badsys)
21288 * normal stack and adjusts ESP with the matching offset.
21289 */
21290 /* fixup the stack */
21291- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21292- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21293+#ifdef CONFIG_SMP
21294+ movl PER_CPU_VAR(cpu_number), %ebx
21295+ shll $PAGE_SHIFT_asm, %ebx
21296+ addl $cpu_gdt_table, %ebx
21297+#else
21298+ movl $cpu_gdt_table, %ebx
21299+#endif
21300+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21301+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21302 shl $16, %eax
21303 addl %esp, %eax /* the adjusted stack pointer */
21304 pushl_cfi $__KERNEL_DS
21305@@ -762,7 +1001,7 @@ vector=vector+1
21306 .endr
21307 2: jmp common_interrupt
21308 .endr
21309-END(irq_entries_start)
21310+ENDPROC(irq_entries_start)
21311
21312 .previous
21313 END(interrupt)
21314@@ -813,7 +1052,7 @@ ENTRY(coprocessor_error)
21315 pushl_cfi $do_coprocessor_error
21316 jmp error_code
21317 CFI_ENDPROC
21318-END(coprocessor_error)
21319+ENDPROC(coprocessor_error)
21320
21321 ENTRY(simd_coprocessor_error)
21322 RING0_INT_FRAME
21323@@ -826,7 +1065,7 @@ ENTRY(simd_coprocessor_error)
21324 .section .altinstructions,"a"
21325 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21326 .previous
21327-.section .altinstr_replacement,"ax"
21328+.section .altinstr_replacement,"a"
21329 663: pushl $do_simd_coprocessor_error
21330 664:
21331 .previous
21332@@ -835,7 +1074,7 @@ ENTRY(simd_coprocessor_error)
21333 #endif
21334 jmp error_code
21335 CFI_ENDPROC
21336-END(simd_coprocessor_error)
21337+ENDPROC(simd_coprocessor_error)
21338
21339 ENTRY(device_not_available)
21340 RING0_INT_FRAME
21341@@ -844,18 +1083,18 @@ ENTRY(device_not_available)
21342 pushl_cfi $do_device_not_available
21343 jmp error_code
21344 CFI_ENDPROC
21345-END(device_not_available)
21346+ENDPROC(device_not_available)
21347
21348 #ifdef CONFIG_PARAVIRT
21349 ENTRY(native_iret)
21350 iret
21351 _ASM_EXTABLE(native_iret, iret_exc)
21352-END(native_iret)
21353+ENDPROC(native_iret)
21354
21355 ENTRY(native_irq_enable_sysexit)
21356 sti
21357 sysexit
21358-END(native_irq_enable_sysexit)
21359+ENDPROC(native_irq_enable_sysexit)
21360 #endif
21361
21362 ENTRY(overflow)
21363@@ -865,7 +1104,7 @@ ENTRY(overflow)
21364 pushl_cfi $do_overflow
21365 jmp error_code
21366 CFI_ENDPROC
21367-END(overflow)
21368+ENDPROC(overflow)
21369
21370 ENTRY(bounds)
21371 RING0_INT_FRAME
21372@@ -874,7 +1113,7 @@ ENTRY(bounds)
21373 pushl_cfi $do_bounds
21374 jmp error_code
21375 CFI_ENDPROC
21376-END(bounds)
21377+ENDPROC(bounds)
21378
21379 ENTRY(invalid_op)
21380 RING0_INT_FRAME
21381@@ -883,7 +1122,7 @@ ENTRY(invalid_op)
21382 pushl_cfi $do_invalid_op
21383 jmp error_code
21384 CFI_ENDPROC
21385-END(invalid_op)
21386+ENDPROC(invalid_op)
21387
21388 ENTRY(coprocessor_segment_overrun)
21389 RING0_INT_FRAME
21390@@ -892,7 +1131,7 @@ ENTRY(coprocessor_segment_overrun)
21391 pushl_cfi $do_coprocessor_segment_overrun
21392 jmp error_code
21393 CFI_ENDPROC
21394-END(coprocessor_segment_overrun)
21395+ENDPROC(coprocessor_segment_overrun)
21396
21397 ENTRY(invalid_TSS)
21398 RING0_EC_FRAME
21399@@ -900,7 +1139,7 @@ ENTRY(invalid_TSS)
21400 pushl_cfi $do_invalid_TSS
21401 jmp error_code
21402 CFI_ENDPROC
21403-END(invalid_TSS)
21404+ENDPROC(invalid_TSS)
21405
21406 ENTRY(segment_not_present)
21407 RING0_EC_FRAME
21408@@ -908,7 +1147,7 @@ ENTRY(segment_not_present)
21409 pushl_cfi $do_segment_not_present
21410 jmp error_code
21411 CFI_ENDPROC
21412-END(segment_not_present)
21413+ENDPROC(segment_not_present)
21414
21415 ENTRY(stack_segment)
21416 RING0_EC_FRAME
21417@@ -916,7 +1155,7 @@ ENTRY(stack_segment)
21418 pushl_cfi $do_stack_segment
21419 jmp error_code
21420 CFI_ENDPROC
21421-END(stack_segment)
21422+ENDPROC(stack_segment)
21423
21424 ENTRY(alignment_check)
21425 RING0_EC_FRAME
21426@@ -924,7 +1163,7 @@ ENTRY(alignment_check)
21427 pushl_cfi $do_alignment_check
21428 jmp error_code
21429 CFI_ENDPROC
21430-END(alignment_check)
21431+ENDPROC(alignment_check)
21432
21433 ENTRY(divide_error)
21434 RING0_INT_FRAME
21435@@ -933,7 +1172,7 @@ ENTRY(divide_error)
21436 pushl_cfi $do_divide_error
21437 jmp error_code
21438 CFI_ENDPROC
21439-END(divide_error)
21440+ENDPROC(divide_error)
21441
21442 #ifdef CONFIG_X86_MCE
21443 ENTRY(machine_check)
21444@@ -943,7 +1182,7 @@ ENTRY(machine_check)
21445 pushl_cfi machine_check_vector
21446 jmp error_code
21447 CFI_ENDPROC
21448-END(machine_check)
21449+ENDPROC(machine_check)
21450 #endif
21451
21452 ENTRY(spurious_interrupt_bug)
21453@@ -953,7 +1192,7 @@ ENTRY(spurious_interrupt_bug)
21454 pushl_cfi $do_spurious_interrupt_bug
21455 jmp error_code
21456 CFI_ENDPROC
21457-END(spurious_interrupt_bug)
21458+ENDPROC(spurious_interrupt_bug)
21459 /*
21460 * End of kprobes section
21461 */
21462@@ -1063,7 +1302,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21463
21464 ENTRY(mcount)
21465 ret
21466-END(mcount)
21467+ENDPROC(mcount)
21468
21469 ENTRY(ftrace_caller)
21470 cmpl $0, function_trace_stop
21471@@ -1096,7 +1335,7 @@ ftrace_graph_call:
21472 .globl ftrace_stub
21473 ftrace_stub:
21474 ret
21475-END(ftrace_caller)
21476+ENDPROC(ftrace_caller)
21477
21478 ENTRY(ftrace_regs_caller)
21479 pushf /* push flags before compare (in cs location) */
21480@@ -1197,7 +1436,7 @@ trace:
21481 popl %ecx
21482 popl %eax
21483 jmp ftrace_stub
21484-END(mcount)
21485+ENDPROC(mcount)
21486 #endif /* CONFIG_DYNAMIC_FTRACE */
21487 #endif /* CONFIG_FUNCTION_TRACER */
21488
21489@@ -1215,7 +1454,7 @@ ENTRY(ftrace_graph_caller)
21490 popl %ecx
21491 popl %eax
21492 ret
21493-END(ftrace_graph_caller)
21494+ENDPROC(ftrace_graph_caller)
21495
21496 .globl return_to_handler
21497 return_to_handler:
21498@@ -1271,15 +1510,18 @@ error_code:
21499 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21500 REG_TO_PTGS %ecx
21501 SET_KERNEL_GS %ecx
21502- movl $(__USER_DS), %ecx
21503+ movl $(__KERNEL_DS), %ecx
21504 movl %ecx, %ds
21505 movl %ecx, %es
21506+
21507+ pax_enter_kernel
21508+
21509 TRACE_IRQS_OFF
21510 movl %esp,%eax # pt_regs pointer
21511 call *%edi
21512 jmp ret_from_exception
21513 CFI_ENDPROC
21514-END(page_fault)
21515+ENDPROC(page_fault)
21516
21517 /*
21518 * Debug traps and NMI can happen at the one SYSENTER instruction
21519@@ -1322,7 +1564,7 @@ debug_stack_correct:
21520 call do_debug
21521 jmp ret_from_exception
21522 CFI_ENDPROC
21523-END(debug)
21524+ENDPROC(debug)
21525
21526 /*
21527 * NMI is doubly nasty. It can happen _while_ we're handling
21528@@ -1360,6 +1602,9 @@ nmi_stack_correct:
21529 xorl %edx,%edx # zero error code
21530 movl %esp,%eax # pt_regs pointer
21531 call do_nmi
21532+
21533+ pax_exit_kernel
21534+
21535 jmp restore_all_notrace
21536 CFI_ENDPROC
21537
21538@@ -1396,12 +1641,15 @@ nmi_espfix_stack:
21539 FIXUP_ESPFIX_STACK # %eax == %esp
21540 xorl %edx,%edx # zero error code
21541 call do_nmi
21542+
21543+ pax_exit_kernel
21544+
21545 RESTORE_REGS
21546 lss 12+4(%esp), %esp # back to espfix stack
21547 CFI_ADJUST_CFA_OFFSET -24
21548 jmp irq_return
21549 CFI_ENDPROC
21550-END(nmi)
21551+ENDPROC(nmi)
21552
21553 ENTRY(int3)
21554 RING0_INT_FRAME
21555@@ -1414,14 +1662,14 @@ ENTRY(int3)
21556 call do_int3
21557 jmp ret_from_exception
21558 CFI_ENDPROC
21559-END(int3)
21560+ENDPROC(int3)
21561
21562 ENTRY(general_protection)
21563 RING0_EC_FRAME
21564 pushl_cfi $do_general_protection
21565 jmp error_code
21566 CFI_ENDPROC
21567-END(general_protection)
21568+ENDPROC(general_protection)
21569
21570 #ifdef CONFIG_KVM_GUEST
21571 ENTRY(async_page_fault)
21572@@ -1430,7 +1678,7 @@ ENTRY(async_page_fault)
21573 pushl_cfi $do_async_page_fault
21574 jmp error_code
21575 CFI_ENDPROC
21576-END(async_page_fault)
21577+ENDPROC(async_page_fault)
21578 #endif
21579
21580 /*
21581diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21582index 7272089..0b74104 100644
21583--- a/arch/x86/kernel/entry_64.S
21584+++ b/arch/x86/kernel/entry_64.S
21585@@ -59,6 +59,8 @@
21586 #include <asm/context_tracking.h>
21587 #include <asm/smap.h>
21588 #include <linux/err.h>
21589+#include <asm/pgtable.h>
21590+#include <asm/alternative-asm.h>
21591
21592 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21593 #include <linux/elf-em.h>
21594@@ -80,8 +82,9 @@
21595 #ifdef CONFIG_DYNAMIC_FTRACE
21596
21597 ENTRY(function_hook)
21598+ pax_force_retaddr
21599 retq
21600-END(function_hook)
21601+ENDPROC(function_hook)
21602
21603 /* skip is set if stack has been adjusted */
21604 .macro ftrace_caller_setup skip=0
21605@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21606 #endif
21607
21608 GLOBAL(ftrace_stub)
21609+ pax_force_retaddr
21610 retq
21611-END(ftrace_caller)
21612+ENDPROC(ftrace_caller)
21613
21614 ENTRY(ftrace_regs_caller)
21615 /* Save the current flags before compare (in SS location)*/
21616@@ -191,7 +195,7 @@ ftrace_restore_flags:
21617 popfq
21618 jmp ftrace_stub
21619
21620-END(ftrace_regs_caller)
21621+ENDPROC(ftrace_regs_caller)
21622
21623
21624 #else /* ! CONFIG_DYNAMIC_FTRACE */
21625@@ -212,6 +216,7 @@ ENTRY(function_hook)
21626 #endif
21627
21628 GLOBAL(ftrace_stub)
21629+ pax_force_retaddr
21630 retq
21631
21632 trace:
21633@@ -225,12 +230,13 @@ trace:
21634 #endif
21635 subq $MCOUNT_INSN_SIZE, %rdi
21636
21637+ pax_force_fptr ftrace_trace_function
21638 call *ftrace_trace_function
21639
21640 MCOUNT_RESTORE_FRAME
21641
21642 jmp ftrace_stub
21643-END(function_hook)
21644+ENDPROC(function_hook)
21645 #endif /* CONFIG_DYNAMIC_FTRACE */
21646 #endif /* CONFIG_FUNCTION_TRACER */
21647
21648@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21649
21650 MCOUNT_RESTORE_FRAME
21651
21652+ pax_force_retaddr
21653 retq
21654-END(ftrace_graph_caller)
21655+ENDPROC(ftrace_graph_caller)
21656
21657 GLOBAL(return_to_handler)
21658 subq $24, %rsp
21659@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21660 movq 8(%rsp), %rdx
21661 movq (%rsp), %rax
21662 addq $24, %rsp
21663+ pax_force_fptr %rdi
21664 jmp *%rdi
21665+ENDPROC(return_to_handler)
21666 #endif
21667
21668
21669@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21670 ENDPROC(native_usergs_sysret64)
21671 #endif /* CONFIG_PARAVIRT */
21672
21673+ .macro ljmpq sel, off
21674+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21675+ .byte 0x48; ljmp *1234f(%rip)
21676+ .pushsection .rodata
21677+ .align 16
21678+ 1234: .quad \off; .word \sel
21679+ .popsection
21680+#else
21681+ pushq $\sel
21682+ pushq $\off
21683+ lretq
21684+#endif
21685+ .endm
21686+
21687+ .macro pax_enter_kernel
21688+ pax_set_fptr_mask
21689+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21690+ call pax_enter_kernel
21691+#endif
21692+ .endm
21693+
21694+ .macro pax_exit_kernel
21695+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21696+ call pax_exit_kernel
21697+#endif
21698+
21699+ .endm
21700+
21701+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21702+ENTRY(pax_enter_kernel)
21703+ pushq %rdi
21704+
21705+#ifdef CONFIG_PARAVIRT
21706+ PV_SAVE_REGS(CLBR_RDI)
21707+#endif
21708+
21709+#ifdef CONFIG_PAX_KERNEXEC
21710+ GET_CR0_INTO_RDI
21711+ bts $16,%rdi
21712+ jnc 3f
21713+ mov %cs,%edi
21714+ cmp $__KERNEL_CS,%edi
21715+ jnz 2f
21716+1:
21717+#endif
21718+
21719+#ifdef CONFIG_PAX_MEMORY_UDEREF
21720+ 661: jmp 111f
21721+ .pushsection .altinstr_replacement, "a"
21722+ 662: ASM_NOP2
21723+ .popsection
21724+ .pushsection .altinstructions, "a"
21725+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21726+ .popsection
21727+ GET_CR3_INTO_RDI
21728+ cmp $0,%dil
21729+ jnz 112f
21730+ mov $__KERNEL_DS,%edi
21731+ mov %edi,%ss
21732+ jmp 111f
21733+112: cmp $1,%dil
21734+ jz 113f
21735+ ud2
21736+113: sub $4097,%rdi
21737+ bts $63,%rdi
21738+ SET_RDI_INTO_CR3
21739+ mov $__UDEREF_KERNEL_DS,%edi
21740+ mov %edi,%ss
21741+111:
21742+#endif
21743+
21744+#ifdef CONFIG_PARAVIRT
21745+ PV_RESTORE_REGS(CLBR_RDI)
21746+#endif
21747+
21748+ popq %rdi
21749+ pax_force_retaddr
21750+ retq
21751+
21752+#ifdef CONFIG_PAX_KERNEXEC
21753+2: ljmpq __KERNEL_CS,1b
21754+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21755+4: SET_RDI_INTO_CR0
21756+ jmp 1b
21757+#endif
21758+ENDPROC(pax_enter_kernel)
21759+
21760+ENTRY(pax_exit_kernel)
21761+ pushq %rdi
21762+
21763+#ifdef CONFIG_PARAVIRT
21764+ PV_SAVE_REGS(CLBR_RDI)
21765+#endif
21766+
21767+#ifdef CONFIG_PAX_KERNEXEC
21768+ mov %cs,%rdi
21769+ cmp $__KERNEXEC_KERNEL_CS,%edi
21770+ jz 2f
21771+ GET_CR0_INTO_RDI
21772+ bts $16,%rdi
21773+ jnc 4f
21774+1:
21775+#endif
21776+
21777+#ifdef CONFIG_PAX_MEMORY_UDEREF
21778+ 661: jmp 111f
21779+ .pushsection .altinstr_replacement, "a"
21780+ 662: ASM_NOP2
21781+ .popsection
21782+ .pushsection .altinstructions, "a"
21783+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21784+ .popsection
21785+ mov %ss,%edi
21786+ cmp $__UDEREF_KERNEL_DS,%edi
21787+ jnz 111f
21788+ GET_CR3_INTO_RDI
21789+ cmp $0,%dil
21790+ jz 112f
21791+ ud2
21792+112: add $4097,%rdi
21793+ bts $63,%rdi
21794+ SET_RDI_INTO_CR3
21795+ mov $__KERNEL_DS,%edi
21796+ mov %edi,%ss
21797+111:
21798+#endif
21799+
21800+#ifdef CONFIG_PARAVIRT
21801+ PV_RESTORE_REGS(CLBR_RDI);
21802+#endif
21803+
21804+ popq %rdi
21805+ pax_force_retaddr
21806+ retq
21807+
21808+#ifdef CONFIG_PAX_KERNEXEC
21809+2: GET_CR0_INTO_RDI
21810+ btr $16,%rdi
21811+ jnc 4f
21812+ ljmpq __KERNEL_CS,3f
21813+3: SET_RDI_INTO_CR0
21814+ jmp 1b
21815+4: ud2
21816+ jmp 4b
21817+#endif
21818+ENDPROC(pax_exit_kernel)
21819+#endif
21820+
21821+ .macro pax_enter_kernel_user
21822+ pax_set_fptr_mask
21823+#ifdef CONFIG_PAX_MEMORY_UDEREF
21824+ call pax_enter_kernel_user
21825+#endif
21826+ .endm
21827+
21828+ .macro pax_exit_kernel_user
21829+#ifdef CONFIG_PAX_MEMORY_UDEREF
21830+ call pax_exit_kernel_user
21831+#endif
21832+#ifdef CONFIG_PAX_RANDKSTACK
21833+ pushq %rax
21834+ pushq %r11
21835+ call pax_randomize_kstack
21836+ popq %r11
21837+ popq %rax
21838+#endif
21839+ .endm
21840+
21841+#ifdef CONFIG_PAX_MEMORY_UDEREF
21842+ENTRY(pax_enter_kernel_user)
21843+ pushq %rdi
21844+ pushq %rbx
21845+
21846+#ifdef CONFIG_PARAVIRT
21847+ PV_SAVE_REGS(CLBR_RDI)
21848+#endif
21849+
21850+ 661: jmp 111f
21851+ .pushsection .altinstr_replacement, "a"
21852+ 662: ASM_NOP2
21853+ .popsection
21854+ .pushsection .altinstructions, "a"
21855+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21856+ .popsection
21857+ GET_CR3_INTO_RDI
21858+ cmp $1,%dil
21859+ jnz 4f
21860+ sub $4097,%rdi
21861+ bts $63,%rdi
21862+ SET_RDI_INTO_CR3
21863+ jmp 3f
21864+111:
21865+
21866+ GET_CR3_INTO_RDI
21867+ mov %rdi,%rbx
21868+ add $__START_KERNEL_map,%rbx
21869+ sub phys_base(%rip),%rbx
21870+
21871+#ifdef CONFIG_PARAVIRT
21872+ cmpl $0, pv_info+PARAVIRT_enabled
21873+ jz 1f
21874+ pushq %rdi
21875+ i = 0
21876+ .rept USER_PGD_PTRS
21877+ mov i*8(%rbx),%rsi
21878+ mov $0,%sil
21879+ lea i*8(%rbx),%rdi
21880+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21881+ i = i + 1
21882+ .endr
21883+ popq %rdi
21884+ jmp 2f
21885+1:
21886+#endif
21887+
21888+ i = 0
21889+ .rept USER_PGD_PTRS
21890+ movb $0,i*8(%rbx)
21891+ i = i + 1
21892+ .endr
21893+
21894+2: SET_RDI_INTO_CR3
21895+
21896+#ifdef CONFIG_PAX_KERNEXEC
21897+ GET_CR0_INTO_RDI
21898+ bts $16,%rdi
21899+ SET_RDI_INTO_CR0
21900+#endif
21901+
21902+3:
21903+
21904+#ifdef CONFIG_PARAVIRT
21905+ PV_RESTORE_REGS(CLBR_RDI)
21906+#endif
21907+
21908+ popq %rbx
21909+ popq %rdi
21910+ pax_force_retaddr
21911+ retq
21912+4: ud2
21913+ENDPROC(pax_enter_kernel_user)
21914+
21915+ENTRY(pax_exit_kernel_user)
21916+ pushq %rdi
21917+ pushq %rbx
21918+
21919+#ifdef CONFIG_PARAVIRT
21920+ PV_SAVE_REGS(CLBR_RDI)
21921+#endif
21922+
21923+ GET_CR3_INTO_RDI
21924+ 661: jmp 1f
21925+ .pushsection .altinstr_replacement, "a"
21926+ 662: ASM_NOP2
21927+ .popsection
21928+ .pushsection .altinstructions, "a"
21929+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21930+ .popsection
21931+ cmp $0,%dil
21932+ jnz 3f
21933+ add $4097,%rdi
21934+ bts $63,%rdi
21935+ SET_RDI_INTO_CR3
21936+ jmp 2f
21937+1:
21938+
21939+ mov %rdi,%rbx
21940+
21941+#ifdef CONFIG_PAX_KERNEXEC
21942+ GET_CR0_INTO_RDI
21943+ btr $16,%rdi
21944+ jnc 3f
21945+ SET_RDI_INTO_CR0
21946+#endif
21947+
21948+ add $__START_KERNEL_map,%rbx
21949+ sub phys_base(%rip),%rbx
21950+
21951+#ifdef CONFIG_PARAVIRT
21952+ cmpl $0, pv_info+PARAVIRT_enabled
21953+ jz 1f
21954+ i = 0
21955+ .rept USER_PGD_PTRS
21956+ mov i*8(%rbx),%rsi
21957+ mov $0x67,%sil
21958+ lea i*8(%rbx),%rdi
21959+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21960+ i = i + 1
21961+ .endr
21962+ jmp 2f
21963+1:
21964+#endif
21965+
21966+ i = 0
21967+ .rept USER_PGD_PTRS
21968+ movb $0x67,i*8(%rbx)
21969+ i = i + 1
21970+ .endr
21971+2:
21972+
21973+#ifdef CONFIG_PARAVIRT
21974+ PV_RESTORE_REGS(CLBR_RDI)
21975+#endif
21976+
21977+ popq %rbx
21978+ popq %rdi
21979+ pax_force_retaddr
21980+ retq
21981+3: ud2
21982+ENDPROC(pax_exit_kernel_user)
21983+#endif
21984+
21985+ .macro pax_enter_kernel_nmi
21986+ pax_set_fptr_mask
21987+
21988+#ifdef CONFIG_PAX_KERNEXEC
21989+ GET_CR0_INTO_RDI
21990+ bts $16,%rdi
21991+ jc 110f
21992+ SET_RDI_INTO_CR0
21993+ or $2,%ebx
21994+110:
21995+#endif
21996+
21997+#ifdef CONFIG_PAX_MEMORY_UDEREF
21998+ 661: jmp 111f
21999+ .pushsection .altinstr_replacement, "a"
22000+ 662: ASM_NOP2
22001+ .popsection
22002+ .pushsection .altinstructions, "a"
22003+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22004+ .popsection
22005+ GET_CR3_INTO_RDI
22006+ cmp $0,%dil
22007+ jz 111f
22008+ sub $4097,%rdi
22009+ or $4,%ebx
22010+ bts $63,%rdi
22011+ SET_RDI_INTO_CR3
22012+ mov $__UDEREF_KERNEL_DS,%edi
22013+ mov %edi,%ss
22014+111:
22015+#endif
22016+ .endm
22017+
22018+ .macro pax_exit_kernel_nmi
22019+#ifdef CONFIG_PAX_KERNEXEC
22020+ btr $1,%ebx
22021+ jnc 110f
22022+ GET_CR0_INTO_RDI
22023+ btr $16,%rdi
22024+ SET_RDI_INTO_CR0
22025+110:
22026+#endif
22027+
22028+#ifdef CONFIG_PAX_MEMORY_UDEREF
22029+ btr $2,%ebx
22030+ jnc 111f
22031+ GET_CR3_INTO_RDI
22032+ add $4097,%rdi
22033+ bts $63,%rdi
22034+ SET_RDI_INTO_CR3
22035+ mov $__KERNEL_DS,%edi
22036+ mov %edi,%ss
22037+111:
22038+#endif
22039+ .endm
22040+
22041+ .macro pax_erase_kstack
22042+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22043+ call pax_erase_kstack
22044+#endif
22045+ .endm
22046+
22047+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22048+ENTRY(pax_erase_kstack)
22049+ pushq %rdi
22050+ pushq %rcx
22051+ pushq %rax
22052+ pushq %r11
22053+
22054+ GET_THREAD_INFO(%r11)
22055+ mov TI_lowest_stack(%r11), %rdi
22056+ mov $-0xBEEF, %rax
22057+ std
22058+
22059+1: mov %edi, %ecx
22060+ and $THREAD_SIZE_asm - 1, %ecx
22061+ shr $3, %ecx
22062+ repne scasq
22063+ jecxz 2f
22064+
22065+ cmp $2*8, %ecx
22066+ jc 2f
22067+
22068+ mov $2*8, %ecx
22069+ repe scasq
22070+ jecxz 2f
22071+ jne 1b
22072+
22073+2: cld
22074+ mov %esp, %ecx
22075+ sub %edi, %ecx
22076+
22077+ cmp $THREAD_SIZE_asm, %rcx
22078+ jb 3f
22079+ ud2
22080+3:
22081+
22082+ shr $3, %ecx
22083+ rep stosq
22084+
22085+ mov TI_task_thread_sp0(%r11), %rdi
22086+ sub $256, %rdi
22087+ mov %rdi, TI_lowest_stack(%r11)
22088+
22089+ popq %r11
22090+ popq %rax
22091+ popq %rcx
22092+ popq %rdi
22093+ pax_force_retaddr
22094+ ret
22095+ENDPROC(pax_erase_kstack)
22096+#endif
22097
22098 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
22099 #ifdef CONFIG_TRACE_IRQFLAGS
22100@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
22101 .endm
22102
22103 .macro UNFAKE_STACK_FRAME
22104- addq $8*6, %rsp
22105- CFI_ADJUST_CFA_OFFSET -(6*8)
22106+ addq $8*6 + ARG_SKIP, %rsp
22107+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
22108 .endm
22109
22110 /*
22111@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
22112 movq %rsp, %rsi
22113
22114 leaq -RBP(%rsp),%rdi /* arg1 for handler */
22115- testl $3, CS-RBP(%rsi)
22116+ testb $3, CS-RBP(%rsi)
22117 je 1f
22118 SWAPGS
22119 /*
22120@@ -498,9 +931,10 @@ ENTRY(save_rest)
22121 movq_cfi r15, R15+16
22122 movq %r11, 8(%rsp) /* return address */
22123 FIXUP_TOP_OF_STACK %r11, 16
22124+ pax_force_retaddr
22125 ret
22126 CFI_ENDPROC
22127-END(save_rest)
22128+ENDPROC(save_rest)
22129
22130 /* save complete stack frame */
22131 .pushsection .kprobes.text, "ax"
22132@@ -529,9 +963,10 @@ ENTRY(save_paranoid)
22133 js 1f /* negative -> in kernel */
22134 SWAPGS
22135 xorl %ebx,%ebx
22136-1: ret
22137+1: pax_force_retaddr_bts
22138+ ret
22139 CFI_ENDPROC
22140-END(save_paranoid)
22141+ENDPROC(save_paranoid)
22142 .popsection
22143
22144 /*
22145@@ -553,7 +988,7 @@ ENTRY(ret_from_fork)
22146
22147 RESTORE_REST
22148
22149- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22150+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22151 jz 1f
22152
22153 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
22154@@ -571,7 +1006,7 @@ ENTRY(ret_from_fork)
22155 RESTORE_REST
22156 jmp int_ret_from_sys_call
22157 CFI_ENDPROC
22158-END(ret_from_fork)
22159+ENDPROC(ret_from_fork)
22160
22161 /*
22162 * System call entry. Up to 6 arguments in registers are supported.
22163@@ -608,7 +1043,7 @@ END(ret_from_fork)
22164 ENTRY(system_call)
22165 CFI_STARTPROC simple
22166 CFI_SIGNAL_FRAME
22167- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
22168+ CFI_DEF_CFA rsp,0
22169 CFI_REGISTER rip,rcx
22170 /*CFI_REGISTER rflags,r11*/
22171 SWAPGS_UNSAFE_STACK
22172@@ -621,16 +1056,23 @@ GLOBAL(system_call_after_swapgs)
22173
22174 movq %rsp,PER_CPU_VAR(old_rsp)
22175 movq PER_CPU_VAR(kernel_stack),%rsp
22176+ SAVE_ARGS 8*6,0
22177+ pax_enter_kernel_user
22178+
22179+#ifdef CONFIG_PAX_RANDKSTACK
22180+ pax_erase_kstack
22181+#endif
22182+
22183 /*
22184 * No need to follow this irqs off/on section - it's straight
22185 * and short:
22186 */
22187 ENABLE_INTERRUPTS(CLBR_NONE)
22188- SAVE_ARGS 8,0
22189 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
22190 movq %rcx,RIP-ARGOFFSET(%rsp)
22191 CFI_REL_OFFSET rip,RIP-ARGOFFSET
22192- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22193+ GET_THREAD_INFO(%rcx)
22194+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
22195 jnz tracesys
22196 system_call_fastpath:
22197 #if __SYSCALL_MASK == ~0
22198@@ -640,7 +1082,7 @@ system_call_fastpath:
22199 cmpl $__NR_syscall_max,%eax
22200 #endif
22201 ja badsys
22202- movq %r10,%rcx
22203+ movq R10-ARGOFFSET(%rsp),%rcx
22204 call *sys_call_table(,%rax,8) # XXX: rip relative
22205 movq %rax,RAX-ARGOFFSET(%rsp)
22206 /*
22207@@ -654,10 +1096,13 @@ sysret_check:
22208 LOCKDEP_SYS_EXIT
22209 DISABLE_INTERRUPTS(CLBR_NONE)
22210 TRACE_IRQS_OFF
22211- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
22212+ GET_THREAD_INFO(%rcx)
22213+ movl TI_flags(%rcx),%edx
22214 andl %edi,%edx
22215 jnz sysret_careful
22216 CFI_REMEMBER_STATE
22217+ pax_exit_kernel_user
22218+ pax_erase_kstack
22219 /*
22220 * sysretq will re-enable interrupts:
22221 */
22222@@ -709,14 +1154,18 @@ badsys:
22223 * jump back to the normal fast path.
22224 */
22225 auditsys:
22226- movq %r10,%r9 /* 6th arg: 4th syscall arg */
22227+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
22228 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
22229 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
22230 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
22231 movq %rax,%rsi /* 2nd arg: syscall number */
22232 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
22233 call __audit_syscall_entry
22234+
22235+ pax_erase_kstack
22236+
22237 LOAD_ARGS 0 /* reload call-clobbered registers */
22238+ pax_set_fptr_mask
22239 jmp system_call_fastpath
22240
22241 /*
22242@@ -737,7 +1186,7 @@ sysret_audit:
22243 /* Do syscall tracing */
22244 tracesys:
22245 #ifdef CONFIG_AUDITSYSCALL
22246- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22247+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
22248 jz auditsys
22249 #endif
22250 SAVE_REST
22251@@ -745,12 +1194,16 @@ tracesys:
22252 FIXUP_TOP_OF_STACK %rdi
22253 movq %rsp,%rdi
22254 call syscall_trace_enter
22255+
22256+ pax_erase_kstack
22257+
22258 /*
22259 * Reload arg registers from stack in case ptrace changed them.
22260 * We don't reload %rax because syscall_trace_enter() returned
22261 * the value it wants us to use in the table lookup.
22262 */
22263 LOAD_ARGS ARGOFFSET, 1
22264+ pax_set_fptr_mask
22265 RESTORE_REST
22266 #if __SYSCALL_MASK == ~0
22267 cmpq $__NR_syscall_max,%rax
22268@@ -759,7 +1212,7 @@ tracesys:
22269 cmpl $__NR_syscall_max,%eax
22270 #endif
22271 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
22272- movq %r10,%rcx /* fixup for C */
22273+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
22274 call *sys_call_table(,%rax,8)
22275 movq %rax,RAX-ARGOFFSET(%rsp)
22276 /* Use IRET because user could have changed frame */
22277@@ -780,7 +1233,9 @@ GLOBAL(int_with_check)
22278 andl %edi,%edx
22279 jnz int_careful
22280 andl $~TS_COMPAT,TI_status(%rcx)
22281- jmp retint_swapgs
22282+ pax_exit_kernel_user
22283+ pax_erase_kstack
22284+ jmp retint_swapgs_pax
22285
22286 /* Either reschedule or signal or syscall exit tracking needed. */
22287 /* First do a reschedule test. */
22288@@ -826,7 +1281,7 @@ int_restore_rest:
22289 TRACE_IRQS_OFF
22290 jmp int_with_check
22291 CFI_ENDPROC
22292-END(system_call)
22293+ENDPROC(system_call)
22294
22295 .macro FORK_LIKE func
22296 ENTRY(stub_\func)
22297@@ -839,9 +1294,10 @@ ENTRY(stub_\func)
22298 DEFAULT_FRAME 0 8 /* offset 8: return address */
22299 call sys_\func
22300 RESTORE_TOP_OF_STACK %r11, 8
22301+ pax_force_retaddr
22302 ret $REST_SKIP /* pop extended registers */
22303 CFI_ENDPROC
22304-END(stub_\func)
22305+ENDPROC(stub_\func)
22306 .endm
22307
22308 .macro FIXED_FRAME label,func
22309@@ -851,9 +1307,10 @@ ENTRY(\label)
22310 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22311 call \func
22312 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22313+ pax_force_retaddr
22314 ret
22315 CFI_ENDPROC
22316-END(\label)
22317+ENDPROC(\label)
22318 .endm
22319
22320 FORK_LIKE clone
22321@@ -870,9 +1327,10 @@ ENTRY(ptregscall_common)
22322 movq_cfi_restore R12+8, r12
22323 movq_cfi_restore RBP+8, rbp
22324 movq_cfi_restore RBX+8, rbx
22325+ pax_force_retaddr
22326 ret $REST_SKIP /* pop extended registers */
22327 CFI_ENDPROC
22328-END(ptregscall_common)
22329+ENDPROC(ptregscall_common)
22330
22331 ENTRY(stub_execve)
22332 CFI_STARTPROC
22333@@ -885,7 +1343,7 @@ ENTRY(stub_execve)
22334 RESTORE_REST
22335 jmp int_ret_from_sys_call
22336 CFI_ENDPROC
22337-END(stub_execve)
22338+ENDPROC(stub_execve)
22339
22340 /*
22341 * sigreturn is special because it needs to restore all registers on return.
22342@@ -902,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
22343 RESTORE_REST
22344 jmp int_ret_from_sys_call
22345 CFI_ENDPROC
22346-END(stub_rt_sigreturn)
22347+ENDPROC(stub_rt_sigreturn)
22348
22349 #ifdef CONFIG_X86_X32_ABI
22350 ENTRY(stub_x32_rt_sigreturn)
22351@@ -916,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
22352 RESTORE_REST
22353 jmp int_ret_from_sys_call
22354 CFI_ENDPROC
22355-END(stub_x32_rt_sigreturn)
22356+ENDPROC(stub_x32_rt_sigreturn)
22357
22358 ENTRY(stub_x32_execve)
22359 CFI_STARTPROC
22360@@ -930,7 +1388,7 @@ ENTRY(stub_x32_execve)
22361 RESTORE_REST
22362 jmp int_ret_from_sys_call
22363 CFI_ENDPROC
22364-END(stub_x32_execve)
22365+ENDPROC(stub_x32_execve)
22366
22367 #endif
22368
22369@@ -967,7 +1425,7 @@ vector=vector+1
22370 2: jmp common_interrupt
22371 .endr
22372 CFI_ENDPROC
22373-END(irq_entries_start)
22374+ENDPROC(irq_entries_start)
22375
22376 .previous
22377 END(interrupt)
22378@@ -987,6 +1445,16 @@ END(interrupt)
22379 subq $ORIG_RAX-RBP, %rsp
22380 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22381 SAVE_ARGS_IRQ
22382+#ifdef CONFIG_PAX_MEMORY_UDEREF
22383+ testb $3, CS(%rdi)
22384+ jnz 1f
22385+ pax_enter_kernel
22386+ jmp 2f
22387+1: pax_enter_kernel_user
22388+2:
22389+#else
22390+ pax_enter_kernel
22391+#endif
22392 call \func
22393 .endm
22394
22395@@ -1019,7 +1487,7 @@ ret_from_intr:
22396
22397 exit_intr:
22398 GET_THREAD_INFO(%rcx)
22399- testl $3,CS-ARGOFFSET(%rsp)
22400+ testb $3,CS-ARGOFFSET(%rsp)
22401 je retint_kernel
22402
22403 /* Interrupt came from user space */
22404@@ -1041,12 +1509,16 @@ retint_swapgs: /* return to user-space */
22405 * The iretq could re-enable interrupts:
22406 */
22407 DISABLE_INTERRUPTS(CLBR_ANY)
22408+ pax_exit_kernel_user
22409+retint_swapgs_pax:
22410 TRACE_IRQS_IRETQ
22411 SWAPGS
22412 jmp restore_args
22413
22414 retint_restore_args: /* return to kernel space */
22415 DISABLE_INTERRUPTS(CLBR_ANY)
22416+ pax_exit_kernel
22417+ pax_force_retaddr (RIP-ARGOFFSET)
22418 /*
22419 * The iretq could re-enable interrupts:
22420 */
22421@@ -1129,7 +1601,7 @@ ENTRY(retint_kernel)
22422 #endif
22423
22424 CFI_ENDPROC
22425-END(common_interrupt)
22426+ENDPROC(common_interrupt)
22427 /*
22428 * End of kprobes section
22429 */
22430@@ -1147,7 +1619,7 @@ ENTRY(\sym)
22431 interrupt \do_sym
22432 jmp ret_from_intr
22433 CFI_ENDPROC
22434-END(\sym)
22435+ENDPROC(\sym)
22436 .endm
22437
22438 #ifdef CONFIG_SMP
22439@@ -1208,12 +1680,22 @@ ENTRY(\sym)
22440 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22441 call error_entry
22442 DEFAULT_FRAME 0
22443+#ifdef CONFIG_PAX_MEMORY_UDEREF
22444+ testb $3, CS(%rsp)
22445+ jnz 1f
22446+ pax_enter_kernel
22447+ jmp 2f
22448+1: pax_enter_kernel_user
22449+2:
22450+#else
22451+ pax_enter_kernel
22452+#endif
22453 movq %rsp,%rdi /* pt_regs pointer */
22454 xorl %esi,%esi /* no error code */
22455 call \do_sym
22456 jmp error_exit /* %ebx: no swapgs flag */
22457 CFI_ENDPROC
22458-END(\sym)
22459+ENDPROC(\sym)
22460 .endm
22461
22462 .macro paranoidzeroentry sym do_sym
22463@@ -1226,15 +1708,25 @@ ENTRY(\sym)
22464 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22465 call save_paranoid
22466 TRACE_IRQS_OFF
22467+#ifdef CONFIG_PAX_MEMORY_UDEREF
22468+ testb $3, CS(%rsp)
22469+ jnz 1f
22470+ pax_enter_kernel
22471+ jmp 2f
22472+1: pax_enter_kernel_user
22473+2:
22474+#else
22475+ pax_enter_kernel
22476+#endif
22477 movq %rsp,%rdi /* pt_regs pointer */
22478 xorl %esi,%esi /* no error code */
22479 call \do_sym
22480 jmp paranoid_exit /* %ebx: no swapgs flag */
22481 CFI_ENDPROC
22482-END(\sym)
22483+ENDPROC(\sym)
22484 .endm
22485
22486-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22487+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22488 .macro paranoidzeroentry_ist sym do_sym ist
22489 ENTRY(\sym)
22490 INTR_FRAME
22491@@ -1245,14 +1737,30 @@ ENTRY(\sym)
22492 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22493 call save_paranoid
22494 TRACE_IRQS_OFF_DEBUG
22495+#ifdef CONFIG_PAX_MEMORY_UDEREF
22496+ testb $3, CS(%rsp)
22497+ jnz 1f
22498+ pax_enter_kernel
22499+ jmp 2f
22500+1: pax_enter_kernel_user
22501+2:
22502+#else
22503+ pax_enter_kernel
22504+#endif
22505 movq %rsp,%rdi /* pt_regs pointer */
22506 xorl %esi,%esi /* no error code */
22507+#ifdef CONFIG_SMP
22508+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22509+ lea init_tss(%r12), %r12
22510+#else
22511+ lea init_tss(%rip), %r12
22512+#endif
22513 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22514 call \do_sym
22515 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22516 jmp paranoid_exit /* %ebx: no swapgs flag */
22517 CFI_ENDPROC
22518-END(\sym)
22519+ENDPROC(\sym)
22520 .endm
22521
22522 .macro errorentry sym do_sym
22523@@ -1264,13 +1772,23 @@ ENTRY(\sym)
22524 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22525 call error_entry
22526 DEFAULT_FRAME 0
22527+#ifdef CONFIG_PAX_MEMORY_UDEREF
22528+ testb $3, CS(%rsp)
22529+ jnz 1f
22530+ pax_enter_kernel
22531+ jmp 2f
22532+1: pax_enter_kernel_user
22533+2:
22534+#else
22535+ pax_enter_kernel
22536+#endif
22537 movq %rsp,%rdi /* pt_regs pointer */
22538 movq ORIG_RAX(%rsp),%rsi /* get error code */
22539 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22540 call \do_sym
22541 jmp error_exit /* %ebx: no swapgs flag */
22542 CFI_ENDPROC
22543-END(\sym)
22544+ENDPROC(\sym)
22545 .endm
22546
22547 /* error code is on the stack already */
22548@@ -1284,13 +1802,23 @@ ENTRY(\sym)
22549 call save_paranoid
22550 DEFAULT_FRAME 0
22551 TRACE_IRQS_OFF
22552+#ifdef CONFIG_PAX_MEMORY_UDEREF
22553+ testb $3, CS(%rsp)
22554+ jnz 1f
22555+ pax_enter_kernel
22556+ jmp 2f
22557+1: pax_enter_kernel_user
22558+2:
22559+#else
22560+ pax_enter_kernel
22561+#endif
22562 movq %rsp,%rdi /* pt_regs pointer */
22563 movq ORIG_RAX(%rsp),%rsi /* get error code */
22564 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22565 call \do_sym
22566 jmp paranoid_exit /* %ebx: no swapgs flag */
22567 CFI_ENDPROC
22568-END(\sym)
22569+ENDPROC(\sym)
22570 .endm
22571
22572 zeroentry divide_error do_divide_error
22573@@ -1320,9 +1848,10 @@ gs_change:
22574 2: mfence /* workaround */
22575 SWAPGS
22576 popfq_cfi
22577+ pax_force_retaddr
22578 ret
22579 CFI_ENDPROC
22580-END(native_load_gs_index)
22581+ENDPROC(native_load_gs_index)
22582
22583 _ASM_EXTABLE(gs_change,bad_gs)
22584 .section .fixup,"ax"
22585@@ -1350,9 +1879,10 @@ ENTRY(call_softirq)
22586 CFI_DEF_CFA_REGISTER rsp
22587 CFI_ADJUST_CFA_OFFSET -8
22588 decl PER_CPU_VAR(irq_count)
22589+ pax_force_retaddr
22590 ret
22591 CFI_ENDPROC
22592-END(call_softirq)
22593+ENDPROC(call_softirq)
22594
22595 #ifdef CONFIG_XEN
22596 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22597@@ -1390,7 +1920,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22598 decl PER_CPU_VAR(irq_count)
22599 jmp error_exit
22600 CFI_ENDPROC
22601-END(xen_do_hypervisor_callback)
22602+ENDPROC(xen_do_hypervisor_callback)
22603
22604 /*
22605 * Hypervisor uses this for application faults while it executes.
22606@@ -1449,7 +1979,7 @@ ENTRY(xen_failsafe_callback)
22607 SAVE_ALL
22608 jmp error_exit
22609 CFI_ENDPROC
22610-END(xen_failsafe_callback)
22611+ENDPROC(xen_failsafe_callback)
22612
22613 apicinterrupt HYPERVISOR_CALLBACK_VECTOR \
22614 xen_hvm_callback_vector xen_evtchn_do_upcall
22615@@ -1501,18 +2031,33 @@ ENTRY(paranoid_exit)
22616 DEFAULT_FRAME
22617 DISABLE_INTERRUPTS(CLBR_NONE)
22618 TRACE_IRQS_OFF_DEBUG
22619- testl %ebx,%ebx /* swapgs needed? */
22620+ testl $1,%ebx /* swapgs needed? */
22621 jnz paranoid_restore
22622- testl $3,CS(%rsp)
22623+ testb $3,CS(%rsp)
22624 jnz paranoid_userspace
22625+#ifdef CONFIG_PAX_MEMORY_UDEREF
22626+ pax_exit_kernel
22627+ TRACE_IRQS_IRETQ 0
22628+ SWAPGS_UNSAFE_STACK
22629+ RESTORE_ALL 8
22630+ pax_force_retaddr_bts
22631+ jmp irq_return
22632+#endif
22633 paranoid_swapgs:
22634+#ifdef CONFIG_PAX_MEMORY_UDEREF
22635+ pax_exit_kernel_user
22636+#else
22637+ pax_exit_kernel
22638+#endif
22639 TRACE_IRQS_IRETQ 0
22640 SWAPGS_UNSAFE_STACK
22641 RESTORE_ALL 8
22642 jmp irq_return
22643 paranoid_restore:
22644+ pax_exit_kernel
22645 TRACE_IRQS_IRETQ_DEBUG 0
22646 RESTORE_ALL 8
22647+ pax_force_retaddr_bts
22648 jmp irq_return
22649 paranoid_userspace:
22650 GET_THREAD_INFO(%rcx)
22651@@ -1541,7 +2086,7 @@ paranoid_schedule:
22652 TRACE_IRQS_OFF
22653 jmp paranoid_userspace
22654 CFI_ENDPROC
22655-END(paranoid_exit)
22656+ENDPROC(paranoid_exit)
22657
22658 /*
22659 * Exception entry point. This expects an error code/orig_rax on the stack.
22660@@ -1568,12 +2113,13 @@ ENTRY(error_entry)
22661 movq_cfi r14, R14+8
22662 movq_cfi r15, R15+8
22663 xorl %ebx,%ebx
22664- testl $3,CS+8(%rsp)
22665+ testb $3,CS+8(%rsp)
22666 je error_kernelspace
22667 error_swapgs:
22668 SWAPGS
22669 error_sti:
22670 TRACE_IRQS_OFF
22671+ pax_force_retaddr_bts
22672 ret
22673
22674 /*
22675@@ -1600,7 +2146,7 @@ bstep_iret:
22676 movq %rcx,RIP+8(%rsp)
22677 jmp error_swapgs
22678 CFI_ENDPROC
22679-END(error_entry)
22680+ENDPROC(error_entry)
22681
22682
22683 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22684@@ -1611,7 +2157,7 @@ ENTRY(error_exit)
22685 DISABLE_INTERRUPTS(CLBR_NONE)
22686 TRACE_IRQS_OFF
22687 GET_THREAD_INFO(%rcx)
22688- testl %eax,%eax
22689+ testl $1,%eax
22690 jne retint_kernel
22691 LOCKDEP_SYS_EXIT_IRQ
22692 movl TI_flags(%rcx),%edx
22693@@ -1620,7 +2166,7 @@ ENTRY(error_exit)
22694 jnz retint_careful
22695 jmp retint_swapgs
22696 CFI_ENDPROC
22697-END(error_exit)
22698+ENDPROC(error_exit)
22699
22700 /*
22701 * Test if a given stack is an NMI stack or not.
22702@@ -1678,9 +2224,11 @@ ENTRY(nmi)
22703 * If %cs was not the kernel segment, then the NMI triggered in user
22704 * space, which means it is definitely not nested.
22705 */
22706+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22707+ je 1f
22708 cmpl $__KERNEL_CS, 16(%rsp)
22709 jne first_nmi
22710-
22711+1:
22712 /*
22713 * Check the special variable on the stack to see if NMIs are
22714 * executing.
22715@@ -1714,8 +2262,7 @@ nested_nmi:
22716
22717 1:
22718 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22719- leaq -1*8(%rsp), %rdx
22720- movq %rdx, %rsp
22721+ subq $8, %rsp
22722 CFI_ADJUST_CFA_OFFSET 1*8
22723 leaq -10*8(%rsp), %rdx
22724 pushq_cfi $__KERNEL_DS
22725@@ -1733,6 +2280,7 @@ nested_nmi_out:
22726 CFI_RESTORE rdx
22727
22728 /* No need to check faults here */
22729+# pax_force_retaddr_bts
22730 INTERRUPT_RETURN
22731
22732 CFI_RESTORE_STATE
22733@@ -1849,6 +2397,8 @@ end_repeat_nmi:
22734 */
22735 movq %cr2, %r12
22736
22737+ pax_enter_kernel_nmi
22738+
22739 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22740 movq %rsp,%rdi
22741 movq $-1,%rsi
22742@@ -1861,26 +2411,31 @@ end_repeat_nmi:
22743 movq %r12, %cr2
22744 1:
22745
22746- testl %ebx,%ebx /* swapgs needed? */
22747+ testl $1,%ebx /* swapgs needed? */
22748 jnz nmi_restore
22749 nmi_swapgs:
22750 SWAPGS_UNSAFE_STACK
22751 nmi_restore:
22752+ pax_exit_kernel_nmi
22753 /* Pop the extra iret frame at once */
22754 RESTORE_ALL 6*8
22755+ testb $3, 8(%rsp)
22756+ jnz 1f
22757+ pax_force_retaddr_bts
22758+1:
22759
22760 /* Clear the NMI executing stack variable */
22761 movq $0, 5*8(%rsp)
22762 jmp irq_return
22763 CFI_ENDPROC
22764-END(nmi)
22765+ENDPROC(nmi)
22766
22767 ENTRY(ignore_sysret)
22768 CFI_STARTPROC
22769 mov $-ENOSYS,%eax
22770 sysret
22771 CFI_ENDPROC
22772-END(ignore_sysret)
22773+ENDPROC(ignore_sysret)
22774
22775 /*
22776 * End of kprobes section
22777diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22778index 42a392a..fbbd930 100644
22779--- a/arch/x86/kernel/ftrace.c
22780+++ b/arch/x86/kernel/ftrace.c
22781@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22782 {
22783 unsigned char replaced[MCOUNT_INSN_SIZE];
22784
22785+ ip = ktla_ktva(ip);
22786+
22787 /*
22788 * Note: Due to modules and __init, code can
22789 * disappear and change, we need to protect against faulting
22790@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22791 unsigned char old[MCOUNT_INSN_SIZE], *new;
22792 int ret;
22793
22794- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22795+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22796 new = ftrace_call_replace(ip, (unsigned long)func);
22797
22798 /* See comment above by declaration of modifying_ftrace_code */
22799@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22800 /* Also update the regs callback function */
22801 if (!ret) {
22802 ip = (unsigned long)(&ftrace_regs_call);
22803- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22804+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22805 new = ftrace_call_replace(ip, (unsigned long)func);
22806 ret = ftrace_modify_code(ip, old, new);
22807 }
22808@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22809 * kernel identity mapping to modify code.
22810 */
22811 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22812- ip = (unsigned long)__va(__pa_symbol(ip));
22813+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22814
22815 return probe_kernel_write((void *)ip, val, size);
22816 }
22817@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
22818 unsigned char replaced[MCOUNT_INSN_SIZE];
22819 unsigned char brk = BREAKPOINT_INSTRUCTION;
22820
22821- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22822+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22823 return -EFAULT;
22824
22825 /* Make sure it is what we expect it to be */
22826@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22827 return ret;
22828
22829 fail_update:
22830- probe_kernel_write((void *)ip, &old_code[0], 1);
22831+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22832 goto out;
22833 }
22834
22835@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22836 {
22837 unsigned char code[MCOUNT_INSN_SIZE];
22838
22839+ ip = ktla_ktva(ip);
22840+
22841 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22842 return -EFAULT;
22843
22844diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22845index 55b6761..a6456fc 100644
22846--- a/arch/x86/kernel/head64.c
22847+++ b/arch/x86/kernel/head64.c
22848@@ -67,12 +67,12 @@ again:
22849 pgd = *pgd_p;
22850
22851 /*
22852- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22853- * critical -- __PAGE_OFFSET would point us back into the dynamic
22854+ * The use of __early_va rather than __va here is critical:
22855+ * __va would point us back into the dynamic
22856 * range and we might end up looping forever...
22857 */
22858 if (pgd)
22859- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22860+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22861 else {
22862 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22863 reset_early_page_tables();
22864@@ -82,13 +82,13 @@ again:
22865 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22866 for (i = 0; i < PTRS_PER_PUD; i++)
22867 pud_p[i] = 0;
22868- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22869+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22870 }
22871 pud_p += pud_index(address);
22872 pud = *pud_p;
22873
22874 if (pud)
22875- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22876+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22877 else {
22878 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22879 reset_early_page_tables();
22880@@ -98,7 +98,7 @@ again:
22881 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22882 for (i = 0; i < PTRS_PER_PMD; i++)
22883 pmd_p[i] = 0;
22884- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22885+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22886 }
22887 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22888 pmd_p[pmd_index(address)] = pmd;
22889@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
22890 if (console_loglevel == 10)
22891 early_printk("Kernel alive\n");
22892
22893- clear_page(init_level4_pgt);
22894 /* set init_level4_pgt kernel high mapping*/
22895 init_level4_pgt[511] = early_level4_pgt[511];
22896
22897diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22898index 73afd11..0ef46f2 100644
22899--- a/arch/x86/kernel/head_32.S
22900+++ b/arch/x86/kernel/head_32.S
22901@@ -26,6 +26,12 @@
22902 /* Physical address */
22903 #define pa(X) ((X) - __PAGE_OFFSET)
22904
22905+#ifdef CONFIG_PAX_KERNEXEC
22906+#define ta(X) (X)
22907+#else
22908+#define ta(X) ((X) - __PAGE_OFFSET)
22909+#endif
22910+
22911 /*
22912 * References to members of the new_cpu_data structure.
22913 */
22914@@ -55,11 +61,7 @@
22915 * and small than max_low_pfn, otherwise will waste some page table entries
22916 */
22917
22918-#if PTRS_PER_PMD > 1
22919-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22920-#else
22921-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22922-#endif
22923+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22924
22925 /* Number of possible pages in the lowmem region */
22926 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22927@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22928 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22929
22930 /*
22931+ * Real beginning of normal "text" segment
22932+ */
22933+ENTRY(stext)
22934+ENTRY(_stext)
22935+
22936+/*
22937 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22938 * %esi points to the real-mode code as a 32-bit pointer.
22939 * CS and DS must be 4 GB flat segments, but we don't depend on
22940@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22941 * can.
22942 */
22943 __HEAD
22944+
22945+#ifdef CONFIG_PAX_KERNEXEC
22946+ jmp startup_32
22947+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22948+.fill PAGE_SIZE-5,1,0xcc
22949+#endif
22950+
22951 ENTRY(startup_32)
22952 movl pa(stack_start),%ecx
22953
22954@@ -106,6 +121,59 @@ ENTRY(startup_32)
22955 2:
22956 leal -__PAGE_OFFSET(%ecx),%esp
22957
22958+#ifdef CONFIG_SMP
22959+ movl $pa(cpu_gdt_table),%edi
22960+ movl $__per_cpu_load,%eax
22961+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22962+ rorl $16,%eax
22963+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22964+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22965+ movl $__per_cpu_end - 1,%eax
22966+ subl $__per_cpu_start,%eax
22967+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22968+#endif
22969+
22970+#ifdef CONFIG_PAX_MEMORY_UDEREF
22971+ movl $NR_CPUS,%ecx
22972+ movl $pa(cpu_gdt_table),%edi
22973+1:
22974+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22975+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22976+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22977+ addl $PAGE_SIZE_asm,%edi
22978+ loop 1b
22979+#endif
22980+
22981+#ifdef CONFIG_PAX_KERNEXEC
22982+ movl $pa(boot_gdt),%edi
22983+ movl $__LOAD_PHYSICAL_ADDR,%eax
22984+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22985+ rorl $16,%eax
22986+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22987+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22988+ rorl $16,%eax
22989+
22990+ ljmp $(__BOOT_CS),$1f
22991+1:
22992+
22993+ movl $NR_CPUS,%ecx
22994+ movl $pa(cpu_gdt_table),%edi
22995+ addl $__PAGE_OFFSET,%eax
22996+1:
22997+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22998+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22999+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
23000+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
23001+ rorl $16,%eax
23002+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
23003+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
23004+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
23005+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
23006+ rorl $16,%eax
23007+ addl $PAGE_SIZE_asm,%edi
23008+ loop 1b
23009+#endif
23010+
23011 /*
23012 * Clear BSS first so that there are no surprises...
23013 */
23014@@ -201,8 +269,11 @@ ENTRY(startup_32)
23015 movl %eax, pa(max_pfn_mapped)
23016
23017 /* Do early initialization of the fixmap area */
23018- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23019- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
23020+#ifdef CONFIG_COMPAT_VDSO
23021+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
23022+#else
23023+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
23024+#endif
23025 #else /* Not PAE */
23026
23027 page_pde_offset = (__PAGE_OFFSET >> 20);
23028@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23029 movl %eax, pa(max_pfn_mapped)
23030
23031 /* Do early initialization of the fixmap area */
23032- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23033- movl %eax,pa(initial_page_table+0xffc)
23034+#ifdef CONFIG_COMPAT_VDSO
23035+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
23036+#else
23037+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
23038+#endif
23039 #endif
23040
23041 #ifdef CONFIG_PARAVIRT
23042@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23043 cmpl $num_subarch_entries, %eax
23044 jae bad_subarch
23045
23046- movl pa(subarch_entries)(,%eax,4), %eax
23047- subl $__PAGE_OFFSET, %eax
23048- jmp *%eax
23049+ jmp *pa(subarch_entries)(,%eax,4)
23050
23051 bad_subarch:
23052 WEAK(lguest_entry)
23053@@ -261,10 +333,10 @@ WEAK(xen_entry)
23054 __INITDATA
23055
23056 subarch_entries:
23057- .long default_entry /* normal x86/PC */
23058- .long lguest_entry /* lguest hypervisor */
23059- .long xen_entry /* Xen hypervisor */
23060- .long default_entry /* Moorestown MID */
23061+ .long ta(default_entry) /* normal x86/PC */
23062+ .long ta(lguest_entry) /* lguest hypervisor */
23063+ .long ta(xen_entry) /* Xen hypervisor */
23064+ .long ta(default_entry) /* Moorestown MID */
23065 num_subarch_entries = (. - subarch_entries) / 4
23066 .previous
23067 #else
23068@@ -355,6 +427,7 @@ default_entry:
23069 movl pa(mmu_cr4_features),%eax
23070 movl %eax,%cr4
23071
23072+#ifdef CONFIG_X86_PAE
23073 testb $X86_CR4_PAE, %al # check if PAE is enabled
23074 jz enable_paging
23075
23076@@ -383,6 +456,9 @@ default_entry:
23077 /* Make changes effective */
23078 wrmsr
23079
23080+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
23081+#endif
23082+
23083 enable_paging:
23084
23085 /*
23086@@ -451,14 +527,20 @@ is486:
23087 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
23088 movl %eax,%ss # after changing gdt.
23089
23090- movl $(__USER_DS),%eax # DS/ES contains default USER segment
23091+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
23092 movl %eax,%ds
23093 movl %eax,%es
23094
23095 movl $(__KERNEL_PERCPU), %eax
23096 movl %eax,%fs # set this cpu's percpu
23097
23098+#ifdef CONFIG_CC_STACKPROTECTOR
23099 movl $(__KERNEL_STACK_CANARY),%eax
23100+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23101+ movl $(__USER_DS),%eax
23102+#else
23103+ xorl %eax,%eax
23104+#endif
23105 movl %eax,%gs
23106
23107 xorl %eax,%eax # Clear LDT
23108@@ -534,8 +616,11 @@ setup_once:
23109 * relocation. Manually set base address in stack canary
23110 * segment descriptor.
23111 */
23112- movl $gdt_page,%eax
23113+ movl $cpu_gdt_table,%eax
23114 movl $stack_canary,%ecx
23115+#ifdef CONFIG_SMP
23116+ addl $__per_cpu_load,%ecx
23117+#endif
23118 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
23119 shrl $16, %ecx
23120 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
23121@@ -566,7 +651,7 @@ ENDPROC(early_idt_handlers)
23122 /* This is global to keep gas from relaxing the jumps */
23123 ENTRY(early_idt_handler)
23124 cld
23125- cmpl $2,%ss:early_recursion_flag
23126+ cmpl $1,%ss:early_recursion_flag
23127 je hlt_loop
23128 incl %ss:early_recursion_flag
23129
23130@@ -604,8 +689,8 @@ ENTRY(early_idt_handler)
23131 pushl (20+6*4)(%esp) /* trapno */
23132 pushl $fault_msg
23133 call printk
23134-#endif
23135 call dump_stack
23136+#endif
23137 hlt_loop:
23138 hlt
23139 jmp hlt_loop
23140@@ -624,8 +709,11 @@ ENDPROC(early_idt_handler)
23141 /* This is the default interrupt "handler" :-) */
23142 ALIGN
23143 ignore_int:
23144- cld
23145 #ifdef CONFIG_PRINTK
23146+ cmpl $2,%ss:early_recursion_flag
23147+ je hlt_loop
23148+ incl %ss:early_recursion_flag
23149+ cld
23150 pushl %eax
23151 pushl %ecx
23152 pushl %edx
23153@@ -634,9 +722,6 @@ ignore_int:
23154 movl $(__KERNEL_DS),%eax
23155 movl %eax,%ds
23156 movl %eax,%es
23157- cmpl $2,early_recursion_flag
23158- je hlt_loop
23159- incl early_recursion_flag
23160 pushl 16(%esp)
23161 pushl 24(%esp)
23162 pushl 32(%esp)
23163@@ -670,29 +755,43 @@ ENTRY(setup_once_ref)
23164 /*
23165 * BSS section
23166 */
23167-__PAGE_ALIGNED_BSS
23168- .align PAGE_SIZE
23169 #ifdef CONFIG_X86_PAE
23170+.section .initial_pg_pmd,"a",@progbits
23171 initial_pg_pmd:
23172 .fill 1024*KPMDS,4,0
23173 #else
23174+.section .initial_page_table,"a",@progbits
23175 ENTRY(initial_page_table)
23176 .fill 1024,4,0
23177 #endif
23178+.section .initial_pg_fixmap,"a",@progbits
23179 initial_pg_fixmap:
23180 .fill 1024,4,0
23181+.section .empty_zero_page,"a",@progbits
23182 ENTRY(empty_zero_page)
23183 .fill 4096,1,0
23184+.section .swapper_pg_dir,"a",@progbits
23185 ENTRY(swapper_pg_dir)
23186+#ifdef CONFIG_X86_PAE
23187+ .fill 4,8,0
23188+#else
23189 .fill 1024,4,0
23190+#endif
23191+
23192+/*
23193+ * The IDT has to be page-aligned to simplify the Pentium
23194+ * F0 0F bug workaround.. We have a special link segment
23195+ * for this.
23196+ */
23197+.section .idt,"a",@progbits
23198+ENTRY(idt_table)
23199+ .fill 256,8,0
23200
23201 /*
23202 * This starts the data section.
23203 */
23204 #ifdef CONFIG_X86_PAE
23205-__PAGE_ALIGNED_DATA
23206- /* Page-aligned for the benefit of paravirt? */
23207- .align PAGE_SIZE
23208+.section .initial_page_table,"a",@progbits
23209 ENTRY(initial_page_table)
23210 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
23211 # if KPMDS == 3
23212@@ -711,12 +810,20 @@ ENTRY(initial_page_table)
23213 # error "Kernel PMDs should be 1, 2 or 3"
23214 # endif
23215 .align PAGE_SIZE /* needs to be page-sized too */
23216+
23217+#ifdef CONFIG_PAX_PER_CPU_PGD
23218+ENTRY(cpu_pgd)
23219+ .rept 2*NR_CPUS
23220+ .fill 4,8,0
23221+ .endr
23222+#endif
23223+
23224 #endif
23225
23226 .data
23227 .balign 4
23228 ENTRY(stack_start)
23229- .long init_thread_union+THREAD_SIZE
23230+ .long init_thread_union+THREAD_SIZE-8
23231
23232 __INITRODATA
23233 int_msg:
23234@@ -744,7 +851,7 @@ fault_msg:
23235 * segment size, and 32-bit linear address value:
23236 */
23237
23238- .data
23239+.section .rodata,"a",@progbits
23240 .globl boot_gdt_descr
23241 .globl idt_descr
23242
23243@@ -753,7 +860,7 @@ fault_msg:
23244 .word 0 # 32 bit align gdt_desc.address
23245 boot_gdt_descr:
23246 .word __BOOT_DS+7
23247- .long boot_gdt - __PAGE_OFFSET
23248+ .long pa(boot_gdt)
23249
23250 .word 0 # 32-bit align idt_desc.address
23251 idt_descr:
23252@@ -764,7 +871,7 @@ idt_descr:
23253 .word 0 # 32 bit align gdt_desc.address
23254 ENTRY(early_gdt_descr)
23255 .word GDT_ENTRIES*8-1
23256- .long gdt_page /* Overwritten for secondary CPUs */
23257+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
23258
23259 /*
23260 * The boot_gdt must mirror the equivalent in setup.S and is
23261@@ -773,5 +880,65 @@ ENTRY(early_gdt_descr)
23262 .align L1_CACHE_BYTES
23263 ENTRY(boot_gdt)
23264 .fill GDT_ENTRY_BOOT_CS,8,0
23265- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
23266- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
23267+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
23268+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
23269+
23270+ .align PAGE_SIZE_asm
23271+ENTRY(cpu_gdt_table)
23272+ .rept NR_CPUS
23273+ .quad 0x0000000000000000 /* NULL descriptor */
23274+ .quad 0x0000000000000000 /* 0x0b reserved */
23275+ .quad 0x0000000000000000 /* 0x13 reserved */
23276+ .quad 0x0000000000000000 /* 0x1b reserved */
23277+
23278+#ifdef CONFIG_PAX_KERNEXEC
23279+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
23280+#else
23281+ .quad 0x0000000000000000 /* 0x20 unused */
23282+#endif
23283+
23284+ .quad 0x0000000000000000 /* 0x28 unused */
23285+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23286+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23287+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23288+ .quad 0x0000000000000000 /* 0x4b reserved */
23289+ .quad 0x0000000000000000 /* 0x53 reserved */
23290+ .quad 0x0000000000000000 /* 0x5b reserved */
23291+
23292+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23293+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23294+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23295+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23296+
23297+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23298+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23299+
23300+ /*
23301+ * Segments used for calling PnP BIOS have byte granularity.
23302+ * The code segments and data segments have fixed 64k limits,
23303+ * the transfer segment sizes are set at run time.
23304+ */
23305+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23306+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23307+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23308+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23309+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23310+
23311+ /*
23312+ * The APM segments have byte granularity and their bases
23313+ * are set at run time. All have 64k limits.
23314+ */
23315+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23316+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23317+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23318+
23319+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23320+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23321+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23322+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23323+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23324+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23325+
23326+ /* Be sure this is zeroed to avoid false validations in Xen */
23327+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23328+ .endr
23329diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23330index a836860..1b5c665 100644
23331--- a/arch/x86/kernel/head_64.S
23332+++ b/arch/x86/kernel/head_64.S
23333@@ -20,6 +20,8 @@
23334 #include <asm/processor-flags.h>
23335 #include <asm/percpu.h>
23336 #include <asm/nops.h>
23337+#include <asm/cpufeature.h>
23338+#include <asm/alternative-asm.h>
23339
23340 #ifdef CONFIG_PARAVIRT
23341 #include <asm/asm-offsets.h>
23342@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23343 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23344 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23345 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23346+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23347+L3_VMALLOC_START = pud_index(VMALLOC_START)
23348+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23349+L3_VMALLOC_END = pud_index(VMALLOC_END)
23350+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23351+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23352
23353 .text
23354 __HEAD
23355@@ -89,11 +97,23 @@ startup_64:
23356 * Fixup the physical addresses in the page table
23357 */
23358 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23359+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23360+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23361+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23362+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23363+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23364
23365- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23366- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23367+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23368+#ifndef CONFIG_XEN
23369+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23370+#endif
23371
23372- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23373+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23374+
23375+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23376+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23377+
23378+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23379
23380 /*
23381 * Set up the identity mapping for the switchover. These
23382@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
23383 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23384 1:
23385
23386- /* Enable PAE mode and PGE */
23387- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23388+ /* Enable PAE mode and PSE/PGE */
23389+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23390 movq %rcx, %cr4
23391
23392 /* Setup early boot stage 4 level pagetables. */
23393@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
23394 movl $MSR_EFER, %ecx
23395 rdmsr
23396 btsl $_EFER_SCE, %eax /* Enable System Call */
23397- btl $20,%edi /* No Execute supported? */
23398+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23399 jnc 1f
23400 btsl $_EFER_NX, %eax
23401 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23402+ leaq init_level4_pgt(%rip), %rdi
23403+#ifndef CONFIG_EFI
23404+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
23405+#endif
23406+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
23407+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
23408+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
23409+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23410 1: wrmsr /* Make changes effective */
23411
23412 /* Setup cr0 */
23413@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
23414 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23415 * address given in m16:64.
23416 */
23417+ pax_set_fptr_mask
23418 movq initial_code(%rip),%rax
23419 pushq $0 # fake return address to stop unwinder
23420 pushq $__KERNEL_CS # set correct cs
23421@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
23422 call dump_stack
23423 #ifdef CONFIG_KALLSYMS
23424 leaq early_idt_ripmsg(%rip),%rdi
23425- movq 40(%rsp),%rsi # %rip again
23426+ movq 88(%rsp),%rsi # %rip again
23427 call __print_symbol
23428 #endif
23429 #endif /* EARLY_PRINTK */
23430@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
23431 early_recursion_flag:
23432 .long 0
23433
23434+ .section .rodata,"a",@progbits
23435 #ifdef CONFIG_EARLY_PRINTK
23436 early_idt_msg:
23437 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23438@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
23439 NEXT_PAGE(early_dynamic_pgts)
23440 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23441
23442- .data
23443+ .section .rodata,"a",@progbits
23444
23445-#ifndef CONFIG_XEN
23446 NEXT_PAGE(init_level4_pgt)
23447- .fill 512,8,0
23448-#else
23449-NEXT_PAGE(init_level4_pgt)
23450- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23451 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23452 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23453+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23454+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23455+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23456+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23457+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23458+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23459 .org init_level4_pgt + L4_START_KERNEL*8, 0
23460 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23461 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23462
23463+#ifdef CONFIG_PAX_PER_CPU_PGD
23464+NEXT_PAGE(cpu_pgd)
23465+ .rept 2*NR_CPUS
23466+ .fill 512,8,0
23467+ .endr
23468+#endif
23469+
23470 NEXT_PAGE(level3_ident_pgt)
23471 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23472+#ifdef CONFIG_XEN
23473 .fill 511, 8, 0
23474+#else
23475+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23476+ .fill 510,8,0
23477+#endif
23478+
23479+NEXT_PAGE(level3_vmalloc_start_pgt)
23480+ .fill 512,8,0
23481+
23482+NEXT_PAGE(level3_vmalloc_end_pgt)
23483+ .fill 512,8,0
23484+
23485+NEXT_PAGE(level3_vmemmap_pgt)
23486+ .fill L3_VMEMMAP_START,8,0
23487+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23488+
23489 NEXT_PAGE(level2_ident_pgt)
23490- /* Since I easily can, map the first 1G.
23491+ /* Since I easily can, map the first 2G.
23492 * Don't set NX because code runs from these pages.
23493 */
23494- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23495-#endif
23496+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23497
23498 NEXT_PAGE(level3_kernel_pgt)
23499 .fill L3_START_KERNEL,8,0
23500@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
23501 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23502 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23503
23504+NEXT_PAGE(level2_vmemmap_pgt)
23505+ .fill 512,8,0
23506+
23507 NEXT_PAGE(level2_kernel_pgt)
23508 /*
23509 * 512 MB kernel mapping. We spend a full page on this pagetable
23510@@ -488,39 +544,70 @@ NEXT_PAGE(level2_kernel_pgt)
23511 KERNEL_IMAGE_SIZE/PMD_SIZE)
23512
23513 NEXT_PAGE(level2_fixmap_pgt)
23514- .fill 506,8,0
23515- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23516- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23517- .fill 5,8,0
23518+ .fill 507,8,0
23519+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23520+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23521+ .fill 4,8,0
23522
23523-NEXT_PAGE(level1_fixmap_pgt)
23524+NEXT_PAGE(level1_vsyscall_pgt)
23525 .fill 512,8,0
23526
23527 #undef PMDS
23528
23529- .data
23530+ .align PAGE_SIZE
23531+ENTRY(cpu_gdt_table)
23532+ .rept NR_CPUS
23533+ .quad 0x0000000000000000 /* NULL descriptor */
23534+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23535+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23536+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23537+ .quad 0x00cffb000000ffff /* __USER32_CS */
23538+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23539+ .quad 0x00affb000000ffff /* __USER_CS */
23540+
23541+#ifdef CONFIG_PAX_KERNEXEC
23542+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23543+#else
23544+ .quad 0x0 /* unused */
23545+#endif
23546+
23547+ .quad 0,0 /* TSS */
23548+ .quad 0,0 /* LDT */
23549+ .quad 0,0,0 /* three TLS descriptors */
23550+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23551+ /* asm/segment.h:GDT_ENTRIES must match this */
23552+
23553+#ifdef CONFIG_PAX_MEMORY_UDEREF
23554+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23555+#else
23556+ .quad 0x0 /* unused */
23557+#endif
23558+
23559+ /* zero the remaining page */
23560+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23561+ .endr
23562+
23563 .align 16
23564 .globl early_gdt_descr
23565 early_gdt_descr:
23566 .word GDT_ENTRIES*8-1
23567 early_gdt_descr_base:
23568- .quad INIT_PER_CPU_VAR(gdt_page)
23569+ .quad cpu_gdt_table
23570
23571 ENTRY(phys_base)
23572 /* This must match the first entry in level2_kernel_pgt */
23573 .quad 0x0000000000000000
23574
23575 #include "../../x86/xen/xen-head.S"
23576-
23577- .section .bss, "aw", @nobits
23578+
23579+ .section .rodata,"a",@progbits
23580+NEXT_PAGE(empty_zero_page)
23581+ .skip PAGE_SIZE
23582+
23583 .align PAGE_SIZE
23584 ENTRY(idt_table)
23585- .skip IDT_ENTRIES * 16
23586+ .fill 512,8,0
23587
23588 .align L1_CACHE_BYTES
23589 ENTRY(nmi_idt_table)
23590- .skip IDT_ENTRIES * 16
23591-
23592- __PAGE_ALIGNED_BSS
23593-NEXT_PAGE(empty_zero_page)
23594- .skip PAGE_SIZE
23595+ .fill 512,8,0
23596diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23597index 0fa6912..b37438b 100644
23598--- a/arch/x86/kernel/i386_ksyms_32.c
23599+++ b/arch/x86/kernel/i386_ksyms_32.c
23600@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23601 EXPORT_SYMBOL(cmpxchg8b_emu);
23602 #endif
23603
23604+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23605+
23606 /* Networking helper routines. */
23607 EXPORT_SYMBOL(csum_partial_copy_generic);
23608+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23609+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23610
23611 EXPORT_SYMBOL(__get_user_1);
23612 EXPORT_SYMBOL(__get_user_2);
23613@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23614
23615 EXPORT_SYMBOL(csum_partial);
23616 EXPORT_SYMBOL(empty_zero_page);
23617+
23618+#ifdef CONFIG_PAX_KERNEXEC
23619+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23620+#endif
23621+
23622+#ifdef CONFIG_PAX_PER_CPU_PGD
23623+EXPORT_SYMBOL(cpu_pgd);
23624+#endif
23625diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23626index f7ea30d..6318acc 100644
23627--- a/arch/x86/kernel/i387.c
23628+++ b/arch/x86/kernel/i387.c
23629@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23630 static inline bool interrupted_user_mode(void)
23631 {
23632 struct pt_regs *regs = get_irq_regs();
23633- return regs && user_mode_vm(regs);
23634+ return regs && user_mode(regs);
23635 }
23636
23637 /*
23638diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23639index 9a5c460..84868423 100644
23640--- a/arch/x86/kernel/i8259.c
23641+++ b/arch/x86/kernel/i8259.c
23642@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23643 static void make_8259A_irq(unsigned int irq)
23644 {
23645 disable_irq_nosync(irq);
23646- io_apic_irqs &= ~(1<<irq);
23647+ io_apic_irqs &= ~(1UL<<irq);
23648 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23649 i8259A_chip.name);
23650 enable_irq(irq);
23651@@ -209,7 +209,7 @@ spurious_8259A_irq:
23652 "spurious 8259A interrupt: IRQ%d.\n", irq);
23653 spurious_irq_mask |= irqmask;
23654 }
23655- atomic_inc(&irq_err_count);
23656+ atomic_inc_unchecked(&irq_err_count);
23657 /*
23658 * Theoretically we do not have to handle this IRQ,
23659 * but in Linux this does not cause problems and is
23660@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23661 /* (slave's support for AEOI in flat mode is to be investigated) */
23662 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23663
23664+ pax_open_kernel();
23665 if (auto_eoi)
23666 /*
23667 * In AEOI mode we just have to mask the interrupt
23668 * when acking.
23669 */
23670- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23671+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23672 else
23673- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23674+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23675+ pax_close_kernel();
23676
23677 udelay(100); /* wait for 8259A to initialize */
23678
23679diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23680index a979b5b..1d6db75 100644
23681--- a/arch/x86/kernel/io_delay.c
23682+++ b/arch/x86/kernel/io_delay.c
23683@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23684 * Quirk table for systems that misbehave (lock up, etc.) if port
23685 * 0x80 is used:
23686 */
23687-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23688+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23689 {
23690 .callback = dmi_io_delay_0xed_port,
23691 .ident = "Compaq Presario V6000",
23692diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23693index 4ddaf66..6292f4e 100644
23694--- a/arch/x86/kernel/ioport.c
23695+++ b/arch/x86/kernel/ioport.c
23696@@ -6,6 +6,7 @@
23697 #include <linux/sched.h>
23698 #include <linux/kernel.h>
23699 #include <linux/capability.h>
23700+#include <linux/security.h>
23701 #include <linux/errno.h>
23702 #include <linux/types.h>
23703 #include <linux/ioport.h>
23704@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23705
23706 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
23707 return -EINVAL;
23708+#ifdef CONFIG_GRKERNSEC_IO
23709+ if (turn_on && grsec_disable_privio) {
23710+ gr_handle_ioperm();
23711+ return -EPERM;
23712+ }
23713+#endif
23714 if (turn_on && !capable(CAP_SYS_RAWIO))
23715 return -EPERM;
23716
23717@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23718 * because the ->io_bitmap_max value must match the bitmap
23719 * contents:
23720 */
23721- tss = &per_cpu(init_tss, get_cpu());
23722+ tss = init_tss + get_cpu();
23723
23724 if (turn_on)
23725 bitmap_clear(t->io_bitmap_ptr, from, num);
23726@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23727 return -EINVAL;
23728 /* Trying to gain more privileges? */
23729 if (level > old) {
23730+#ifdef CONFIG_GRKERNSEC_IO
23731+ if (grsec_disable_privio) {
23732+ gr_handle_iopl();
23733+ return -EPERM;
23734+ }
23735+#endif
23736 if (!capable(CAP_SYS_RAWIO))
23737 return -EPERM;
23738 }
23739diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23740index ac0631d..ff7cb62 100644
23741--- a/arch/x86/kernel/irq.c
23742+++ b/arch/x86/kernel/irq.c
23743@@ -18,7 +18,7 @@
23744 #include <asm/mce.h>
23745 #include <asm/hw_irq.h>
23746
23747-atomic_t irq_err_count;
23748+atomic_unchecked_t irq_err_count;
23749
23750 /* Function pointer for generic interrupt vector handling */
23751 void (*x86_platform_ipi_callback)(void) = NULL;
23752@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23753 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23754 seq_printf(p, " Machine check polls\n");
23755 #endif
23756- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23757+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23758 #if defined(CONFIG_X86_IO_APIC)
23759- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23760+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23761 #endif
23762 return 0;
23763 }
23764@@ -164,7 +164,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23765
23766 u64 arch_irq_stat(void)
23767 {
23768- u64 sum = atomic_read(&irq_err_count);
23769+ u64 sum = atomic_read_unchecked(&irq_err_count);
23770 return sum;
23771 }
23772
23773diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23774index 344faf8..355f60d 100644
23775--- a/arch/x86/kernel/irq_32.c
23776+++ b/arch/x86/kernel/irq_32.c
23777@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23778 __asm__ __volatile__("andl %%esp,%0" :
23779 "=r" (sp) : "0" (THREAD_SIZE - 1));
23780
23781- return sp < (sizeof(struct thread_info) + STACK_WARN);
23782+ return sp < STACK_WARN;
23783 }
23784
23785 static void print_stack_overflow(void)
23786@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23787 * per-CPU IRQ handling contexts (thread information and stack)
23788 */
23789 union irq_ctx {
23790- struct thread_info tinfo;
23791- u32 stack[THREAD_SIZE/sizeof(u32)];
23792+ unsigned long previous_esp;
23793+ u32 stack[THREAD_SIZE/sizeof(u32)];
23794 } __attribute__((aligned(THREAD_SIZE)));
23795
23796 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23797@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23798 static inline int
23799 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23800 {
23801- union irq_ctx *curctx, *irqctx;
23802+ union irq_ctx *irqctx;
23803 u32 *isp, arg1, arg2;
23804
23805- curctx = (union irq_ctx *) current_thread_info();
23806 irqctx = __this_cpu_read(hardirq_ctx);
23807
23808 /*
23809@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23810 * handler) we can't do that and just have to keep using the
23811 * current stack (which is the irq stack already after all)
23812 */
23813- if (unlikely(curctx == irqctx))
23814+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23815 return 0;
23816
23817 /* build the stack frame on the IRQ stack */
23818- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23819- irqctx->tinfo.task = curctx->tinfo.task;
23820- irqctx->tinfo.previous_esp = current_stack_pointer;
23821+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23822+ irqctx->previous_esp = current_stack_pointer;
23823
23824- /* Copy the preempt_count so that the [soft]irq checks work. */
23825- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23826+#ifdef CONFIG_PAX_MEMORY_UDEREF
23827+ __set_fs(MAKE_MM_SEG(0));
23828+#endif
23829
23830 if (unlikely(overflow))
23831 call_on_stack(print_stack_overflow, isp);
23832@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23833 : "0" (irq), "1" (desc), "2" (isp),
23834 "D" (desc->handle_irq)
23835 : "memory", "cc", "ecx");
23836+
23837+#ifdef CONFIG_PAX_MEMORY_UDEREF
23838+ __set_fs(current_thread_info()->addr_limit);
23839+#endif
23840+
23841 return 1;
23842 }
23843
23844@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23845 */
23846 void __cpuinit irq_ctx_init(int cpu)
23847 {
23848- union irq_ctx *irqctx;
23849-
23850 if (per_cpu(hardirq_ctx, cpu))
23851 return;
23852
23853- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23854- THREADINFO_GFP,
23855- THREAD_SIZE_ORDER));
23856- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23857- irqctx->tinfo.cpu = cpu;
23858- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23859- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23860-
23861- per_cpu(hardirq_ctx, cpu) = irqctx;
23862-
23863- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23864- THREADINFO_GFP,
23865- THREAD_SIZE_ORDER));
23866- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23867- irqctx->tinfo.cpu = cpu;
23868- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23869-
23870- per_cpu(softirq_ctx, cpu) = irqctx;
23871+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23872+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23873+
23874+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23875+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23876
23877 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23878 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23879@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
23880 asmlinkage void do_softirq(void)
23881 {
23882 unsigned long flags;
23883- struct thread_info *curctx;
23884 union irq_ctx *irqctx;
23885 u32 *isp;
23886
23887@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23888 local_irq_save(flags);
23889
23890 if (local_softirq_pending()) {
23891- curctx = current_thread_info();
23892 irqctx = __this_cpu_read(softirq_ctx);
23893- irqctx->tinfo.task = curctx->task;
23894- irqctx->tinfo.previous_esp = current_stack_pointer;
23895+ irqctx->previous_esp = current_stack_pointer;
23896
23897 /* build the stack frame on the softirq stack */
23898- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23899+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23900+
23901+#ifdef CONFIG_PAX_MEMORY_UDEREF
23902+ __set_fs(MAKE_MM_SEG(0));
23903+#endif
23904
23905 call_on_stack(__do_softirq, isp);
23906+
23907+#ifdef CONFIG_PAX_MEMORY_UDEREF
23908+ __set_fs(current_thread_info()->addr_limit);
23909+#endif
23910+
23911 /*
23912 * Shouldn't happen, we returned above if in_interrupt():
23913 */
23914@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23915 if (unlikely(!desc))
23916 return false;
23917
23918- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23919+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23920 if (unlikely(overflow))
23921 print_stack_overflow();
23922 desc->handle_irq(irq, desc);
23923diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23924index d04d3ec..ea4b374 100644
23925--- a/arch/x86/kernel/irq_64.c
23926+++ b/arch/x86/kernel/irq_64.c
23927@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23928 u64 estack_top, estack_bottom;
23929 u64 curbase = (u64)task_stack_page(current);
23930
23931- if (user_mode_vm(regs))
23932+ if (user_mode(regs))
23933 return;
23934
23935 if (regs->sp >= curbase + sizeof(struct thread_info) +
23936diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
23937index dc1404b..bbc43e7 100644
23938--- a/arch/x86/kernel/kdebugfs.c
23939+++ b/arch/x86/kernel/kdebugfs.c
23940@@ -27,7 +27,7 @@ struct setup_data_node {
23941 u32 len;
23942 };
23943
23944-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
23945+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
23946 size_t count, loff_t *ppos)
23947 {
23948 struct setup_data_node *node = file->private_data;
23949diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23950index 836f832..a8bda67 100644
23951--- a/arch/x86/kernel/kgdb.c
23952+++ b/arch/x86/kernel/kgdb.c
23953@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23954 #ifdef CONFIG_X86_32
23955 switch (regno) {
23956 case GDB_SS:
23957- if (!user_mode_vm(regs))
23958+ if (!user_mode(regs))
23959 *(unsigned long *)mem = __KERNEL_DS;
23960 break;
23961 case GDB_SP:
23962- if (!user_mode_vm(regs))
23963+ if (!user_mode(regs))
23964 *(unsigned long *)mem = kernel_stack_pointer(regs);
23965 break;
23966 case GDB_GS:
23967@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23968 bp->attr.bp_addr = breakinfo[breakno].addr;
23969 bp->attr.bp_len = breakinfo[breakno].len;
23970 bp->attr.bp_type = breakinfo[breakno].type;
23971- info->address = breakinfo[breakno].addr;
23972+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23973+ info->address = ktla_ktva(breakinfo[breakno].addr);
23974+ else
23975+ info->address = breakinfo[breakno].addr;
23976 info->len = breakinfo[breakno].len;
23977 info->type = breakinfo[breakno].type;
23978 val = arch_install_hw_breakpoint(bp);
23979@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23980 case 'k':
23981 /* clear the trace bit */
23982 linux_regs->flags &= ~X86_EFLAGS_TF;
23983- atomic_set(&kgdb_cpu_doing_single_step, -1);
23984+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23985
23986 /* set the trace bit if we're stepping */
23987 if (remcomInBuffer[0] == 's') {
23988 linux_regs->flags |= X86_EFLAGS_TF;
23989- atomic_set(&kgdb_cpu_doing_single_step,
23990+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23991 raw_smp_processor_id());
23992 }
23993
23994@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23995
23996 switch (cmd) {
23997 case DIE_DEBUG:
23998- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23999+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
24000 if (user_mode(regs))
24001 return single_step_cont(regs, args);
24002 break;
24003@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24004 #endif /* CONFIG_DEBUG_RODATA */
24005
24006 bpt->type = BP_BREAKPOINT;
24007- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
24008+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
24009 BREAK_INSTR_SIZE);
24010 if (err)
24011 return err;
24012- err = probe_kernel_write((char *)bpt->bpt_addr,
24013+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24014 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
24015 #ifdef CONFIG_DEBUG_RODATA
24016 if (!err)
24017@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24018 return -EBUSY;
24019 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
24020 BREAK_INSTR_SIZE);
24021- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24022+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24023 if (err)
24024 return err;
24025 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
24026@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
24027 if (mutex_is_locked(&text_mutex))
24028 goto knl_write;
24029 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
24030- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24031+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24032 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
24033 goto knl_write;
24034 return err;
24035 knl_write:
24036 #endif /* CONFIG_DEBUG_RODATA */
24037- return probe_kernel_write((char *)bpt->bpt_addr,
24038+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24039 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
24040 }
24041
24042diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
24043index 211bce4..6e2580a 100644
24044--- a/arch/x86/kernel/kprobes/core.c
24045+++ b/arch/x86/kernel/kprobes/core.c
24046@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
24047 s32 raddr;
24048 } __packed *insn;
24049
24050- insn = (struct __arch_relative_insn *)from;
24051+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
24052+
24053+ pax_open_kernel();
24054 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
24055 insn->op = op;
24056+ pax_close_kernel();
24057 }
24058
24059 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
24060@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
24061 kprobe_opcode_t opcode;
24062 kprobe_opcode_t *orig_opcodes = opcodes;
24063
24064- if (search_exception_tables((unsigned long)opcodes))
24065+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
24066 return 0; /* Page fault may occur on this address. */
24067
24068 retry:
24069@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
24070 * for the first byte, we can recover the original instruction
24071 * from it and kp->opcode.
24072 */
24073- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24074+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24075 buf[0] = kp->opcode;
24076- return (unsigned long)buf;
24077+ return ktva_ktla((unsigned long)buf);
24078 }
24079
24080 /*
24081@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24082 /* Another subsystem puts a breakpoint, failed to recover */
24083 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
24084 return 0;
24085+ pax_open_kernel();
24086 memcpy(dest, insn.kaddr, insn.length);
24087+ pax_close_kernel();
24088
24089 #ifdef CONFIG_X86_64
24090 if (insn_rip_relative(&insn)) {
24091@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24092 return 0;
24093 }
24094 disp = (u8 *) dest + insn_offset_displacement(&insn);
24095+ pax_open_kernel();
24096 *(s32 *) disp = (s32) newdisp;
24097+ pax_close_kernel();
24098 }
24099 #endif
24100 return insn.length;
24101@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24102 * nor set current_kprobe, because it doesn't use single
24103 * stepping.
24104 */
24105- regs->ip = (unsigned long)p->ainsn.insn;
24106+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24107 preempt_enable_no_resched();
24108 return;
24109 }
24110@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24111 regs->flags &= ~X86_EFLAGS_IF;
24112 /* single step inline if the instruction is an int3 */
24113 if (p->opcode == BREAKPOINT_INSTRUCTION)
24114- regs->ip = (unsigned long)p->addr;
24115+ regs->ip = ktla_ktva((unsigned long)p->addr);
24116 else
24117- regs->ip = (unsigned long)p->ainsn.insn;
24118+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24119 }
24120
24121 /*
24122@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
24123 setup_singlestep(p, regs, kcb, 0);
24124 return 1;
24125 }
24126- } else if (*addr != BREAKPOINT_INSTRUCTION) {
24127+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
24128 /*
24129 * The breakpoint instruction was removed right
24130 * after we hit it. Another cpu has removed
24131@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
24132 " movq %rax, 152(%rsp)\n"
24133 RESTORE_REGS_STRING
24134 " popfq\n"
24135+#ifdef KERNEXEC_PLUGIN
24136+ " btsq $63,(%rsp)\n"
24137+#endif
24138 #else
24139 " pushf\n"
24140 SAVE_REGS_STRING
24141@@ -779,7 +789,7 @@ static void __kprobes
24142 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
24143 {
24144 unsigned long *tos = stack_addr(regs);
24145- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
24146+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
24147 unsigned long orig_ip = (unsigned long)p->addr;
24148 kprobe_opcode_t *insn = p->ainsn.insn;
24149
24150@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
24151 struct die_args *args = data;
24152 int ret = NOTIFY_DONE;
24153
24154- if (args->regs && user_mode_vm(args->regs))
24155+ if (args->regs && user_mode(args->regs))
24156 return ret;
24157
24158 switch (val) {
24159diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
24160index 76dc6f0..66bdfc3 100644
24161--- a/arch/x86/kernel/kprobes/opt.c
24162+++ b/arch/x86/kernel/kprobes/opt.c
24163@@ -79,6 +79,7 @@ found:
24164 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
24165 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
24166 {
24167+ pax_open_kernel();
24168 #ifdef CONFIG_X86_64
24169 *addr++ = 0x48;
24170 *addr++ = 0xbf;
24171@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
24172 *addr++ = 0xb8;
24173 #endif
24174 *(unsigned long *)addr = val;
24175+ pax_close_kernel();
24176 }
24177
24178 static void __used __kprobes kprobes_optinsn_template_holder(void)
24179@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24180 * Verify if the address gap is in 2GB range, because this uses
24181 * a relative jump.
24182 */
24183- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
24184+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
24185 if (abs(rel) > 0x7fffffff)
24186 return -ERANGE;
24187
24188@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24189 op->optinsn.size = ret;
24190
24191 /* Copy arch-dep-instance from template */
24192- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
24193+ pax_open_kernel();
24194+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
24195+ pax_close_kernel();
24196
24197 /* Set probe information */
24198 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
24199
24200 /* Set probe function call */
24201- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
24202+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
24203
24204 /* Set returning jmp instruction at the tail of out-of-line buffer */
24205- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
24206+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
24207 (u8 *)op->kp.addr + op->optinsn.size);
24208
24209 flush_icache_range((unsigned long) buf,
24210@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
24211 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
24212
24213 /* Backup instructions which will be replaced by jump address */
24214- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
24215+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
24216 RELATIVE_ADDR_SIZE);
24217
24218 insn_buf[0] = RELATIVEJUMP_OPCODE;
24219@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
24220 /* This kprobe is really able to run optimized path. */
24221 op = container_of(p, struct optimized_kprobe, kp);
24222 /* Detour through copied instructions */
24223- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
24224+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
24225 if (!reenter)
24226 reset_current_kprobe();
24227 preempt_enable_no_resched();
24228diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
24229index cd6d9a5..16245a4 100644
24230--- a/arch/x86/kernel/kvm.c
24231+++ b/arch/x86/kernel/kvm.c
24232@@ -455,7 +455,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
24233 return NOTIFY_OK;
24234 }
24235
24236-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
24237+static struct notifier_block kvm_cpu_notifier = {
24238 .notifier_call = kvm_cpu_notify,
24239 };
24240 #endif
24241diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
24242index ebc9873..1b9724b 100644
24243--- a/arch/x86/kernel/ldt.c
24244+++ b/arch/x86/kernel/ldt.c
24245@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
24246 if (reload) {
24247 #ifdef CONFIG_SMP
24248 preempt_disable();
24249- load_LDT(pc);
24250+ load_LDT_nolock(pc);
24251 if (!cpumask_equal(mm_cpumask(current->mm),
24252 cpumask_of(smp_processor_id())))
24253 smp_call_function(flush_ldt, current->mm, 1);
24254 preempt_enable();
24255 #else
24256- load_LDT(pc);
24257+ load_LDT_nolock(pc);
24258 #endif
24259 }
24260 if (oldsize) {
24261@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
24262 return err;
24263
24264 for (i = 0; i < old->size; i++)
24265- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
24266+ write_ldt_entry(new->ldt, i, old->ldt + i);
24267 return 0;
24268 }
24269
24270@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
24271 retval = copy_ldt(&mm->context, &old_mm->context);
24272 mutex_unlock(&old_mm->context.lock);
24273 }
24274+
24275+ if (tsk == current) {
24276+ mm->context.vdso = 0;
24277+
24278+#ifdef CONFIG_X86_32
24279+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24280+ mm->context.user_cs_base = 0UL;
24281+ mm->context.user_cs_limit = ~0UL;
24282+
24283+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
24284+ cpus_clear(mm->context.cpu_user_cs_mask);
24285+#endif
24286+
24287+#endif
24288+#endif
24289+
24290+ }
24291+
24292 return retval;
24293 }
24294
24295@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
24296 }
24297 }
24298
24299+#ifdef CONFIG_PAX_SEGMEXEC
24300+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
24301+ error = -EINVAL;
24302+ goto out_unlock;
24303+ }
24304+#endif
24305+
24306 fill_ldt(&ldt, &ldt_info);
24307 if (oldmode)
24308 ldt.avl = 0;
24309diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
24310index 5b19e4d..6476a76 100644
24311--- a/arch/x86/kernel/machine_kexec_32.c
24312+++ b/arch/x86/kernel/machine_kexec_32.c
24313@@ -26,7 +26,7 @@
24314 #include <asm/cacheflush.h>
24315 #include <asm/debugreg.h>
24316
24317-static void set_idt(void *newidt, __u16 limit)
24318+static void set_idt(struct desc_struct *newidt, __u16 limit)
24319 {
24320 struct desc_ptr curidt;
24321
24322@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24323 }
24324
24325
24326-static void set_gdt(void *newgdt, __u16 limit)
24327+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24328 {
24329 struct desc_ptr curgdt;
24330
24331@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24332 }
24333
24334 control_page = page_address(image->control_code_page);
24335- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24336+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24337
24338 relocate_kernel_ptr = control_page;
24339 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24340diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24341index 22db92b..d546bec 100644
24342--- a/arch/x86/kernel/microcode_core.c
24343+++ b/arch/x86/kernel/microcode_core.c
24344@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24345 return NOTIFY_OK;
24346 }
24347
24348-static struct notifier_block __refdata mc_cpu_notifier = {
24349+static struct notifier_block mc_cpu_notifier = {
24350 .notifier_call = mc_cpu_callback,
24351 };
24352
24353diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24354index 5fb2ceb..3ae90bb 100644
24355--- a/arch/x86/kernel/microcode_intel.c
24356+++ b/arch/x86/kernel/microcode_intel.c
24357@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24358
24359 static int get_ucode_user(void *to, const void *from, size_t n)
24360 {
24361- return copy_from_user(to, from, n);
24362+ return copy_from_user(to, (const void __force_user *)from, n);
24363 }
24364
24365 static enum ucode_state
24366 request_microcode_user(int cpu, const void __user *buf, size_t size)
24367 {
24368- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24369+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24370 }
24371
24372 static void microcode_fini_cpu(int cpu)
24373diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24374index 216a4d7..228255a 100644
24375--- a/arch/x86/kernel/module.c
24376+++ b/arch/x86/kernel/module.c
24377@@ -43,15 +43,60 @@ do { \
24378 } while (0)
24379 #endif
24380
24381-void *module_alloc(unsigned long size)
24382+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24383 {
24384- if (PAGE_ALIGN(size) > MODULES_LEN)
24385+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24386 return NULL;
24387 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24388- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24389+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24390 -1, __builtin_return_address(0));
24391 }
24392
24393+void *module_alloc(unsigned long size)
24394+{
24395+
24396+#ifdef CONFIG_PAX_KERNEXEC
24397+ return __module_alloc(size, PAGE_KERNEL);
24398+#else
24399+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24400+#endif
24401+
24402+}
24403+
24404+#ifdef CONFIG_PAX_KERNEXEC
24405+#ifdef CONFIG_X86_32
24406+void *module_alloc_exec(unsigned long size)
24407+{
24408+ struct vm_struct *area;
24409+
24410+ if (size == 0)
24411+ return NULL;
24412+
24413+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24414+ return area ? area->addr : NULL;
24415+}
24416+EXPORT_SYMBOL(module_alloc_exec);
24417+
24418+void module_free_exec(struct module *mod, void *module_region)
24419+{
24420+ vunmap(module_region);
24421+}
24422+EXPORT_SYMBOL(module_free_exec);
24423+#else
24424+void module_free_exec(struct module *mod, void *module_region)
24425+{
24426+ module_free(mod, module_region);
24427+}
24428+EXPORT_SYMBOL(module_free_exec);
24429+
24430+void *module_alloc_exec(unsigned long size)
24431+{
24432+ return __module_alloc(size, PAGE_KERNEL_RX);
24433+}
24434+EXPORT_SYMBOL(module_alloc_exec);
24435+#endif
24436+#endif
24437+
24438 #ifdef CONFIG_X86_32
24439 int apply_relocate(Elf32_Shdr *sechdrs,
24440 const char *strtab,
24441@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24442 unsigned int i;
24443 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24444 Elf32_Sym *sym;
24445- uint32_t *location;
24446+ uint32_t *plocation, location;
24447
24448 DEBUGP("Applying relocate section %u to %u\n",
24449 relsec, sechdrs[relsec].sh_info);
24450 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24451 /* This is where to make the change */
24452- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24453- + rel[i].r_offset;
24454+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24455+ location = (uint32_t)plocation;
24456+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24457+ plocation = ktla_ktva((void *)plocation);
24458 /* This is the symbol it is referring to. Note that all
24459 undefined symbols have been resolved. */
24460 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24461@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24462 switch (ELF32_R_TYPE(rel[i].r_info)) {
24463 case R_386_32:
24464 /* We add the value into the location given */
24465- *location += sym->st_value;
24466+ pax_open_kernel();
24467+ *plocation += sym->st_value;
24468+ pax_close_kernel();
24469 break;
24470 case R_386_PC32:
24471 /* Add the value, subtract its position */
24472- *location += sym->st_value - (uint32_t)location;
24473+ pax_open_kernel();
24474+ *plocation += sym->st_value - location;
24475+ pax_close_kernel();
24476 break;
24477 default:
24478 pr_err("%s: Unknown relocation: %u\n",
24479@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24480 case R_X86_64_NONE:
24481 break;
24482 case R_X86_64_64:
24483+ pax_open_kernel();
24484 *(u64 *)loc = val;
24485+ pax_close_kernel();
24486 break;
24487 case R_X86_64_32:
24488+ pax_open_kernel();
24489 *(u32 *)loc = val;
24490+ pax_close_kernel();
24491 if (val != *(u32 *)loc)
24492 goto overflow;
24493 break;
24494 case R_X86_64_32S:
24495+ pax_open_kernel();
24496 *(s32 *)loc = val;
24497+ pax_close_kernel();
24498 if ((s64)val != *(s32 *)loc)
24499 goto overflow;
24500 break;
24501 case R_X86_64_PC32:
24502 val -= (u64)loc;
24503+ pax_open_kernel();
24504 *(u32 *)loc = val;
24505+ pax_close_kernel();
24506+
24507 #if 0
24508 if ((s64)val != *(s32 *)loc)
24509 goto overflow;
24510diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24511index ce13049..e2e9c3c 100644
24512--- a/arch/x86/kernel/msr.c
24513+++ b/arch/x86/kernel/msr.c
24514@@ -233,7 +233,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
24515 return notifier_from_errno(err);
24516 }
24517
24518-static struct notifier_block __refdata msr_class_cpu_notifier = {
24519+static struct notifier_block msr_class_cpu_notifier = {
24520 .notifier_call = msr_class_cpu_callback,
24521 };
24522
24523diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24524index 6030805..2d33f21 100644
24525--- a/arch/x86/kernel/nmi.c
24526+++ b/arch/x86/kernel/nmi.c
24527@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24528 return handled;
24529 }
24530
24531-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24532+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24533 {
24534 struct nmi_desc *desc = nmi_to_desc(type);
24535 unsigned long flags;
24536@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24537 * event confuses some handlers (kdump uses this flag)
24538 */
24539 if (action->flags & NMI_FLAG_FIRST)
24540- list_add_rcu(&action->list, &desc->head);
24541+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24542 else
24543- list_add_tail_rcu(&action->list, &desc->head);
24544+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24545
24546 spin_unlock_irqrestore(&desc->lock, flags);
24547 return 0;
24548@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24549 if (!strcmp(n->name, name)) {
24550 WARN(in_nmi(),
24551 "Trying to free NMI (%s) from NMI context!\n", n->name);
24552- list_del_rcu(&n->list);
24553+ pax_list_del_rcu((struct list_head *)&n->list);
24554 break;
24555 }
24556 }
24557@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
24558 dotraplinkage notrace __kprobes void
24559 do_nmi(struct pt_regs *regs, long error_code)
24560 {
24561+
24562+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24563+ if (!user_mode(regs)) {
24564+ unsigned long cs = regs->cs & 0xFFFF;
24565+ unsigned long ip = ktva_ktla(regs->ip);
24566+
24567+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24568+ regs->ip = ip;
24569+ }
24570+#endif
24571+
24572 nmi_nesting_preprocess(regs);
24573
24574 nmi_enter();
24575diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24576index 6d9582e..f746287 100644
24577--- a/arch/x86/kernel/nmi_selftest.c
24578+++ b/arch/x86/kernel/nmi_selftest.c
24579@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24580 {
24581 /* trap all the unknown NMIs we may generate */
24582 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24583- __initdata);
24584+ __initconst);
24585 }
24586
24587 static void __init cleanup_nmi_testsuite(void)
24588@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24589 unsigned long timeout;
24590
24591 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24592- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24593+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24594 nmi_fail = FAILURE;
24595 return;
24596 }
24597diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24598index 676b8c7..870ba04 100644
24599--- a/arch/x86/kernel/paravirt-spinlocks.c
24600+++ b/arch/x86/kernel/paravirt-spinlocks.c
24601@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
24602 arch_spin_lock(lock);
24603 }
24604
24605-struct pv_lock_ops pv_lock_ops = {
24606+struct pv_lock_ops pv_lock_ops __read_only = {
24607 #ifdef CONFIG_SMP
24608 .spin_is_locked = __ticket_spin_is_locked,
24609 .spin_is_contended = __ticket_spin_is_contended,
24610diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24611index cd6de64..27c6af0 100644
24612--- a/arch/x86/kernel/paravirt.c
24613+++ b/arch/x86/kernel/paravirt.c
24614@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24615 {
24616 return x;
24617 }
24618+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24619+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24620+#endif
24621
24622 void __init default_banner(void)
24623 {
24624@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24625 if (opfunc == NULL)
24626 /* If there's no function, patch it with a ud2a (BUG) */
24627 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24628- else if (opfunc == _paravirt_nop)
24629+ else if (opfunc == (void *)_paravirt_nop)
24630 /* If the operation is a nop, then nop the callsite */
24631 ret = paravirt_patch_nop();
24632
24633 /* identity functions just return their single argument */
24634- else if (opfunc == _paravirt_ident_32)
24635+ else if (opfunc == (void *)_paravirt_ident_32)
24636 ret = paravirt_patch_ident_32(insnbuf, len);
24637- else if (opfunc == _paravirt_ident_64)
24638+ else if (opfunc == (void *)_paravirt_ident_64)
24639 ret = paravirt_patch_ident_64(insnbuf, len);
24640+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24641+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24642+ ret = paravirt_patch_ident_64(insnbuf, len);
24643+#endif
24644
24645 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24646 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24647@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24648 if (insn_len > len || start == NULL)
24649 insn_len = len;
24650 else
24651- memcpy(insnbuf, start, insn_len);
24652+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24653
24654 return insn_len;
24655 }
24656@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24657 return this_cpu_read(paravirt_lazy_mode);
24658 }
24659
24660-struct pv_info pv_info = {
24661+struct pv_info pv_info __read_only = {
24662 .name = "bare hardware",
24663 .paravirt_enabled = 0,
24664 .kernel_rpl = 0,
24665@@ -315,16 +322,16 @@ struct pv_info pv_info = {
24666 #endif
24667 };
24668
24669-struct pv_init_ops pv_init_ops = {
24670+struct pv_init_ops pv_init_ops __read_only = {
24671 .patch = native_patch,
24672 };
24673
24674-struct pv_time_ops pv_time_ops = {
24675+struct pv_time_ops pv_time_ops __read_only = {
24676 .sched_clock = native_sched_clock,
24677 .steal_clock = native_steal_clock,
24678 };
24679
24680-struct pv_irq_ops pv_irq_ops = {
24681+struct pv_irq_ops pv_irq_ops __read_only = {
24682 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24683 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24684 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24685@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
24686 #endif
24687 };
24688
24689-struct pv_cpu_ops pv_cpu_ops = {
24690+struct pv_cpu_ops pv_cpu_ops __read_only = {
24691 .cpuid = native_cpuid,
24692 .get_debugreg = native_get_debugreg,
24693 .set_debugreg = native_set_debugreg,
24694@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
24695 .end_context_switch = paravirt_nop,
24696 };
24697
24698-struct pv_apic_ops pv_apic_ops = {
24699+struct pv_apic_ops pv_apic_ops __read_only= {
24700 #ifdef CONFIG_X86_LOCAL_APIC
24701 .startup_ipi_hook = paravirt_nop,
24702 #endif
24703 };
24704
24705-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24706+#ifdef CONFIG_X86_32
24707+#ifdef CONFIG_X86_PAE
24708+/* 64-bit pagetable entries */
24709+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24710+#else
24711 /* 32-bit pagetable entries */
24712 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24713+#endif
24714 #else
24715 /* 64-bit pagetable entries */
24716 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24717 #endif
24718
24719-struct pv_mmu_ops pv_mmu_ops = {
24720+struct pv_mmu_ops pv_mmu_ops __read_only = {
24721
24722 .read_cr2 = native_read_cr2,
24723 .write_cr2 = native_write_cr2,
24724@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24725 .make_pud = PTE_IDENT,
24726
24727 .set_pgd = native_set_pgd,
24728+ .set_pgd_batched = native_set_pgd_batched,
24729 #endif
24730 #endif /* PAGETABLE_LEVELS >= 3 */
24731
24732@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24733 },
24734
24735 .set_fixmap = native_set_fixmap,
24736+
24737+#ifdef CONFIG_PAX_KERNEXEC
24738+ .pax_open_kernel = native_pax_open_kernel,
24739+ .pax_close_kernel = native_pax_close_kernel,
24740+#endif
24741+
24742 };
24743
24744 EXPORT_SYMBOL_GPL(pv_time_ops);
24745diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24746index 299d493..2ccb0ee 100644
24747--- a/arch/x86/kernel/pci-calgary_64.c
24748+++ b/arch/x86/kernel/pci-calgary_64.c
24749@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24750 tce_space = be64_to_cpu(readq(target));
24751 tce_space = tce_space & TAR_SW_BITS;
24752
24753- tce_space = tce_space & (~specified_table_size);
24754+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24755 info->tce_space = (u64 *)__va(tce_space);
24756 }
24757 }
24758diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24759index 35ccf75..7a15747 100644
24760--- a/arch/x86/kernel/pci-iommu_table.c
24761+++ b/arch/x86/kernel/pci-iommu_table.c
24762@@ -2,7 +2,7 @@
24763 #include <asm/iommu_table.h>
24764 #include <linux/string.h>
24765 #include <linux/kallsyms.h>
24766-
24767+#include <linux/sched.h>
24768
24769 #define DEBUG 1
24770
24771diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24772index 6c483ba..d10ce2f 100644
24773--- a/arch/x86/kernel/pci-swiotlb.c
24774+++ b/arch/x86/kernel/pci-swiotlb.c
24775@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24776 void *vaddr, dma_addr_t dma_addr,
24777 struct dma_attrs *attrs)
24778 {
24779- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24780+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24781 }
24782
24783 static struct dma_map_ops swiotlb_dma_ops = {
24784diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24785index 81a5f5e..20f8b58 100644
24786--- a/arch/x86/kernel/process.c
24787+++ b/arch/x86/kernel/process.c
24788@@ -36,7 +36,8 @@
24789 * section. Since TSS's are completely CPU-local, we want them
24790 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24791 */
24792-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24793+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24794+EXPORT_SYMBOL(init_tss);
24795
24796 #ifdef CONFIG_X86_64
24797 static DEFINE_PER_CPU(unsigned char, is_idle);
24798@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24799 task_xstate_cachep =
24800 kmem_cache_create("task_xstate", xstate_size,
24801 __alignof__(union thread_xstate),
24802- SLAB_PANIC | SLAB_NOTRACK, NULL);
24803+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24804 }
24805
24806 /*
24807@@ -105,7 +106,7 @@ void exit_thread(void)
24808 unsigned long *bp = t->io_bitmap_ptr;
24809
24810 if (bp) {
24811- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24812+ struct tss_struct *tss = init_tss + get_cpu();
24813
24814 t->io_bitmap_ptr = NULL;
24815 clear_thread_flag(TIF_IO_BITMAP);
24816@@ -125,6 +126,9 @@ void flush_thread(void)
24817 {
24818 struct task_struct *tsk = current;
24819
24820+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24821+ loadsegment(gs, 0);
24822+#endif
24823 flush_ptrace_hw_breakpoint(tsk);
24824 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24825 drop_init_fpu(tsk);
24826@@ -271,7 +275,7 @@ static void __exit_idle(void)
24827 void exit_idle(void)
24828 {
24829 /* idle loop has pid 0 */
24830- if (current->pid)
24831+ if (task_pid_nr(current))
24832 return;
24833 __exit_idle();
24834 }
24835@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24836 return ret;
24837 }
24838 #endif
24839-void stop_this_cpu(void *dummy)
24840+__noreturn void stop_this_cpu(void *dummy)
24841 {
24842 local_irq_disable();
24843 /*
24844@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24845 }
24846 early_param("idle", idle_setup);
24847
24848-unsigned long arch_align_stack(unsigned long sp)
24849+#ifdef CONFIG_PAX_RANDKSTACK
24850+void pax_randomize_kstack(struct pt_regs *regs)
24851 {
24852- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24853- sp -= get_random_int() % 8192;
24854- return sp & ~0xf;
24855-}
24856+ struct thread_struct *thread = &current->thread;
24857+ unsigned long time;
24858
24859-unsigned long arch_randomize_brk(struct mm_struct *mm)
24860-{
24861- unsigned long range_end = mm->brk + 0x02000000;
24862- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24863-}
24864+ if (!randomize_va_space)
24865+ return;
24866+
24867+ if (v8086_mode(regs))
24868+ return;
24869
24870+ rdtscl(time);
24871+
24872+ /* P4 seems to return a 0 LSB, ignore it */
24873+#ifdef CONFIG_MPENTIUM4
24874+ time &= 0x3EUL;
24875+ time <<= 2;
24876+#elif defined(CONFIG_X86_64)
24877+ time &= 0xFUL;
24878+ time <<= 4;
24879+#else
24880+ time &= 0x1FUL;
24881+ time <<= 3;
24882+#endif
24883+
24884+ thread->sp0 ^= time;
24885+ load_sp0(init_tss + smp_processor_id(), thread);
24886+
24887+#ifdef CONFIG_X86_64
24888+ this_cpu_write(kernel_stack, thread->sp0);
24889+#endif
24890+}
24891+#endif
24892diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24893index 7305f7d..22f73d6 100644
24894--- a/arch/x86/kernel/process_32.c
24895+++ b/arch/x86/kernel/process_32.c
24896@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24897 unsigned long thread_saved_pc(struct task_struct *tsk)
24898 {
24899 return ((unsigned long *)tsk->thread.sp)[3];
24900+//XXX return tsk->thread.eip;
24901 }
24902
24903 void __show_regs(struct pt_regs *regs, int all)
24904@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24905 unsigned long sp;
24906 unsigned short ss, gs;
24907
24908- if (user_mode_vm(regs)) {
24909+ if (user_mode(regs)) {
24910 sp = regs->sp;
24911 ss = regs->ss & 0xffff;
24912- gs = get_user_gs(regs);
24913 } else {
24914 sp = kernel_stack_pointer(regs);
24915 savesegment(ss, ss);
24916- savesegment(gs, gs);
24917 }
24918+ gs = get_user_gs(regs);
24919
24920 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24921 (u16)regs->cs, regs->ip, regs->flags,
24922- smp_processor_id());
24923+ raw_smp_processor_id());
24924 print_symbol("EIP is at %s\n", regs->ip);
24925
24926 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24927@@ -128,20 +128,21 @@ void release_thread(struct task_struct *dead_task)
24928 int copy_thread(unsigned long clone_flags, unsigned long sp,
24929 unsigned long arg, struct task_struct *p)
24930 {
24931- struct pt_regs *childregs = task_pt_regs(p);
24932+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24933 struct task_struct *tsk;
24934 int err;
24935
24936 p->thread.sp = (unsigned long) childregs;
24937 p->thread.sp0 = (unsigned long) (childregs+1);
24938+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24939
24940 if (unlikely(p->flags & PF_KTHREAD)) {
24941 /* kernel thread */
24942 memset(childregs, 0, sizeof(struct pt_regs));
24943 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24944- task_user_gs(p) = __KERNEL_STACK_CANARY;
24945- childregs->ds = __USER_DS;
24946- childregs->es = __USER_DS;
24947+ savesegment(gs, childregs->gs);
24948+ childregs->ds = __KERNEL_DS;
24949+ childregs->es = __KERNEL_DS;
24950 childregs->fs = __KERNEL_PERCPU;
24951 childregs->bx = sp; /* function */
24952 childregs->bp = arg;
24953@@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24954 struct thread_struct *prev = &prev_p->thread,
24955 *next = &next_p->thread;
24956 int cpu = smp_processor_id();
24957- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24958+ struct tss_struct *tss = init_tss + cpu;
24959 fpu_switch_t fpu;
24960
24961 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24962@@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24963 */
24964 lazy_save_gs(prev->gs);
24965
24966+#ifdef CONFIG_PAX_MEMORY_UDEREF
24967+ __set_fs(task_thread_info(next_p)->addr_limit);
24968+#endif
24969+
24970 /*
24971 * Load the per-thread Thread-Local Storage descriptor.
24972 */
24973@@ -302,6 +307,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24974 */
24975 arch_end_context_switch(next_p);
24976
24977+ this_cpu_write(current_task, next_p);
24978+ this_cpu_write(current_tinfo, &next_p->tinfo);
24979+
24980 /*
24981 * Restore %gs if needed (which is common)
24982 */
24983@@ -310,8 +318,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24984
24985 switch_fpu_finish(next_p, fpu);
24986
24987- this_cpu_write(current_task, next_p);
24988-
24989 return prev_p;
24990 }
24991
24992@@ -341,4 +347,3 @@ unsigned long get_wchan(struct task_struct *p)
24993 } while (count++ < 16);
24994 return 0;
24995 }
24996-
24997diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24998index 355ae06..560fbbe 100644
24999--- a/arch/x86/kernel/process_64.c
25000+++ b/arch/x86/kernel/process_64.c
25001@@ -151,10 +151,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25002 struct pt_regs *childregs;
25003 struct task_struct *me = current;
25004
25005- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
25006+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
25007 childregs = task_pt_regs(p);
25008 p->thread.sp = (unsigned long) childregs;
25009 p->thread.usersp = me->thread.usersp;
25010+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25011 set_tsk_thread_flag(p, TIF_FORK);
25012 p->fpu_counter = 0;
25013 p->thread.io_bitmap_ptr = NULL;
25014@@ -165,6 +166,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25015 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
25016 savesegment(es, p->thread.es);
25017 savesegment(ds, p->thread.ds);
25018+ savesegment(ss, p->thread.ss);
25019+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
25020 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
25021
25022 if (unlikely(p->flags & PF_KTHREAD)) {
25023@@ -273,7 +276,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25024 struct thread_struct *prev = &prev_p->thread;
25025 struct thread_struct *next = &next_p->thread;
25026 int cpu = smp_processor_id();
25027- struct tss_struct *tss = &per_cpu(init_tss, cpu);
25028+ struct tss_struct *tss = init_tss + cpu;
25029 unsigned fsindex, gsindex;
25030 fpu_switch_t fpu;
25031
25032@@ -296,6 +299,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25033 if (unlikely(next->ds | prev->ds))
25034 loadsegment(ds, next->ds);
25035
25036+ savesegment(ss, prev->ss);
25037+ if (unlikely(next->ss != prev->ss))
25038+ loadsegment(ss, next->ss);
25039
25040 /* We must save %fs and %gs before load_TLS() because
25041 * %fs and %gs may be cleared by load_TLS().
25042@@ -355,10 +361,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25043 prev->usersp = this_cpu_read(old_rsp);
25044 this_cpu_write(old_rsp, next->usersp);
25045 this_cpu_write(current_task, next_p);
25046+ this_cpu_write(current_tinfo, &next_p->tinfo);
25047
25048- this_cpu_write(kernel_stack,
25049- (unsigned long)task_stack_page(next_p) +
25050- THREAD_SIZE - KERNEL_STACK_OFFSET);
25051+ this_cpu_write(kernel_stack, next->sp0);
25052
25053 /*
25054 * Now maybe reload the debug registers and handle I/O bitmaps
25055@@ -427,12 +432,11 @@ unsigned long get_wchan(struct task_struct *p)
25056 if (!p || p == current || p->state == TASK_RUNNING)
25057 return 0;
25058 stack = (unsigned long)task_stack_page(p);
25059- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
25060+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
25061 return 0;
25062 fp = *(u64 *)(p->thread.sp);
25063 do {
25064- if (fp < (unsigned long)stack ||
25065- fp >= (unsigned long)stack+THREAD_SIZE)
25066+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
25067 return 0;
25068 ip = *(u64 *)(fp+8);
25069 if (!in_sched_functions(ip))
25070diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
25071index 29a8120..a50b5ee 100644
25072--- a/arch/x86/kernel/ptrace.c
25073+++ b/arch/x86/kernel/ptrace.c
25074@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
25075 {
25076 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
25077 unsigned long sp = (unsigned long)&regs->sp;
25078- struct thread_info *tinfo;
25079
25080- if (context == (sp & ~(THREAD_SIZE - 1)))
25081+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
25082 return sp;
25083
25084- tinfo = (struct thread_info *)context;
25085- if (tinfo->previous_esp)
25086- return tinfo->previous_esp;
25087+ sp = *(unsigned long *)context;
25088+ if (sp)
25089+ return sp;
25090
25091 return (unsigned long)regs;
25092 }
25093@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
25094 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
25095 {
25096 int i;
25097- int dr7 = 0;
25098+ unsigned long dr7 = 0;
25099 struct arch_hw_breakpoint *info;
25100
25101 for (i = 0; i < HBP_NUM; i++) {
25102@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
25103 unsigned long addr, unsigned long data)
25104 {
25105 int ret;
25106- unsigned long __user *datap = (unsigned long __user *)data;
25107+ unsigned long __user *datap = (__force unsigned long __user *)data;
25108
25109 switch (request) {
25110 /* read the word at location addr in the USER area. */
25111@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
25112 if ((int) addr < 0)
25113 return -EIO;
25114 ret = do_get_thread_area(child, addr,
25115- (struct user_desc __user *)data);
25116+ (__force struct user_desc __user *) data);
25117 break;
25118
25119 case PTRACE_SET_THREAD_AREA:
25120 if ((int) addr < 0)
25121 return -EIO;
25122 ret = do_set_thread_area(child, addr,
25123- (struct user_desc __user *)data, 0);
25124+ (__force struct user_desc __user *) data, 0);
25125 break;
25126 #endif
25127
25128@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
25129
25130 #ifdef CONFIG_X86_64
25131
25132-static struct user_regset x86_64_regsets[] __read_mostly = {
25133+static user_regset_no_const x86_64_regsets[] __read_only = {
25134 [REGSET_GENERAL] = {
25135 .core_note_type = NT_PRSTATUS,
25136 .n = sizeof(struct user_regs_struct) / sizeof(long),
25137@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
25138 #endif /* CONFIG_X86_64 */
25139
25140 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
25141-static struct user_regset x86_32_regsets[] __read_mostly = {
25142+static user_regset_no_const x86_32_regsets[] __read_only = {
25143 [REGSET_GENERAL] = {
25144 .core_note_type = NT_PRSTATUS,
25145 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
25146@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
25147 */
25148 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
25149
25150-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25151+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25152 {
25153 #ifdef CONFIG_X86_64
25154 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
25155@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
25156 memset(info, 0, sizeof(*info));
25157 info->si_signo = SIGTRAP;
25158 info->si_code = si_code;
25159- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
25160+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
25161 }
25162
25163 void user_single_step_siginfo(struct task_struct *tsk,
25164@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
25165 # define IS_IA32 0
25166 #endif
25167
25168+#ifdef CONFIG_GRKERNSEC_SETXID
25169+extern void gr_delayed_cred_worker(void);
25170+#endif
25171+
25172 /*
25173 * We must return the syscall number to actually look up in the table.
25174 * This can be -1L to skip running any syscall at all.
25175@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
25176
25177 user_exit();
25178
25179+#ifdef CONFIG_GRKERNSEC_SETXID
25180+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25181+ gr_delayed_cred_worker();
25182+#endif
25183+
25184 /*
25185 * If we stepped into a sysenter/syscall insn, it trapped in
25186 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
25187@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
25188 */
25189 user_exit();
25190
25191+#ifdef CONFIG_GRKERNSEC_SETXID
25192+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25193+ gr_delayed_cred_worker();
25194+#endif
25195+
25196 audit_syscall_exit(regs);
25197
25198 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
25199diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
25200index 2cb9470..ff1fd80 100644
25201--- a/arch/x86/kernel/pvclock.c
25202+++ b/arch/x86/kernel/pvclock.c
25203@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
25204 return pv_tsc_khz;
25205 }
25206
25207-static atomic64_t last_value = ATOMIC64_INIT(0);
25208+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
25209
25210 void pvclock_resume(void)
25211 {
25212- atomic64_set(&last_value, 0);
25213+ atomic64_set_unchecked(&last_value, 0);
25214 }
25215
25216 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
25217@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
25218 * updating at the same time, and one of them could be slightly behind,
25219 * making the assumption that last_value always go forward fail to hold.
25220 */
25221- last = atomic64_read(&last_value);
25222+ last = atomic64_read_unchecked(&last_value);
25223 do {
25224 if (ret < last)
25225 return last;
25226- last = atomic64_cmpxchg(&last_value, last, ret);
25227+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
25228 } while (unlikely(last != ret));
25229
25230 return ret;
25231diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
25232index 76fa1e9..abf09ea 100644
25233--- a/arch/x86/kernel/reboot.c
25234+++ b/arch/x86/kernel/reboot.c
25235@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
25236 EXPORT_SYMBOL(pm_power_off);
25237
25238 static const struct desc_ptr no_idt = {};
25239-static int reboot_mode;
25240+static unsigned short reboot_mode;
25241 enum reboot_type reboot_type = BOOT_ACPI;
25242 int reboot_force;
25243
25244@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
25245
25246 void __noreturn machine_real_restart(unsigned int type)
25247 {
25248+
25249+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
25250+ struct desc_struct *gdt;
25251+#endif
25252+
25253 local_irq_disable();
25254
25255 /*
25256@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
25257
25258 /* Jump to the identity-mapped low memory code */
25259 #ifdef CONFIG_X86_32
25260- asm volatile("jmpl *%0" : :
25261+
25262+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
25263+ gdt = get_cpu_gdt_table(smp_processor_id());
25264+ pax_open_kernel();
25265+#ifdef CONFIG_PAX_MEMORY_UDEREF
25266+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
25267+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
25268+ loadsegment(ds, __KERNEL_DS);
25269+ loadsegment(es, __KERNEL_DS);
25270+ loadsegment(ss, __KERNEL_DS);
25271+#endif
25272+#ifdef CONFIG_PAX_KERNEXEC
25273+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
25274+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
25275+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
25276+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
25277+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
25278+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
25279+#endif
25280+ pax_close_kernel();
25281+#endif
25282+
25283+ asm volatile("ljmpl *%0" : :
25284 "rm" (real_mode_header->machine_real_restart_asm),
25285 "a" (type));
25286 #else
25287@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
25288 * try to force a triple fault and then cycle between hitting the keyboard
25289 * controller and doing that
25290 */
25291-static void native_machine_emergency_restart(void)
25292+static void __noreturn native_machine_emergency_restart(void)
25293 {
25294 int i;
25295 int attempt = 0;
25296@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
25297 #endif
25298 }
25299
25300-static void __machine_emergency_restart(int emergency)
25301+static void __noreturn __machine_emergency_restart(int emergency)
25302 {
25303 reboot_emergency = emergency;
25304 machine_ops.emergency_restart();
25305 }
25306
25307-static void native_machine_restart(char *__unused)
25308+static void __noreturn native_machine_restart(char *__unused)
25309 {
25310 pr_notice("machine restart\n");
25311
25312@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
25313 __machine_emergency_restart(0);
25314 }
25315
25316-static void native_machine_halt(void)
25317+static void __noreturn native_machine_halt(void)
25318 {
25319 /* Stop other cpus and apics */
25320 machine_shutdown();
25321@@ -679,7 +706,7 @@ static void native_machine_halt(void)
25322 stop_this_cpu(NULL);
25323 }
25324
25325-static void native_machine_power_off(void)
25326+static void __noreturn native_machine_power_off(void)
25327 {
25328 if (pm_power_off) {
25329 if (!reboot_force)
25330@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
25331 }
25332 /* A fallback in case there is no PM info available */
25333 tboot_shutdown(TB_SHUTDOWN_HALT);
25334+ unreachable();
25335 }
25336
25337-struct machine_ops machine_ops = {
25338+struct machine_ops machine_ops __read_only = {
25339 .power_off = native_machine_power_off,
25340 .shutdown = native_machine_shutdown,
25341 .emergency_restart = native_machine_emergency_restart,
25342diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25343index c8e41e9..64049ef 100644
25344--- a/arch/x86/kernel/reboot_fixups_32.c
25345+++ b/arch/x86/kernel/reboot_fixups_32.c
25346@@ -57,7 +57,7 @@ struct device_fixup {
25347 unsigned int vendor;
25348 unsigned int device;
25349 void (*reboot_fixup)(struct pci_dev *);
25350-};
25351+} __do_const;
25352
25353 /*
25354 * PCI ids solely used for fixups_table go here
25355diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25356index f2bb9c9..bed145d7 100644
25357--- a/arch/x86/kernel/relocate_kernel_64.S
25358+++ b/arch/x86/kernel/relocate_kernel_64.S
25359@@ -11,6 +11,7 @@
25360 #include <asm/kexec.h>
25361 #include <asm/processor-flags.h>
25362 #include <asm/pgtable_types.h>
25363+#include <asm/alternative-asm.h>
25364
25365 /*
25366 * Must be relocatable PIC code callable as a C function
25367@@ -167,6 +168,7 @@ identity_mapped:
25368 xorq %r14, %r14
25369 xorq %r15, %r15
25370
25371+ pax_force_retaddr 0, 1
25372 ret
25373
25374 1:
25375diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25376index 56f7fcf..2cfe4f1 100644
25377--- a/arch/x86/kernel/setup.c
25378+++ b/arch/x86/kernel/setup.c
25379@@ -110,6 +110,7 @@
25380 #include <asm/mce.h>
25381 #include <asm/alternative.h>
25382 #include <asm/prom.h>
25383+#include <asm/boot.h>
25384
25385 /*
25386 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25387@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25388 #endif
25389
25390
25391-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25392-unsigned long mmu_cr4_features;
25393+#ifdef CONFIG_X86_64
25394+unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25395+#elif defined(CONFIG_X86_PAE)
25396+unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25397 #else
25398-unsigned long mmu_cr4_features = X86_CR4_PAE;
25399+unsigned long mmu_cr4_features __read_only;
25400 #endif
25401
25402+void set_in_cr4(unsigned long mask)
25403+{
25404+ unsigned long cr4 = read_cr4();
25405+
25406+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25407+ return;
25408+
25409+ pax_open_kernel();
25410+ mmu_cr4_features |= mask;
25411+ pax_close_kernel();
25412+
25413+ if (trampoline_cr4_features)
25414+ *trampoline_cr4_features = mmu_cr4_features;
25415+ cr4 |= mask;
25416+ write_cr4(cr4);
25417+}
25418+EXPORT_SYMBOL(set_in_cr4);
25419+
25420+void clear_in_cr4(unsigned long mask)
25421+{
25422+ unsigned long cr4 = read_cr4();
25423+
25424+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25425+ return;
25426+
25427+ pax_open_kernel();
25428+ mmu_cr4_features &= ~mask;
25429+ pax_close_kernel();
25430+
25431+ if (trampoline_cr4_features)
25432+ *trampoline_cr4_features = mmu_cr4_features;
25433+ cr4 &= ~mask;
25434+ write_cr4(cr4);
25435+}
25436+EXPORT_SYMBOL(clear_in_cr4);
25437+
25438 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25439 int bootloader_type, bootloader_version;
25440
25441@@ -444,7 +483,7 @@ static void __init parse_setup_data(void)
25442
25443 switch (data->type) {
25444 case SETUP_E820_EXT:
25445- parse_e820_ext(data);
25446+ parse_e820_ext((struct setup_data __force_kernel *)data);
25447 break;
25448 case SETUP_DTB:
25449 add_dtb(pa_data);
25450@@ -771,7 +810,7 @@ static void __init trim_bios_range(void)
25451 * area (640->1Mb) as ram even though it is not.
25452 * take them out.
25453 */
25454- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25455+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25456
25457 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25458 }
25459@@ -779,7 +818,7 @@ static void __init trim_bios_range(void)
25460 /* called before trim_bios_range() to spare extra sanitize */
25461 static void __init e820_add_kernel_range(void)
25462 {
25463- u64 start = __pa_symbol(_text);
25464+ u64 start = __pa_symbol(ktla_ktva(_text));
25465 u64 size = __pa_symbol(_end) - start;
25466
25467 /*
25468@@ -841,8 +880,12 @@ static void __init trim_low_memory_range(void)
25469
25470 void __init setup_arch(char **cmdline_p)
25471 {
25472+#ifdef CONFIG_X86_32
25473+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25474+#else
25475 memblock_reserve(__pa_symbol(_text),
25476 (unsigned long)__bss_stop - (unsigned long)_text);
25477+#endif
25478
25479 early_reserve_initrd();
25480
25481@@ -934,14 +977,14 @@ void __init setup_arch(char **cmdline_p)
25482
25483 if (!boot_params.hdr.root_flags)
25484 root_mountflags &= ~MS_RDONLY;
25485- init_mm.start_code = (unsigned long) _text;
25486- init_mm.end_code = (unsigned long) _etext;
25487+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25488+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25489 init_mm.end_data = (unsigned long) _edata;
25490 init_mm.brk = _brk_end;
25491
25492- code_resource.start = __pa_symbol(_text);
25493- code_resource.end = __pa_symbol(_etext)-1;
25494- data_resource.start = __pa_symbol(_etext);
25495+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25496+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25497+ data_resource.start = __pa_symbol(_sdata);
25498 data_resource.end = __pa_symbol(_edata)-1;
25499 bss_resource.start = __pa_symbol(__bss_start);
25500 bss_resource.end = __pa_symbol(__bss_stop)-1;
25501diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25502index 5cdff03..80fa283 100644
25503--- a/arch/x86/kernel/setup_percpu.c
25504+++ b/arch/x86/kernel/setup_percpu.c
25505@@ -21,19 +21,17 @@
25506 #include <asm/cpu.h>
25507 #include <asm/stackprotector.h>
25508
25509-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25510+#ifdef CONFIG_SMP
25511+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25512 EXPORT_PER_CPU_SYMBOL(cpu_number);
25513+#endif
25514
25515-#ifdef CONFIG_X86_64
25516 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25517-#else
25518-#define BOOT_PERCPU_OFFSET 0
25519-#endif
25520
25521 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25522 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25523
25524-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25525+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25526 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25527 };
25528 EXPORT_SYMBOL(__per_cpu_offset);
25529@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25530 {
25531 #ifdef CONFIG_NEED_MULTIPLE_NODES
25532 pg_data_t *last = NULL;
25533- unsigned int cpu;
25534+ int cpu;
25535
25536 for_each_possible_cpu(cpu) {
25537 int node = early_cpu_to_node(cpu);
25538@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25539 {
25540 #ifdef CONFIG_X86_32
25541 struct desc_struct gdt;
25542+ unsigned long base = per_cpu_offset(cpu);
25543
25544- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25545- 0x2 | DESCTYPE_S, 0x8);
25546- gdt.s = 1;
25547+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25548+ 0x83 | DESCTYPE_S, 0xC);
25549 write_gdt_entry(get_cpu_gdt_table(cpu),
25550 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25551 #endif
25552@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25553 /* alrighty, percpu areas up and running */
25554 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25555 for_each_possible_cpu(cpu) {
25556+#ifdef CONFIG_CC_STACKPROTECTOR
25557+#ifdef CONFIG_X86_32
25558+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25559+#endif
25560+#endif
25561 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25562 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25563 per_cpu(cpu_number, cpu) = cpu;
25564@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25565 */
25566 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25567 #endif
25568+#ifdef CONFIG_CC_STACKPROTECTOR
25569+#ifdef CONFIG_X86_32
25570+ if (!cpu)
25571+ per_cpu(stack_canary.canary, cpu) = canary;
25572+#endif
25573+#endif
25574 /*
25575 * Up to this point, the boot CPU has been using .init.data
25576 * area. Reload any changed state for the boot CPU.
25577diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25578index 6956299..18126ec4 100644
25579--- a/arch/x86/kernel/signal.c
25580+++ b/arch/x86/kernel/signal.c
25581@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
25582 * Align the stack pointer according to the i386 ABI,
25583 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25584 */
25585- sp = ((sp + 4) & -16ul) - 4;
25586+ sp = ((sp - 12) & -16ul) - 4;
25587 #else /* !CONFIG_X86_32 */
25588 sp = round_down(sp, 16) - 8;
25589 #endif
25590@@ -304,9 +304,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25591 }
25592
25593 if (current->mm->context.vdso)
25594- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25595+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25596 else
25597- restorer = &frame->retcode;
25598+ restorer = (void __user *)&frame->retcode;
25599 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25600 restorer = ksig->ka.sa.sa_restorer;
25601
25602@@ -320,7 +320,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25603 * reasons and because gdb uses it as a signature to notice
25604 * signal handler stack frames.
25605 */
25606- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25607+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25608
25609 if (err)
25610 return -EFAULT;
25611@@ -364,10 +364,13 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25612 else
25613 put_user_ex(0, &frame->uc.uc_flags);
25614 put_user_ex(0, &frame->uc.uc_link);
25615- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
25616+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25617
25618 /* Set up to return from userspace. */
25619- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25620+ if (current->mm->context.vdso)
25621+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25622+ else
25623+ restorer = (void __user *)&frame->retcode;
25624 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25625 restorer = ksig->ka.sa.sa_restorer;
25626 put_user_ex(restorer, &frame->pretcode);
25627@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25628 * reasons and because gdb uses it as a signature to notice
25629 * signal handler stack frames.
25630 */
25631- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25632+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25633 } put_user_catch(err);
25634
25635 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25636@@ -429,7 +432,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25637 else
25638 put_user_ex(0, &frame->uc.uc_flags);
25639 put_user_ex(0, &frame->uc.uc_link);
25640- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
25641+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25642
25643 /* Set up to return from userspace. If provided, use a stub
25644 already in userspace. */
25645@@ -615,7 +618,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25646 {
25647 int usig = signr_convert(ksig->sig);
25648 sigset_t *set = sigmask_to_save();
25649- compat_sigset_t *cset = (compat_sigset_t *) set;
25650+ sigset_t sigcopy;
25651+ compat_sigset_t *cset;
25652+
25653+ sigcopy = *set;
25654+
25655+ cset = (compat_sigset_t *) &sigcopy;
25656
25657 /* Set up the stack frame */
25658 if (is_ia32_frame()) {
25659@@ -626,7 +634,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25660 } else if (is_x32_frame()) {
25661 return x32_setup_rt_frame(ksig, cset, regs);
25662 } else {
25663- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25664+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25665 }
25666 }
25667
25668diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25669index 48d2b7d..90d328a 100644
25670--- a/arch/x86/kernel/smp.c
25671+++ b/arch/x86/kernel/smp.c
25672@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
25673
25674 __setup("nonmi_ipi", nonmi_ipi_setup);
25675
25676-struct smp_ops smp_ops = {
25677+struct smp_ops smp_ops __read_only = {
25678 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25679 .smp_prepare_cpus = native_smp_prepare_cpus,
25680 .smp_cpus_done = native_smp_cpus_done,
25681diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25682index bfd348e..914f323 100644
25683--- a/arch/x86/kernel/smpboot.c
25684+++ b/arch/x86/kernel/smpboot.c
25685@@ -251,14 +251,18 @@ notrace static void __cpuinit start_secondary(void *unused)
25686
25687 enable_start_cpu0 = 0;
25688
25689-#ifdef CONFIG_X86_32
25690- /* switch away from the initial page table */
25691- load_cr3(swapper_pg_dir);
25692- __flush_tlb_all();
25693-#endif
25694-
25695 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25696 barrier();
25697+
25698+ /* switch away from the initial page table */
25699+#ifdef CONFIG_PAX_PER_CPU_PGD
25700+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25701+ __flush_tlb_all();
25702+#elif defined(CONFIG_X86_32)
25703+ load_cr3(swapper_pg_dir);
25704+ __flush_tlb_all();
25705+#endif
25706+
25707 /*
25708 * Check TSC synchronization with the BP:
25709 */
25710@@ -748,6 +752,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25711 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25712 (THREAD_SIZE + task_stack_page(idle))) - 1);
25713 per_cpu(current_task, cpu) = idle;
25714+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25715
25716 #ifdef CONFIG_X86_32
25717 /* Stack for startup_32 can be just as for start_secondary onwards */
25718@@ -755,11 +760,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25719 #else
25720 clear_tsk_thread_flag(idle, TIF_FORK);
25721 initial_gs = per_cpu_offset(cpu);
25722- per_cpu(kernel_stack, cpu) =
25723- (unsigned long)task_stack_page(idle) -
25724- KERNEL_STACK_OFFSET + THREAD_SIZE;
25725+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25726 #endif
25727+
25728+ pax_open_kernel();
25729 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25730+ pax_close_kernel();
25731+
25732 initial_code = (unsigned long)start_secondary;
25733 stack_start = idle->thread.sp;
25734
25735@@ -908,6 +915,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25736 /* the FPU context is blank, nobody can own it */
25737 __cpu_disable_lazy_restore(cpu);
25738
25739+#ifdef CONFIG_PAX_PER_CPU_PGD
25740+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25741+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25742+ KERNEL_PGD_PTRS);
25743+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25744+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25745+ KERNEL_PGD_PTRS);
25746+#endif
25747+
25748 err = do_boot_cpu(apicid, cpu, tidle);
25749 if (err) {
25750 pr_debug("do_boot_cpu failed %d\n", err);
25751diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25752index 9b4d51d..5d28b58 100644
25753--- a/arch/x86/kernel/step.c
25754+++ b/arch/x86/kernel/step.c
25755@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25756 struct desc_struct *desc;
25757 unsigned long base;
25758
25759- seg &= ~7UL;
25760+ seg >>= 3;
25761
25762 mutex_lock(&child->mm->context.lock);
25763- if (unlikely((seg >> 3) >= child->mm->context.size))
25764+ if (unlikely(seg >= child->mm->context.size))
25765 addr = -1L; /* bogus selector, access would fault */
25766 else {
25767 desc = child->mm->context.ldt + seg;
25768@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25769 addr += base;
25770 }
25771 mutex_unlock(&child->mm->context.lock);
25772- }
25773+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25774+ addr = ktla_ktva(addr);
25775
25776 return addr;
25777 }
25778@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25779 unsigned char opcode[15];
25780 unsigned long addr = convert_ip_to_linear(child, regs);
25781
25782+ if (addr == -EINVAL)
25783+ return 0;
25784+
25785 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25786 for (i = 0; i < copied; i++) {
25787 switch (opcode[i]) {
25788diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25789new file mode 100644
25790index 0000000..5877189
25791--- /dev/null
25792+++ b/arch/x86/kernel/sys_i386_32.c
25793@@ -0,0 +1,189 @@
25794+/*
25795+ * This file contains various random system calls that
25796+ * have a non-standard calling sequence on the Linux/i386
25797+ * platform.
25798+ */
25799+
25800+#include <linux/errno.h>
25801+#include <linux/sched.h>
25802+#include <linux/mm.h>
25803+#include <linux/fs.h>
25804+#include <linux/smp.h>
25805+#include <linux/sem.h>
25806+#include <linux/msg.h>
25807+#include <linux/shm.h>
25808+#include <linux/stat.h>
25809+#include <linux/syscalls.h>
25810+#include <linux/mman.h>
25811+#include <linux/file.h>
25812+#include <linux/utsname.h>
25813+#include <linux/ipc.h>
25814+#include <linux/elf.h>
25815+
25816+#include <linux/uaccess.h>
25817+#include <linux/unistd.h>
25818+
25819+#include <asm/syscalls.h>
25820+
25821+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25822+{
25823+ unsigned long pax_task_size = TASK_SIZE;
25824+
25825+#ifdef CONFIG_PAX_SEGMEXEC
25826+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25827+ pax_task_size = SEGMEXEC_TASK_SIZE;
25828+#endif
25829+
25830+ if (flags & MAP_FIXED)
25831+ if (len > pax_task_size || addr > pax_task_size - len)
25832+ return -EINVAL;
25833+
25834+ return 0;
25835+}
25836+
25837+/*
25838+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25839+ */
25840+static unsigned long get_align_mask(void)
25841+{
25842+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25843+ return 0;
25844+
25845+ if (!(current->flags & PF_RANDOMIZE))
25846+ return 0;
25847+
25848+ return va_align.mask;
25849+}
25850+
25851+unsigned long
25852+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25853+ unsigned long len, unsigned long pgoff, unsigned long flags)
25854+{
25855+ struct mm_struct *mm = current->mm;
25856+ struct vm_area_struct *vma;
25857+ unsigned long pax_task_size = TASK_SIZE;
25858+ struct vm_unmapped_area_info info;
25859+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25860+
25861+#ifdef CONFIG_PAX_SEGMEXEC
25862+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25863+ pax_task_size = SEGMEXEC_TASK_SIZE;
25864+#endif
25865+
25866+ pax_task_size -= PAGE_SIZE;
25867+
25868+ if (len > pax_task_size)
25869+ return -ENOMEM;
25870+
25871+ if (flags & MAP_FIXED)
25872+ return addr;
25873+
25874+#ifdef CONFIG_PAX_RANDMMAP
25875+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25876+#endif
25877+
25878+ if (addr) {
25879+ addr = PAGE_ALIGN(addr);
25880+ if (pax_task_size - len >= addr) {
25881+ vma = find_vma(mm, addr);
25882+ if (check_heap_stack_gap(vma, addr, len, offset))
25883+ return addr;
25884+ }
25885+ }
25886+
25887+ info.flags = 0;
25888+ info.length = len;
25889+ info.align_mask = filp ? get_align_mask() : 0;
25890+ info.align_offset = pgoff << PAGE_SHIFT;
25891+ info.threadstack_offset = offset;
25892+
25893+#ifdef CONFIG_PAX_PAGEEXEC
25894+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25895+ info.low_limit = 0x00110000UL;
25896+ info.high_limit = mm->start_code;
25897+
25898+#ifdef CONFIG_PAX_RANDMMAP
25899+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25900+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25901+#endif
25902+
25903+ if (info.low_limit < info.high_limit) {
25904+ addr = vm_unmapped_area(&info);
25905+ if (!IS_ERR_VALUE(addr))
25906+ return addr;
25907+ }
25908+ } else
25909+#endif
25910+
25911+ info.low_limit = mm->mmap_base;
25912+ info.high_limit = pax_task_size;
25913+
25914+ return vm_unmapped_area(&info);
25915+}
25916+
25917+unsigned long
25918+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25919+ const unsigned long len, const unsigned long pgoff,
25920+ const unsigned long flags)
25921+{
25922+ struct vm_area_struct *vma;
25923+ struct mm_struct *mm = current->mm;
25924+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25925+ struct vm_unmapped_area_info info;
25926+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25927+
25928+#ifdef CONFIG_PAX_SEGMEXEC
25929+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25930+ pax_task_size = SEGMEXEC_TASK_SIZE;
25931+#endif
25932+
25933+ pax_task_size -= PAGE_SIZE;
25934+
25935+ /* requested length too big for entire address space */
25936+ if (len > pax_task_size)
25937+ return -ENOMEM;
25938+
25939+ if (flags & MAP_FIXED)
25940+ return addr;
25941+
25942+#ifdef CONFIG_PAX_PAGEEXEC
25943+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25944+ goto bottomup;
25945+#endif
25946+
25947+#ifdef CONFIG_PAX_RANDMMAP
25948+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25949+#endif
25950+
25951+ /* requesting a specific address */
25952+ if (addr) {
25953+ addr = PAGE_ALIGN(addr);
25954+ if (pax_task_size - len >= addr) {
25955+ vma = find_vma(mm, addr);
25956+ if (check_heap_stack_gap(vma, addr, len, offset))
25957+ return addr;
25958+ }
25959+ }
25960+
25961+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25962+ info.length = len;
25963+ info.low_limit = PAGE_SIZE;
25964+ info.high_limit = mm->mmap_base;
25965+ info.align_mask = filp ? get_align_mask() : 0;
25966+ info.align_offset = pgoff << PAGE_SHIFT;
25967+ info.threadstack_offset = offset;
25968+
25969+ addr = vm_unmapped_area(&info);
25970+ if (!(addr & ~PAGE_MASK))
25971+ return addr;
25972+ VM_BUG_ON(addr != -ENOMEM);
25973+
25974+bottomup:
25975+ /*
25976+ * A failed mmap() very likely causes application failure,
25977+ * so fall back to the bottom-up function here. This scenario
25978+ * can happen with large stack limits and large mmap()
25979+ * allocations.
25980+ */
25981+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25982+}
25983diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25984index 30277e2..5664a29 100644
25985--- a/arch/x86/kernel/sys_x86_64.c
25986+++ b/arch/x86/kernel/sys_x86_64.c
25987@@ -81,8 +81,8 @@ out:
25988 return error;
25989 }
25990
25991-static void find_start_end(unsigned long flags, unsigned long *begin,
25992- unsigned long *end)
25993+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25994+ unsigned long *begin, unsigned long *end)
25995 {
25996 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25997 unsigned long new_begin;
25998@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25999 *begin = new_begin;
26000 }
26001 } else {
26002- *begin = current->mm->mmap_legacy_base;
26003+ *begin = mm->mmap_legacy_base;
26004 *end = TASK_SIZE;
26005 }
26006 }
26007@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26008 struct vm_area_struct *vma;
26009 struct vm_unmapped_area_info info;
26010 unsigned long begin, end;
26011+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26012
26013 if (flags & MAP_FIXED)
26014 return addr;
26015
26016- find_start_end(flags, &begin, &end);
26017+ find_start_end(mm, flags, &begin, &end);
26018
26019 if (len > end)
26020 return -ENOMEM;
26021
26022+#ifdef CONFIG_PAX_RANDMMAP
26023+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26024+#endif
26025+
26026 if (addr) {
26027 addr = PAGE_ALIGN(addr);
26028 vma = find_vma(mm, addr);
26029- if (end - len >= addr &&
26030- (!vma || addr + len <= vma->vm_start))
26031+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26032 return addr;
26033 }
26034
26035@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26036 info.high_limit = end;
26037 info.align_mask = filp ? get_align_mask() : 0;
26038 info.align_offset = pgoff << PAGE_SHIFT;
26039+ info.threadstack_offset = offset;
26040 return vm_unmapped_area(&info);
26041 }
26042
26043@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26044 struct mm_struct *mm = current->mm;
26045 unsigned long addr = addr0;
26046 struct vm_unmapped_area_info info;
26047+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26048
26049 /* requested length too big for entire address space */
26050 if (len > TASK_SIZE)
26051@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26052 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
26053 goto bottomup;
26054
26055+#ifdef CONFIG_PAX_RANDMMAP
26056+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26057+#endif
26058+
26059 /* requesting a specific address */
26060 if (addr) {
26061 addr = PAGE_ALIGN(addr);
26062 vma = find_vma(mm, addr);
26063- if (TASK_SIZE - len >= addr &&
26064- (!vma || addr + len <= vma->vm_start))
26065+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26066 return addr;
26067 }
26068
26069@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26070 info.high_limit = mm->mmap_base;
26071 info.align_mask = filp ? get_align_mask() : 0;
26072 info.align_offset = pgoff << PAGE_SHIFT;
26073+ info.threadstack_offset = offset;
26074 addr = vm_unmapped_area(&info);
26075 if (!(addr & ~PAGE_MASK))
26076 return addr;
26077diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
26078index f84fe00..f41d9f1 100644
26079--- a/arch/x86/kernel/tboot.c
26080+++ b/arch/x86/kernel/tboot.c
26081@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
26082
26083 void tboot_shutdown(u32 shutdown_type)
26084 {
26085- void (*shutdown)(void);
26086+ void (* __noreturn shutdown)(void);
26087
26088 if (!tboot_enabled())
26089 return;
26090@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
26091
26092 switch_to_tboot_pt();
26093
26094- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
26095+ shutdown = (void *)tboot->shutdown_entry;
26096 shutdown();
26097
26098 /* should not reach here */
26099@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
26100 return 0;
26101 }
26102
26103-static atomic_t ap_wfs_count;
26104+static atomic_unchecked_t ap_wfs_count;
26105
26106 static int tboot_wait_for_aps(int num_aps)
26107 {
26108@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
26109 {
26110 switch (action) {
26111 case CPU_DYING:
26112- atomic_inc(&ap_wfs_count);
26113+ atomic_inc_unchecked(&ap_wfs_count);
26114 if (num_online_cpus() == 1)
26115- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
26116+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
26117 return NOTIFY_BAD;
26118 break;
26119 }
26120 return NOTIFY_OK;
26121 }
26122
26123-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
26124+static struct notifier_block tboot_cpu_notifier =
26125 {
26126 .notifier_call = tboot_cpu_callback,
26127 };
26128@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
26129
26130 tboot_create_trampoline();
26131
26132- atomic_set(&ap_wfs_count, 0);
26133+ atomic_set_unchecked(&ap_wfs_count, 0);
26134 register_hotcpu_notifier(&tboot_cpu_notifier);
26135
26136 acpi_os_set_prepare_sleep(&tboot_sleep);
26137diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
26138index 24d3c91..d06b473 100644
26139--- a/arch/x86/kernel/time.c
26140+++ b/arch/x86/kernel/time.c
26141@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
26142 {
26143 unsigned long pc = instruction_pointer(regs);
26144
26145- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
26146+ if (!user_mode(regs) && in_lock_functions(pc)) {
26147 #ifdef CONFIG_FRAME_POINTER
26148- return *(unsigned long *)(regs->bp + sizeof(long));
26149+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
26150 #else
26151 unsigned long *sp =
26152 (unsigned long *)kernel_stack_pointer(regs);
26153@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
26154 * or above a saved flags. Eflags has bits 22-31 zero,
26155 * kernel addresses don't.
26156 */
26157+
26158+#ifdef CONFIG_PAX_KERNEXEC
26159+ return ktla_ktva(sp[0]);
26160+#else
26161 if (sp[0] >> 22)
26162 return sp[0];
26163 if (sp[1] >> 22)
26164 return sp[1];
26165 #endif
26166+
26167+#endif
26168 }
26169 return pc;
26170 }
26171diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
26172index f7fec09..9991981 100644
26173--- a/arch/x86/kernel/tls.c
26174+++ b/arch/x86/kernel/tls.c
26175@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
26176 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
26177 return -EINVAL;
26178
26179+#ifdef CONFIG_PAX_SEGMEXEC
26180+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
26181+ return -EINVAL;
26182+#endif
26183+
26184 set_tls_desc(p, idx, &info, 1);
26185
26186 return 0;
26187@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
26188
26189 if (kbuf)
26190 info = kbuf;
26191- else if (__copy_from_user(infobuf, ubuf, count))
26192+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
26193 return -EFAULT;
26194 else
26195 info = infobuf;
26196diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
26197index 772e2a8..bad5bf6 100644
26198--- a/arch/x86/kernel/traps.c
26199+++ b/arch/x86/kernel/traps.c
26200@@ -68,12 +68,6 @@
26201 #include <asm/setup.h>
26202
26203 asmlinkage int system_call(void);
26204-
26205-/*
26206- * The IDT has to be page-aligned to simplify the Pentium
26207- * F0 0F bug workaround.
26208- */
26209-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
26210 #endif
26211
26212 DECLARE_BITMAP(used_vectors, NR_VECTORS);
26213@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
26214 }
26215
26216 static int __kprobes
26217-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26218+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
26219 struct pt_regs *regs, long error_code)
26220 {
26221 #ifdef CONFIG_X86_32
26222- if (regs->flags & X86_VM_MASK) {
26223+ if (v8086_mode(regs)) {
26224 /*
26225 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
26226 * On nmi (interrupt 2), do_trap should not be called.
26227@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26228 return -1;
26229 }
26230 #endif
26231- if (!user_mode(regs)) {
26232+ if (!user_mode_novm(regs)) {
26233 if (!fixup_exception(regs)) {
26234 tsk->thread.error_code = error_code;
26235 tsk->thread.trap_nr = trapnr;
26236+
26237+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26238+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
26239+ str = "PAX: suspicious stack segment fault";
26240+#endif
26241+
26242 die(str, regs, error_code);
26243 }
26244+
26245+#ifdef CONFIG_PAX_REFCOUNT
26246+ if (trapnr == 4)
26247+ pax_report_refcount_overflow(regs);
26248+#endif
26249+
26250 return 0;
26251 }
26252
26253@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26254 }
26255
26256 static void __kprobes
26257-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26258+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
26259 long error_code, siginfo_t *info)
26260 {
26261 struct task_struct *tsk = current;
26262@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26263 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
26264 printk_ratelimit()) {
26265 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
26266- tsk->comm, tsk->pid, str,
26267+ tsk->comm, task_pid_nr(tsk), str,
26268 regs->ip, regs->sp, error_code);
26269 print_vma_addr(" in ", regs->ip);
26270 pr_cont("\n");
26271@@ -273,7 +279,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
26272 conditional_sti(regs);
26273
26274 #ifdef CONFIG_X86_32
26275- if (regs->flags & X86_VM_MASK) {
26276+ if (v8086_mode(regs)) {
26277 local_irq_enable();
26278 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
26279 goto exit;
26280@@ -281,18 +287,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
26281 #endif
26282
26283 tsk = current;
26284- if (!user_mode(regs)) {
26285+ if (!user_mode_novm(regs)) {
26286 if (fixup_exception(regs))
26287 goto exit;
26288
26289 tsk->thread.error_code = error_code;
26290 tsk->thread.trap_nr = X86_TRAP_GP;
26291 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
26292- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
26293+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
26294+
26295+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26296+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
26297+ die("PAX: suspicious general protection fault", regs, error_code);
26298+ else
26299+#endif
26300+
26301 die("general protection fault", regs, error_code);
26302+ }
26303 goto exit;
26304 }
26305
26306+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26307+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
26308+ struct mm_struct *mm = tsk->mm;
26309+ unsigned long limit;
26310+
26311+ down_write(&mm->mmap_sem);
26312+ limit = mm->context.user_cs_limit;
26313+ if (limit < TASK_SIZE) {
26314+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26315+ up_write(&mm->mmap_sem);
26316+ return;
26317+ }
26318+ up_write(&mm->mmap_sem);
26319+ }
26320+#endif
26321+
26322 tsk->thread.error_code = error_code;
26323 tsk->thread.trap_nr = X86_TRAP_GP;
26324
26325@@ -450,7 +480,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26326 /* It's safe to allow irq's after DR6 has been saved */
26327 preempt_conditional_sti(regs);
26328
26329- if (regs->flags & X86_VM_MASK) {
26330+ if (v8086_mode(regs)) {
26331 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26332 X86_TRAP_DB);
26333 preempt_conditional_cli(regs);
26334@@ -465,7 +495,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26335 * We already checked v86 mode above, so we can check for kernel mode
26336 * by just checking the CPL of CS.
26337 */
26338- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26339+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26340 tsk->thread.debugreg6 &= ~DR_STEP;
26341 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26342 regs->flags &= ~X86_EFLAGS_TF;
26343@@ -497,7 +527,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26344 return;
26345 conditional_sti(regs);
26346
26347- if (!user_mode_vm(regs))
26348+ if (!user_mode(regs))
26349 {
26350 if (!fixup_exception(regs)) {
26351 task->thread.error_code = error_code;
26352diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26353index 2ed8459..7cf329f 100644
26354--- a/arch/x86/kernel/uprobes.c
26355+++ b/arch/x86/kernel/uprobes.c
26356@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26357 int ret = NOTIFY_DONE;
26358
26359 /* We are only interested in userspace traps */
26360- if (regs && !user_mode_vm(regs))
26361+ if (regs && !user_mode(regs))
26362 return NOTIFY_DONE;
26363
26364 switch (val) {
26365@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26366
26367 if (ncopied != rasize) {
26368 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26369- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26370+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26371
26372 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26373 }
26374diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26375index b9242ba..50c5edd 100644
26376--- a/arch/x86/kernel/verify_cpu.S
26377+++ b/arch/x86/kernel/verify_cpu.S
26378@@ -20,6 +20,7 @@
26379 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26380 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26381 * arch/x86/kernel/head_32.S: processor startup
26382+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26383 *
26384 * verify_cpu, returns the status of longmode and SSE in register %eax.
26385 * 0: Success 1: Failure
26386diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26387index e8edcf5..27f9344 100644
26388--- a/arch/x86/kernel/vm86_32.c
26389+++ b/arch/x86/kernel/vm86_32.c
26390@@ -44,6 +44,7 @@
26391 #include <linux/ptrace.h>
26392 #include <linux/audit.h>
26393 #include <linux/stddef.h>
26394+#include <linux/grsecurity.h>
26395
26396 #include <asm/uaccess.h>
26397 #include <asm/io.h>
26398@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26399 do_exit(SIGSEGV);
26400 }
26401
26402- tss = &per_cpu(init_tss, get_cpu());
26403+ tss = init_tss + get_cpu();
26404 current->thread.sp0 = current->thread.saved_sp0;
26405 current->thread.sysenter_cs = __KERNEL_CS;
26406 load_sp0(tss, &current->thread);
26407@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26408
26409 if (tsk->thread.saved_sp0)
26410 return -EPERM;
26411+
26412+#ifdef CONFIG_GRKERNSEC_VM86
26413+ if (!capable(CAP_SYS_RAWIO)) {
26414+ gr_handle_vm86();
26415+ return -EPERM;
26416+ }
26417+#endif
26418+
26419 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26420 offsetof(struct kernel_vm86_struct, vm86plus) -
26421 sizeof(info.regs));
26422@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26423 int tmp;
26424 struct vm86plus_struct __user *v86;
26425
26426+#ifdef CONFIG_GRKERNSEC_VM86
26427+ if (!capable(CAP_SYS_RAWIO)) {
26428+ gr_handle_vm86();
26429+ return -EPERM;
26430+ }
26431+#endif
26432+
26433 tsk = current;
26434 switch (cmd) {
26435 case VM86_REQUEST_IRQ:
26436@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26437 tsk->thread.saved_fs = info->regs32->fs;
26438 tsk->thread.saved_gs = get_user_gs(info->regs32);
26439
26440- tss = &per_cpu(init_tss, get_cpu());
26441+ tss = init_tss + get_cpu();
26442 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26443 if (cpu_has_sep)
26444 tsk->thread.sysenter_cs = 0;
26445@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26446 goto cannot_handle;
26447 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26448 goto cannot_handle;
26449- intr_ptr = (unsigned long __user *) (i << 2);
26450+ intr_ptr = (__force unsigned long __user *) (i << 2);
26451 if (get_user(segoffs, intr_ptr))
26452 goto cannot_handle;
26453 if ((segoffs >> 16) == BIOSSEG)
26454diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26455index 10c4f30..57377c2 100644
26456--- a/arch/x86/kernel/vmlinux.lds.S
26457+++ b/arch/x86/kernel/vmlinux.lds.S
26458@@ -26,6 +26,13 @@
26459 #include <asm/page_types.h>
26460 #include <asm/cache.h>
26461 #include <asm/boot.h>
26462+#include <asm/segment.h>
26463+
26464+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26465+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26466+#else
26467+#define __KERNEL_TEXT_OFFSET 0
26468+#endif
26469
26470 #undef i386 /* in case the preprocessor is a 32bit one */
26471
26472@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26473
26474 PHDRS {
26475 text PT_LOAD FLAGS(5); /* R_E */
26476+#ifdef CONFIG_X86_32
26477+ module PT_LOAD FLAGS(5); /* R_E */
26478+#endif
26479+#ifdef CONFIG_XEN
26480+ rodata PT_LOAD FLAGS(5); /* R_E */
26481+#else
26482+ rodata PT_LOAD FLAGS(4); /* R__ */
26483+#endif
26484 data PT_LOAD FLAGS(6); /* RW_ */
26485-#ifdef CONFIG_X86_64
26486+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26487 #ifdef CONFIG_SMP
26488 percpu PT_LOAD FLAGS(6); /* RW_ */
26489 #endif
26490+ text.init PT_LOAD FLAGS(5); /* R_E */
26491+ text.exit PT_LOAD FLAGS(5); /* R_E */
26492 init PT_LOAD FLAGS(7); /* RWE */
26493-#endif
26494 note PT_NOTE FLAGS(0); /* ___ */
26495 }
26496
26497 SECTIONS
26498 {
26499 #ifdef CONFIG_X86_32
26500- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26501- phys_startup_32 = startup_32 - LOAD_OFFSET;
26502+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26503 #else
26504- . = __START_KERNEL;
26505- phys_startup_64 = startup_64 - LOAD_OFFSET;
26506+ . = __START_KERNEL;
26507 #endif
26508
26509 /* Text and read-only data */
26510- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26511- _text = .;
26512+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26513 /* bootstrapping code */
26514+#ifdef CONFIG_X86_32
26515+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26516+#else
26517+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26518+#endif
26519+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26520+ _text = .;
26521 HEAD_TEXT
26522 . = ALIGN(8);
26523 _stext = .;
26524@@ -104,13 +124,48 @@ SECTIONS
26525 IRQENTRY_TEXT
26526 *(.fixup)
26527 *(.gnu.warning)
26528- /* End of text section */
26529- _etext = .;
26530 } :text = 0x9090
26531
26532- NOTES :text :note
26533+ . += __KERNEL_TEXT_OFFSET;
26534
26535- EXCEPTION_TABLE(16) :text = 0x9090
26536+#ifdef CONFIG_X86_32
26537+ . = ALIGN(PAGE_SIZE);
26538+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26539+
26540+#ifdef CONFIG_PAX_KERNEXEC
26541+ MODULES_EXEC_VADDR = .;
26542+ BYTE(0)
26543+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26544+ . = ALIGN(HPAGE_SIZE) - 1;
26545+ MODULES_EXEC_END = .;
26546+#endif
26547+
26548+ } :module
26549+#endif
26550+
26551+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26552+ /* End of text section */
26553+ BYTE(0)
26554+ _etext = . - __KERNEL_TEXT_OFFSET;
26555+ }
26556+
26557+#ifdef CONFIG_X86_32
26558+ . = ALIGN(PAGE_SIZE);
26559+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26560+ *(.idt)
26561+ . = ALIGN(PAGE_SIZE);
26562+ *(.empty_zero_page)
26563+ *(.initial_pg_fixmap)
26564+ *(.initial_pg_pmd)
26565+ *(.initial_page_table)
26566+ *(.swapper_pg_dir)
26567+ } :rodata
26568+#endif
26569+
26570+ . = ALIGN(PAGE_SIZE);
26571+ NOTES :rodata :note
26572+
26573+ EXCEPTION_TABLE(16) :rodata
26574
26575 #if defined(CONFIG_DEBUG_RODATA)
26576 /* .text should occupy whole number of pages */
26577@@ -122,16 +177,20 @@ SECTIONS
26578
26579 /* Data */
26580 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26581+
26582+#ifdef CONFIG_PAX_KERNEXEC
26583+ . = ALIGN(HPAGE_SIZE);
26584+#else
26585+ . = ALIGN(PAGE_SIZE);
26586+#endif
26587+
26588 /* Start of data section */
26589 _sdata = .;
26590
26591 /* init_task */
26592 INIT_TASK_DATA(THREAD_SIZE)
26593
26594-#ifdef CONFIG_X86_32
26595- /* 32 bit has nosave before _edata */
26596 NOSAVE_DATA
26597-#endif
26598
26599 PAGE_ALIGNED_DATA(PAGE_SIZE)
26600
26601@@ -172,12 +231,19 @@ SECTIONS
26602 #endif /* CONFIG_X86_64 */
26603
26604 /* Init code and data - will be freed after init */
26605- . = ALIGN(PAGE_SIZE);
26606 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26607+ BYTE(0)
26608+
26609+#ifdef CONFIG_PAX_KERNEXEC
26610+ . = ALIGN(HPAGE_SIZE);
26611+#else
26612+ . = ALIGN(PAGE_SIZE);
26613+#endif
26614+
26615 __init_begin = .; /* paired with __init_end */
26616- }
26617+ } :init.begin
26618
26619-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26620+#ifdef CONFIG_SMP
26621 /*
26622 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26623 * output PHDR, so the next output section - .init.text - should
26624@@ -186,12 +252,27 @@ SECTIONS
26625 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26626 #endif
26627
26628- INIT_TEXT_SECTION(PAGE_SIZE)
26629-#ifdef CONFIG_X86_64
26630- :init
26631-#endif
26632+ . = ALIGN(PAGE_SIZE);
26633+ init_begin = .;
26634+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26635+ VMLINUX_SYMBOL(_sinittext) = .;
26636+ INIT_TEXT
26637+ VMLINUX_SYMBOL(_einittext) = .;
26638+ . = ALIGN(PAGE_SIZE);
26639+ } :text.init
26640
26641- INIT_DATA_SECTION(16)
26642+ /*
26643+ * .exit.text is discard at runtime, not link time, to deal with
26644+ * references from .altinstructions and .eh_frame
26645+ */
26646+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26647+ EXIT_TEXT
26648+ . = ALIGN(16);
26649+ } :text.exit
26650+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26651+
26652+ . = ALIGN(PAGE_SIZE);
26653+ INIT_DATA_SECTION(16) :init
26654
26655 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26656 __x86_cpu_dev_start = .;
26657@@ -253,19 +334,12 @@ SECTIONS
26658 }
26659
26660 . = ALIGN(8);
26661- /*
26662- * .exit.text is discard at runtime, not link time, to deal with
26663- * references from .altinstructions and .eh_frame
26664- */
26665- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26666- EXIT_TEXT
26667- }
26668
26669 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26670 EXIT_DATA
26671 }
26672
26673-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26674+#ifndef CONFIG_SMP
26675 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26676 #endif
26677
26678@@ -284,16 +358,10 @@ SECTIONS
26679 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26680 __smp_locks = .;
26681 *(.smp_locks)
26682- . = ALIGN(PAGE_SIZE);
26683 __smp_locks_end = .;
26684+ . = ALIGN(PAGE_SIZE);
26685 }
26686
26687-#ifdef CONFIG_X86_64
26688- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26689- NOSAVE_DATA
26690- }
26691-#endif
26692-
26693 /* BSS */
26694 . = ALIGN(PAGE_SIZE);
26695 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26696@@ -309,6 +377,7 @@ SECTIONS
26697 __brk_base = .;
26698 . += 64 * 1024; /* 64k alignment slop space */
26699 *(.brk_reservation) /* areas brk users have reserved */
26700+ . = ALIGN(HPAGE_SIZE);
26701 __brk_limit = .;
26702 }
26703
26704@@ -335,13 +404,12 @@ SECTIONS
26705 * for the boot processor.
26706 */
26707 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26708-INIT_PER_CPU(gdt_page);
26709 INIT_PER_CPU(irq_stack_union);
26710
26711 /*
26712 * Build-time check on the image size:
26713 */
26714-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26715+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26716 "kernel image bigger than KERNEL_IMAGE_SIZE");
26717
26718 #ifdef CONFIG_SMP
26719diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26720index 9a907a6..f83f921 100644
26721--- a/arch/x86/kernel/vsyscall_64.c
26722+++ b/arch/x86/kernel/vsyscall_64.c
26723@@ -56,15 +56,13 @@
26724 DEFINE_VVAR(int, vgetcpu_mode);
26725 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26726
26727-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26728+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26729
26730 static int __init vsyscall_setup(char *str)
26731 {
26732 if (str) {
26733 if (!strcmp("emulate", str))
26734 vsyscall_mode = EMULATE;
26735- else if (!strcmp("native", str))
26736- vsyscall_mode = NATIVE;
26737 else if (!strcmp("none", str))
26738 vsyscall_mode = NONE;
26739 else
26740@@ -323,8 +321,7 @@ do_ret:
26741 return true;
26742
26743 sigsegv:
26744- force_sig(SIGSEGV, current);
26745- return true;
26746+ do_group_exit(SIGKILL);
26747 }
26748
26749 /*
26750@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26751 extern char __vvar_page;
26752 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26753
26754- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26755- vsyscall_mode == NATIVE
26756- ? PAGE_KERNEL_VSYSCALL
26757- : PAGE_KERNEL_VVAR);
26758+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26759 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26760 (unsigned long)VSYSCALL_START);
26761
26762diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26763index b014d94..e775258 100644
26764--- a/arch/x86/kernel/x8664_ksyms_64.c
26765+++ b/arch/x86/kernel/x8664_ksyms_64.c
26766@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26767 EXPORT_SYMBOL(copy_user_generic_unrolled);
26768 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26769 EXPORT_SYMBOL(__copy_user_nocache);
26770-EXPORT_SYMBOL(_copy_from_user);
26771-EXPORT_SYMBOL(_copy_to_user);
26772
26773 EXPORT_SYMBOL(copy_page);
26774 EXPORT_SYMBOL(clear_page);
26775@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26776 #ifndef CONFIG_PARAVIRT
26777 EXPORT_SYMBOL(native_load_gs_index);
26778 #endif
26779+
26780+#ifdef CONFIG_PAX_PER_CPU_PGD
26781+EXPORT_SYMBOL(cpu_pgd);
26782+#endif
26783diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26784index 45a14db..075bb9b 100644
26785--- a/arch/x86/kernel/x86_init.c
26786+++ b/arch/x86/kernel/x86_init.c
26787@@ -85,7 +85,7 @@ struct x86_init_ops x86_init __initdata = {
26788 },
26789 };
26790
26791-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
26792+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
26793 .early_percpu_clock_init = x86_init_noop,
26794 .setup_percpu_clockev = setup_secondary_APIC_clock,
26795 };
26796@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
26797 static void default_nmi_init(void) { };
26798 static int default_i8042_detect(void) { return 1; };
26799
26800-struct x86_platform_ops x86_platform = {
26801+struct x86_platform_ops x86_platform __read_only = {
26802 .calibrate_tsc = native_calibrate_tsc,
26803 .get_wallclock = mach_get_cmos_time,
26804 .set_wallclock = mach_set_rtc_mmss,
26805@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
26806 };
26807
26808 EXPORT_SYMBOL_GPL(x86_platform);
26809-struct x86_msi_ops x86_msi = {
26810+struct x86_msi_ops x86_msi __read_only = {
26811 .setup_msi_irqs = native_setup_msi_irqs,
26812 .compose_msi_msg = native_compose_msi_msg,
26813 .teardown_msi_irq = native_teardown_msi_irq,
26814@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
26815 .setup_hpet_msi = default_setup_hpet_msi,
26816 };
26817
26818-struct x86_io_apic_ops x86_io_apic_ops = {
26819+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26820 .init = native_io_apic_init_mappings,
26821 .read = native_io_apic_read,
26822 .write = native_io_apic_write,
26823diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26824index ada87a3..afea76d 100644
26825--- a/arch/x86/kernel/xsave.c
26826+++ b/arch/x86/kernel/xsave.c
26827@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26828 {
26829 int err;
26830
26831+ buf = (struct xsave_struct __user *)____m(buf);
26832 if (use_xsave())
26833 err = xsave_user(buf);
26834 else if (use_fxsr())
26835@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26836 */
26837 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26838 {
26839+ buf = (void __user *)____m(buf);
26840 if (use_xsave()) {
26841 if ((unsigned long)buf % 64 || fx_only) {
26842 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26843diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26844index a20ecb5..d0e2194 100644
26845--- a/arch/x86/kvm/cpuid.c
26846+++ b/arch/x86/kvm/cpuid.c
26847@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26848 struct kvm_cpuid2 *cpuid,
26849 struct kvm_cpuid_entry2 __user *entries)
26850 {
26851- int r;
26852+ int r, i;
26853
26854 r = -E2BIG;
26855 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26856 goto out;
26857 r = -EFAULT;
26858- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26859- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26860+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26861 goto out;
26862+ for (i = 0; i < cpuid->nent; ++i) {
26863+ struct kvm_cpuid_entry2 cpuid_entry;
26864+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26865+ goto out;
26866+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26867+ }
26868 vcpu->arch.cpuid_nent = cpuid->nent;
26869 kvm_apic_set_version(vcpu);
26870 kvm_x86_ops->cpuid_update(vcpu);
26871@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26872 struct kvm_cpuid2 *cpuid,
26873 struct kvm_cpuid_entry2 __user *entries)
26874 {
26875- int r;
26876+ int r, i;
26877
26878 r = -E2BIG;
26879 if (cpuid->nent < vcpu->arch.cpuid_nent)
26880 goto out;
26881 r = -EFAULT;
26882- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26883- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26884+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26885 goto out;
26886+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26887+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26888+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26889+ goto out;
26890+ }
26891 return 0;
26892
26893 out:
26894diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
26895index 5953dce..f11a7d2 100644
26896--- a/arch/x86/kvm/emulate.c
26897+++ b/arch/x86/kvm/emulate.c
26898@@ -329,6 +329,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
26899
26900 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
26901 do { \
26902+ unsigned long _tmp; \
26903 __asm__ __volatile__ ( \
26904 _PRE_EFLAGS("0", "4", "2") \
26905 _op _suffix " %"_x"3,%1; " \
26906@@ -343,8 +344,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
26907 /* Raw emulation: instruction has two explicit operands. */
26908 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
26909 do { \
26910- unsigned long _tmp; \
26911- \
26912 switch ((ctxt)->dst.bytes) { \
26913 case 2: \
26914 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
26915@@ -360,7 +359,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
26916
26917 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
26918 do { \
26919- unsigned long _tmp; \
26920 switch ((ctxt)->dst.bytes) { \
26921 case 1: \
26922 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
26923diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26924index 0eee2c8..94a32c3 100644
26925--- a/arch/x86/kvm/lapic.c
26926+++ b/arch/x86/kvm/lapic.c
26927@@ -55,7 +55,7 @@
26928 #define APIC_BUS_CYCLE_NS 1
26929
26930 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26931-#define apic_debug(fmt, arg...)
26932+#define apic_debug(fmt, arg...) do {} while (0)
26933
26934 #define APIC_LVT_NUM 6
26935 /* 14 is the version for Xeon and Pentium 8.4.8*/
26936diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26937index da20860..d19fdf5 100644
26938--- a/arch/x86/kvm/paging_tmpl.h
26939+++ b/arch/x86/kvm/paging_tmpl.h
26940@@ -208,7 +208,7 @@ retry_walk:
26941 if (unlikely(kvm_is_error_hva(host_addr)))
26942 goto error;
26943
26944- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26945+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26946 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26947 goto error;
26948 walker->ptep_user[walker->level - 1] = ptep_user;
26949diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26950index a14a6ea..dc86cf0 100644
26951--- a/arch/x86/kvm/svm.c
26952+++ b/arch/x86/kvm/svm.c
26953@@ -3493,7 +3493,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26954 int cpu = raw_smp_processor_id();
26955
26956 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26957+
26958+ pax_open_kernel();
26959 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26960+ pax_close_kernel();
26961+
26962 load_TR_desc();
26963 }
26964
26965@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26966 #endif
26967 #endif
26968
26969+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26970+ __set_fs(current_thread_info()->addr_limit);
26971+#endif
26972+
26973 reload_tss(vcpu);
26974
26975 local_irq_disable();
26976diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26977index 5402c94..c3bdeee 100644
26978--- a/arch/x86/kvm/vmx.c
26979+++ b/arch/x86/kvm/vmx.c
26980@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26981 #endif
26982 }
26983
26984-static void vmcs_clear_bits(unsigned long field, u32 mask)
26985+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26986 {
26987 vmcs_writel(field, vmcs_readl(field) & ~mask);
26988 }
26989
26990-static void vmcs_set_bits(unsigned long field, u32 mask)
26991+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26992 {
26993 vmcs_writel(field, vmcs_readl(field) | mask);
26994 }
26995@@ -1517,7 +1517,11 @@ static void reload_tss(void)
26996 struct desc_struct *descs;
26997
26998 descs = (void *)gdt->address;
26999+
27000+ pax_open_kernel();
27001 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
27002+ pax_close_kernel();
27003+
27004 load_TR_desc();
27005 }
27006
27007@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
27008 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
27009 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
27010
27011+#ifdef CONFIG_PAX_PER_CPU_PGD
27012+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27013+#endif
27014+
27015 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
27016 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
27017 vmx->loaded_vmcs->cpu = cpu;
27018@@ -2935,8 +2943,11 @@ static __init int hardware_setup(void)
27019 if (!cpu_has_vmx_flexpriority())
27020 flexpriority_enabled = 0;
27021
27022- if (!cpu_has_vmx_tpr_shadow())
27023- kvm_x86_ops->update_cr8_intercept = NULL;
27024+ if (!cpu_has_vmx_tpr_shadow()) {
27025+ pax_open_kernel();
27026+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27027+ pax_close_kernel();
27028+ }
27029
27030 if (enable_ept && !cpu_has_vmx_ept_2m_page())
27031 kvm_disable_largepages();
27032@@ -2947,13 +2958,15 @@ static __init int hardware_setup(void)
27033 if (!cpu_has_vmx_apicv())
27034 enable_apicv = 0;
27035
27036+ pax_open_kernel();
27037 if (enable_apicv)
27038- kvm_x86_ops->update_cr8_intercept = NULL;
27039+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27040 else {
27041- kvm_x86_ops->hwapic_irr_update = NULL;
27042- kvm_x86_ops->deliver_posted_interrupt = NULL;
27043- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27044+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
27045+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
27046+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27047 }
27048+ pax_close_kernel();
27049
27050 if (nested)
27051 nested_vmx_setup_ctls_msrs();
27052@@ -4076,7 +4089,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27053
27054 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
27055 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
27056+
27057+#ifndef CONFIG_PAX_PER_CPU_PGD
27058 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27059+#endif
27060
27061 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
27062 #ifdef CONFIG_X86_64
27063@@ -4098,7 +4114,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27064 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
27065 vmx->host_idt_base = dt.address;
27066
27067- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
27068+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
27069
27070 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
27071 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
27072@@ -7030,6 +7046,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27073 "jmp 2f \n\t"
27074 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
27075 "2: "
27076+
27077+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27078+ "ljmp %[cs],$3f\n\t"
27079+ "3: "
27080+#endif
27081+
27082 /* Save guest registers, load host registers, keep flags */
27083 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
27084 "pop %0 \n\t"
27085@@ -7082,6 +7104,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27086 #endif
27087 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
27088 [wordsize]"i"(sizeof(ulong))
27089+
27090+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27091+ ,[cs]"i"(__KERNEL_CS)
27092+#endif
27093+
27094 : "cc", "memory"
27095 #ifdef CONFIG_X86_64
27096 , "rax", "rbx", "rdi", "rsi"
27097@@ -7095,7 +7122,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27098 if (debugctlmsr)
27099 update_debugctlmsr(debugctlmsr);
27100
27101-#ifndef CONFIG_X86_64
27102+#ifdef CONFIG_X86_32
27103 /*
27104 * The sysexit path does not restore ds/es, so we must set them to
27105 * a reasonable value ourselves.
27106@@ -7104,8 +7131,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27107 * may be executed in interrupt context, which saves and restore segments
27108 * around it, nullifying its effect.
27109 */
27110- loadsegment(ds, __USER_DS);
27111- loadsegment(es, __USER_DS);
27112+ loadsegment(ds, __KERNEL_DS);
27113+ loadsegment(es, __KERNEL_DS);
27114+ loadsegment(ss, __KERNEL_DS);
27115+
27116+#ifdef CONFIG_PAX_KERNEXEC
27117+ loadsegment(fs, __KERNEL_PERCPU);
27118+#endif
27119+
27120+#ifdef CONFIG_PAX_MEMORY_UDEREF
27121+ __set_fs(current_thread_info()->addr_limit);
27122+#endif
27123+
27124 #endif
27125
27126 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
27127diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
27128index e8ba99c..ee9d7d9 100644
27129--- a/arch/x86/kvm/x86.c
27130+++ b/arch/x86/kvm/x86.c
27131@@ -1725,8 +1725,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
27132 {
27133 struct kvm *kvm = vcpu->kvm;
27134 int lm = is_long_mode(vcpu);
27135- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27136- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27137+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27138+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27139 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
27140 : kvm->arch.xen_hvm_config.blob_size_32;
27141 u32 page_num = data & ~PAGE_MASK;
27142@@ -2609,6 +2609,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
27143 if (n < msr_list.nmsrs)
27144 goto out;
27145 r = -EFAULT;
27146+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
27147+ goto out;
27148 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
27149 num_msrs_to_save * sizeof(u32)))
27150 goto out;
27151@@ -5297,7 +5299,7 @@ static struct notifier_block pvclock_gtod_notifier = {
27152 };
27153 #endif
27154
27155-int kvm_arch_init(void *opaque)
27156+int kvm_arch_init(const void *opaque)
27157 {
27158 int r;
27159 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
27160diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
27161index 7114c63..a1018fc 100644
27162--- a/arch/x86/lguest/boot.c
27163+++ b/arch/x86/lguest/boot.c
27164@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
27165 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
27166 * Launcher to reboot us.
27167 */
27168-static void lguest_restart(char *reason)
27169+static __noreturn void lguest_restart(char *reason)
27170 {
27171 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
27172+ BUG();
27173 }
27174
27175 /*G:050
27176diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
27177index 00933d5..3a64af9 100644
27178--- a/arch/x86/lib/atomic64_386_32.S
27179+++ b/arch/x86/lib/atomic64_386_32.S
27180@@ -48,6 +48,10 @@ BEGIN(read)
27181 movl (v), %eax
27182 movl 4(v), %edx
27183 RET_ENDP
27184+BEGIN(read_unchecked)
27185+ movl (v), %eax
27186+ movl 4(v), %edx
27187+RET_ENDP
27188 #undef v
27189
27190 #define v %esi
27191@@ -55,6 +59,10 @@ BEGIN(set)
27192 movl %ebx, (v)
27193 movl %ecx, 4(v)
27194 RET_ENDP
27195+BEGIN(set_unchecked)
27196+ movl %ebx, (v)
27197+ movl %ecx, 4(v)
27198+RET_ENDP
27199 #undef v
27200
27201 #define v %esi
27202@@ -70,6 +78,20 @@ RET_ENDP
27203 BEGIN(add)
27204 addl %eax, (v)
27205 adcl %edx, 4(v)
27206+
27207+#ifdef CONFIG_PAX_REFCOUNT
27208+ jno 0f
27209+ subl %eax, (v)
27210+ sbbl %edx, 4(v)
27211+ int $4
27212+0:
27213+ _ASM_EXTABLE(0b, 0b)
27214+#endif
27215+
27216+RET_ENDP
27217+BEGIN(add_unchecked)
27218+ addl %eax, (v)
27219+ adcl %edx, 4(v)
27220 RET_ENDP
27221 #undef v
27222
27223@@ -77,6 +99,24 @@ RET_ENDP
27224 BEGIN(add_return)
27225 addl (v), %eax
27226 adcl 4(v), %edx
27227+
27228+#ifdef CONFIG_PAX_REFCOUNT
27229+ into
27230+1234:
27231+ _ASM_EXTABLE(1234b, 2f)
27232+#endif
27233+
27234+ movl %eax, (v)
27235+ movl %edx, 4(v)
27236+
27237+#ifdef CONFIG_PAX_REFCOUNT
27238+2:
27239+#endif
27240+
27241+RET_ENDP
27242+BEGIN(add_return_unchecked)
27243+ addl (v), %eax
27244+ adcl 4(v), %edx
27245 movl %eax, (v)
27246 movl %edx, 4(v)
27247 RET_ENDP
27248@@ -86,6 +126,20 @@ RET_ENDP
27249 BEGIN(sub)
27250 subl %eax, (v)
27251 sbbl %edx, 4(v)
27252+
27253+#ifdef CONFIG_PAX_REFCOUNT
27254+ jno 0f
27255+ addl %eax, (v)
27256+ adcl %edx, 4(v)
27257+ int $4
27258+0:
27259+ _ASM_EXTABLE(0b, 0b)
27260+#endif
27261+
27262+RET_ENDP
27263+BEGIN(sub_unchecked)
27264+ subl %eax, (v)
27265+ sbbl %edx, 4(v)
27266 RET_ENDP
27267 #undef v
27268
27269@@ -96,6 +150,27 @@ BEGIN(sub_return)
27270 sbbl $0, %edx
27271 addl (v), %eax
27272 adcl 4(v), %edx
27273+
27274+#ifdef CONFIG_PAX_REFCOUNT
27275+ into
27276+1234:
27277+ _ASM_EXTABLE(1234b, 2f)
27278+#endif
27279+
27280+ movl %eax, (v)
27281+ movl %edx, 4(v)
27282+
27283+#ifdef CONFIG_PAX_REFCOUNT
27284+2:
27285+#endif
27286+
27287+RET_ENDP
27288+BEGIN(sub_return_unchecked)
27289+ negl %edx
27290+ negl %eax
27291+ sbbl $0, %edx
27292+ addl (v), %eax
27293+ adcl 4(v), %edx
27294 movl %eax, (v)
27295 movl %edx, 4(v)
27296 RET_ENDP
27297@@ -105,6 +180,20 @@ RET_ENDP
27298 BEGIN(inc)
27299 addl $1, (v)
27300 adcl $0, 4(v)
27301+
27302+#ifdef CONFIG_PAX_REFCOUNT
27303+ jno 0f
27304+ subl $1, (v)
27305+ sbbl $0, 4(v)
27306+ int $4
27307+0:
27308+ _ASM_EXTABLE(0b, 0b)
27309+#endif
27310+
27311+RET_ENDP
27312+BEGIN(inc_unchecked)
27313+ addl $1, (v)
27314+ adcl $0, 4(v)
27315 RET_ENDP
27316 #undef v
27317
27318@@ -114,6 +203,26 @@ BEGIN(inc_return)
27319 movl 4(v), %edx
27320 addl $1, %eax
27321 adcl $0, %edx
27322+
27323+#ifdef CONFIG_PAX_REFCOUNT
27324+ into
27325+1234:
27326+ _ASM_EXTABLE(1234b, 2f)
27327+#endif
27328+
27329+ movl %eax, (v)
27330+ movl %edx, 4(v)
27331+
27332+#ifdef CONFIG_PAX_REFCOUNT
27333+2:
27334+#endif
27335+
27336+RET_ENDP
27337+BEGIN(inc_return_unchecked)
27338+ movl (v), %eax
27339+ movl 4(v), %edx
27340+ addl $1, %eax
27341+ adcl $0, %edx
27342 movl %eax, (v)
27343 movl %edx, 4(v)
27344 RET_ENDP
27345@@ -123,6 +232,20 @@ RET_ENDP
27346 BEGIN(dec)
27347 subl $1, (v)
27348 sbbl $0, 4(v)
27349+
27350+#ifdef CONFIG_PAX_REFCOUNT
27351+ jno 0f
27352+ addl $1, (v)
27353+ adcl $0, 4(v)
27354+ int $4
27355+0:
27356+ _ASM_EXTABLE(0b, 0b)
27357+#endif
27358+
27359+RET_ENDP
27360+BEGIN(dec_unchecked)
27361+ subl $1, (v)
27362+ sbbl $0, 4(v)
27363 RET_ENDP
27364 #undef v
27365
27366@@ -132,6 +255,26 @@ BEGIN(dec_return)
27367 movl 4(v), %edx
27368 subl $1, %eax
27369 sbbl $0, %edx
27370+
27371+#ifdef CONFIG_PAX_REFCOUNT
27372+ into
27373+1234:
27374+ _ASM_EXTABLE(1234b, 2f)
27375+#endif
27376+
27377+ movl %eax, (v)
27378+ movl %edx, 4(v)
27379+
27380+#ifdef CONFIG_PAX_REFCOUNT
27381+2:
27382+#endif
27383+
27384+RET_ENDP
27385+BEGIN(dec_return_unchecked)
27386+ movl (v), %eax
27387+ movl 4(v), %edx
27388+ subl $1, %eax
27389+ sbbl $0, %edx
27390 movl %eax, (v)
27391 movl %edx, 4(v)
27392 RET_ENDP
27393@@ -143,6 +286,13 @@ BEGIN(add_unless)
27394 adcl %edx, %edi
27395 addl (v), %eax
27396 adcl 4(v), %edx
27397+
27398+#ifdef CONFIG_PAX_REFCOUNT
27399+ into
27400+1234:
27401+ _ASM_EXTABLE(1234b, 2f)
27402+#endif
27403+
27404 cmpl %eax, %ecx
27405 je 3f
27406 1:
27407@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27408 1:
27409 addl $1, %eax
27410 adcl $0, %edx
27411+
27412+#ifdef CONFIG_PAX_REFCOUNT
27413+ into
27414+1234:
27415+ _ASM_EXTABLE(1234b, 2f)
27416+#endif
27417+
27418 movl %eax, (v)
27419 movl %edx, 4(v)
27420 movl $1, %eax
27421@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27422 movl 4(v), %edx
27423 subl $1, %eax
27424 sbbl $0, %edx
27425+
27426+#ifdef CONFIG_PAX_REFCOUNT
27427+ into
27428+1234:
27429+ _ASM_EXTABLE(1234b, 1f)
27430+#endif
27431+
27432 js 1f
27433 movl %eax, (v)
27434 movl %edx, 4(v)
27435diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27436index f5cc9eb..51fa319 100644
27437--- a/arch/x86/lib/atomic64_cx8_32.S
27438+++ b/arch/x86/lib/atomic64_cx8_32.S
27439@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27440 CFI_STARTPROC
27441
27442 read64 %ecx
27443+ pax_force_retaddr
27444 ret
27445 CFI_ENDPROC
27446 ENDPROC(atomic64_read_cx8)
27447
27448+ENTRY(atomic64_read_unchecked_cx8)
27449+ CFI_STARTPROC
27450+
27451+ read64 %ecx
27452+ pax_force_retaddr
27453+ ret
27454+ CFI_ENDPROC
27455+ENDPROC(atomic64_read_unchecked_cx8)
27456+
27457 ENTRY(atomic64_set_cx8)
27458 CFI_STARTPROC
27459
27460@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27461 cmpxchg8b (%esi)
27462 jne 1b
27463
27464+ pax_force_retaddr
27465 ret
27466 CFI_ENDPROC
27467 ENDPROC(atomic64_set_cx8)
27468
27469+ENTRY(atomic64_set_unchecked_cx8)
27470+ CFI_STARTPROC
27471+
27472+1:
27473+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27474+ * are atomic on 586 and newer */
27475+ cmpxchg8b (%esi)
27476+ jne 1b
27477+
27478+ pax_force_retaddr
27479+ ret
27480+ CFI_ENDPROC
27481+ENDPROC(atomic64_set_unchecked_cx8)
27482+
27483 ENTRY(atomic64_xchg_cx8)
27484 CFI_STARTPROC
27485
27486@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27487 cmpxchg8b (%esi)
27488 jne 1b
27489
27490+ pax_force_retaddr
27491 ret
27492 CFI_ENDPROC
27493 ENDPROC(atomic64_xchg_cx8)
27494
27495-.macro addsub_return func ins insc
27496-ENTRY(atomic64_\func\()_return_cx8)
27497+.macro addsub_return func ins insc unchecked=""
27498+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27499 CFI_STARTPROC
27500 SAVE ebp
27501 SAVE ebx
27502@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27503 movl %edx, %ecx
27504 \ins\()l %esi, %ebx
27505 \insc\()l %edi, %ecx
27506+
27507+.ifb \unchecked
27508+#ifdef CONFIG_PAX_REFCOUNT
27509+ into
27510+2:
27511+ _ASM_EXTABLE(2b, 3f)
27512+#endif
27513+.endif
27514+
27515 LOCK_PREFIX
27516 cmpxchg8b (%ebp)
27517 jne 1b
27518-
27519-10:
27520 movl %ebx, %eax
27521 movl %ecx, %edx
27522+
27523+.ifb \unchecked
27524+#ifdef CONFIG_PAX_REFCOUNT
27525+3:
27526+#endif
27527+.endif
27528+
27529 RESTORE edi
27530 RESTORE esi
27531 RESTORE ebx
27532 RESTORE ebp
27533+ pax_force_retaddr
27534 ret
27535 CFI_ENDPROC
27536-ENDPROC(atomic64_\func\()_return_cx8)
27537+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27538 .endm
27539
27540 addsub_return add add adc
27541 addsub_return sub sub sbb
27542+addsub_return add add adc _unchecked
27543+addsub_return sub sub sbb _unchecked
27544
27545-.macro incdec_return func ins insc
27546-ENTRY(atomic64_\func\()_return_cx8)
27547+.macro incdec_return func ins insc unchecked=""
27548+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27549 CFI_STARTPROC
27550 SAVE ebx
27551
27552@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27553 movl %edx, %ecx
27554 \ins\()l $1, %ebx
27555 \insc\()l $0, %ecx
27556+
27557+.ifb \unchecked
27558+#ifdef CONFIG_PAX_REFCOUNT
27559+ into
27560+2:
27561+ _ASM_EXTABLE(2b, 3f)
27562+#endif
27563+.endif
27564+
27565 LOCK_PREFIX
27566 cmpxchg8b (%esi)
27567 jne 1b
27568
27569-10:
27570 movl %ebx, %eax
27571 movl %ecx, %edx
27572+
27573+.ifb \unchecked
27574+#ifdef CONFIG_PAX_REFCOUNT
27575+3:
27576+#endif
27577+.endif
27578+
27579 RESTORE ebx
27580+ pax_force_retaddr
27581 ret
27582 CFI_ENDPROC
27583-ENDPROC(atomic64_\func\()_return_cx8)
27584+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27585 .endm
27586
27587 incdec_return inc add adc
27588 incdec_return dec sub sbb
27589+incdec_return inc add adc _unchecked
27590+incdec_return dec sub sbb _unchecked
27591
27592 ENTRY(atomic64_dec_if_positive_cx8)
27593 CFI_STARTPROC
27594@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27595 movl %edx, %ecx
27596 subl $1, %ebx
27597 sbb $0, %ecx
27598+
27599+#ifdef CONFIG_PAX_REFCOUNT
27600+ into
27601+1234:
27602+ _ASM_EXTABLE(1234b, 2f)
27603+#endif
27604+
27605 js 2f
27606 LOCK_PREFIX
27607 cmpxchg8b (%esi)
27608@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27609 movl %ebx, %eax
27610 movl %ecx, %edx
27611 RESTORE ebx
27612+ pax_force_retaddr
27613 ret
27614 CFI_ENDPROC
27615 ENDPROC(atomic64_dec_if_positive_cx8)
27616@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27617 movl %edx, %ecx
27618 addl %ebp, %ebx
27619 adcl %edi, %ecx
27620+
27621+#ifdef CONFIG_PAX_REFCOUNT
27622+ into
27623+1234:
27624+ _ASM_EXTABLE(1234b, 3f)
27625+#endif
27626+
27627 LOCK_PREFIX
27628 cmpxchg8b (%esi)
27629 jne 1b
27630@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27631 CFI_ADJUST_CFA_OFFSET -8
27632 RESTORE ebx
27633 RESTORE ebp
27634+ pax_force_retaddr
27635 ret
27636 4:
27637 cmpl %edx, 4(%esp)
27638@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27639 xorl %ecx, %ecx
27640 addl $1, %ebx
27641 adcl %edx, %ecx
27642+
27643+#ifdef CONFIG_PAX_REFCOUNT
27644+ into
27645+1234:
27646+ _ASM_EXTABLE(1234b, 3f)
27647+#endif
27648+
27649 LOCK_PREFIX
27650 cmpxchg8b (%esi)
27651 jne 1b
27652@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27653 movl $1, %eax
27654 3:
27655 RESTORE ebx
27656+ pax_force_retaddr
27657 ret
27658 CFI_ENDPROC
27659 ENDPROC(atomic64_inc_not_zero_cx8)
27660diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27661index e78b8ee..7e173a8 100644
27662--- a/arch/x86/lib/checksum_32.S
27663+++ b/arch/x86/lib/checksum_32.S
27664@@ -29,7 +29,8 @@
27665 #include <asm/dwarf2.h>
27666 #include <asm/errno.h>
27667 #include <asm/asm.h>
27668-
27669+#include <asm/segment.h>
27670+
27671 /*
27672 * computes a partial checksum, e.g. for TCP/UDP fragments
27673 */
27674@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27675
27676 #define ARGBASE 16
27677 #define FP 12
27678-
27679-ENTRY(csum_partial_copy_generic)
27680+
27681+ENTRY(csum_partial_copy_generic_to_user)
27682 CFI_STARTPROC
27683+
27684+#ifdef CONFIG_PAX_MEMORY_UDEREF
27685+ pushl_cfi %gs
27686+ popl_cfi %es
27687+ jmp csum_partial_copy_generic
27688+#endif
27689+
27690+ENTRY(csum_partial_copy_generic_from_user)
27691+
27692+#ifdef CONFIG_PAX_MEMORY_UDEREF
27693+ pushl_cfi %gs
27694+ popl_cfi %ds
27695+#endif
27696+
27697+ENTRY(csum_partial_copy_generic)
27698 subl $4,%esp
27699 CFI_ADJUST_CFA_OFFSET 4
27700 pushl_cfi %edi
27701@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27702 jmp 4f
27703 SRC(1: movw (%esi), %bx )
27704 addl $2, %esi
27705-DST( movw %bx, (%edi) )
27706+DST( movw %bx, %es:(%edi) )
27707 addl $2, %edi
27708 addw %bx, %ax
27709 adcl $0, %eax
27710@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27711 SRC(1: movl (%esi), %ebx )
27712 SRC( movl 4(%esi), %edx )
27713 adcl %ebx, %eax
27714-DST( movl %ebx, (%edi) )
27715+DST( movl %ebx, %es:(%edi) )
27716 adcl %edx, %eax
27717-DST( movl %edx, 4(%edi) )
27718+DST( movl %edx, %es:4(%edi) )
27719
27720 SRC( movl 8(%esi), %ebx )
27721 SRC( movl 12(%esi), %edx )
27722 adcl %ebx, %eax
27723-DST( movl %ebx, 8(%edi) )
27724+DST( movl %ebx, %es:8(%edi) )
27725 adcl %edx, %eax
27726-DST( movl %edx, 12(%edi) )
27727+DST( movl %edx, %es:12(%edi) )
27728
27729 SRC( movl 16(%esi), %ebx )
27730 SRC( movl 20(%esi), %edx )
27731 adcl %ebx, %eax
27732-DST( movl %ebx, 16(%edi) )
27733+DST( movl %ebx, %es:16(%edi) )
27734 adcl %edx, %eax
27735-DST( movl %edx, 20(%edi) )
27736+DST( movl %edx, %es:20(%edi) )
27737
27738 SRC( movl 24(%esi), %ebx )
27739 SRC( movl 28(%esi), %edx )
27740 adcl %ebx, %eax
27741-DST( movl %ebx, 24(%edi) )
27742+DST( movl %ebx, %es:24(%edi) )
27743 adcl %edx, %eax
27744-DST( movl %edx, 28(%edi) )
27745+DST( movl %edx, %es:28(%edi) )
27746
27747 lea 32(%esi), %esi
27748 lea 32(%edi), %edi
27749@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27750 shrl $2, %edx # This clears CF
27751 SRC(3: movl (%esi), %ebx )
27752 adcl %ebx, %eax
27753-DST( movl %ebx, (%edi) )
27754+DST( movl %ebx, %es:(%edi) )
27755 lea 4(%esi), %esi
27756 lea 4(%edi), %edi
27757 dec %edx
27758@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27759 jb 5f
27760 SRC( movw (%esi), %cx )
27761 leal 2(%esi), %esi
27762-DST( movw %cx, (%edi) )
27763+DST( movw %cx, %es:(%edi) )
27764 leal 2(%edi), %edi
27765 je 6f
27766 shll $16,%ecx
27767 SRC(5: movb (%esi), %cl )
27768-DST( movb %cl, (%edi) )
27769+DST( movb %cl, %es:(%edi) )
27770 6: addl %ecx, %eax
27771 adcl $0, %eax
27772 7:
27773@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27774
27775 6001:
27776 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27777- movl $-EFAULT, (%ebx)
27778+ movl $-EFAULT, %ss:(%ebx)
27779
27780 # zero the complete destination - computing the rest
27781 # is too much work
27782@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27783
27784 6002:
27785 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27786- movl $-EFAULT,(%ebx)
27787+ movl $-EFAULT,%ss:(%ebx)
27788 jmp 5000b
27789
27790 .previous
27791
27792+ pushl_cfi %ss
27793+ popl_cfi %ds
27794+ pushl_cfi %ss
27795+ popl_cfi %es
27796 popl_cfi %ebx
27797 CFI_RESTORE ebx
27798 popl_cfi %esi
27799@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27800 popl_cfi %ecx # equivalent to addl $4,%esp
27801 ret
27802 CFI_ENDPROC
27803-ENDPROC(csum_partial_copy_generic)
27804+ENDPROC(csum_partial_copy_generic_to_user)
27805
27806 #else
27807
27808 /* Version for PentiumII/PPro */
27809
27810 #define ROUND1(x) \
27811+ nop; nop; nop; \
27812 SRC(movl x(%esi), %ebx ) ; \
27813 addl %ebx, %eax ; \
27814- DST(movl %ebx, x(%edi) ) ;
27815+ DST(movl %ebx, %es:x(%edi)) ;
27816
27817 #define ROUND(x) \
27818+ nop; nop; nop; \
27819 SRC(movl x(%esi), %ebx ) ; \
27820 adcl %ebx, %eax ; \
27821- DST(movl %ebx, x(%edi) ) ;
27822+ DST(movl %ebx, %es:x(%edi)) ;
27823
27824 #define ARGBASE 12
27825-
27826-ENTRY(csum_partial_copy_generic)
27827+
27828+ENTRY(csum_partial_copy_generic_to_user)
27829 CFI_STARTPROC
27830+
27831+#ifdef CONFIG_PAX_MEMORY_UDEREF
27832+ pushl_cfi %gs
27833+ popl_cfi %es
27834+ jmp csum_partial_copy_generic
27835+#endif
27836+
27837+ENTRY(csum_partial_copy_generic_from_user)
27838+
27839+#ifdef CONFIG_PAX_MEMORY_UDEREF
27840+ pushl_cfi %gs
27841+ popl_cfi %ds
27842+#endif
27843+
27844+ENTRY(csum_partial_copy_generic)
27845 pushl_cfi %ebx
27846 CFI_REL_OFFSET ebx, 0
27847 pushl_cfi %edi
27848@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27849 subl %ebx, %edi
27850 lea -1(%esi),%edx
27851 andl $-32,%edx
27852- lea 3f(%ebx,%ebx), %ebx
27853+ lea 3f(%ebx,%ebx,2), %ebx
27854 testl %esi, %esi
27855 jmp *%ebx
27856 1: addl $64,%esi
27857@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27858 jb 5f
27859 SRC( movw (%esi), %dx )
27860 leal 2(%esi), %esi
27861-DST( movw %dx, (%edi) )
27862+DST( movw %dx, %es:(%edi) )
27863 leal 2(%edi), %edi
27864 je 6f
27865 shll $16,%edx
27866 5:
27867 SRC( movb (%esi), %dl )
27868-DST( movb %dl, (%edi) )
27869+DST( movb %dl, %es:(%edi) )
27870 6: addl %edx, %eax
27871 adcl $0, %eax
27872 7:
27873 .section .fixup, "ax"
27874 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27875- movl $-EFAULT, (%ebx)
27876+ movl $-EFAULT, %ss:(%ebx)
27877 # zero the complete destination (computing the rest is too much work)
27878 movl ARGBASE+8(%esp),%edi # dst
27879 movl ARGBASE+12(%esp),%ecx # len
27880@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27881 rep; stosb
27882 jmp 7b
27883 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27884- movl $-EFAULT, (%ebx)
27885+ movl $-EFAULT, %ss:(%ebx)
27886 jmp 7b
27887 .previous
27888
27889+#ifdef CONFIG_PAX_MEMORY_UDEREF
27890+ pushl_cfi %ss
27891+ popl_cfi %ds
27892+ pushl_cfi %ss
27893+ popl_cfi %es
27894+#endif
27895+
27896 popl_cfi %esi
27897 CFI_RESTORE esi
27898 popl_cfi %edi
27899@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27900 CFI_RESTORE ebx
27901 ret
27902 CFI_ENDPROC
27903-ENDPROC(csum_partial_copy_generic)
27904+ENDPROC(csum_partial_copy_generic_to_user)
27905
27906 #undef ROUND
27907 #undef ROUND1
27908diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27909index f2145cf..cea889d 100644
27910--- a/arch/x86/lib/clear_page_64.S
27911+++ b/arch/x86/lib/clear_page_64.S
27912@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27913 movl $4096/8,%ecx
27914 xorl %eax,%eax
27915 rep stosq
27916+ pax_force_retaddr
27917 ret
27918 CFI_ENDPROC
27919 ENDPROC(clear_page_c)
27920@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27921 movl $4096,%ecx
27922 xorl %eax,%eax
27923 rep stosb
27924+ pax_force_retaddr
27925 ret
27926 CFI_ENDPROC
27927 ENDPROC(clear_page_c_e)
27928@@ -43,6 +45,7 @@ ENTRY(clear_page)
27929 leaq 64(%rdi),%rdi
27930 jnz .Lloop
27931 nop
27932+ pax_force_retaddr
27933 ret
27934 CFI_ENDPROC
27935 .Lclear_page_end:
27936@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27937
27938 #include <asm/cpufeature.h>
27939
27940- .section .altinstr_replacement,"ax"
27941+ .section .altinstr_replacement,"a"
27942 1: .byte 0xeb /* jmp <disp8> */
27943 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27944 2: .byte 0xeb /* jmp <disp8> */
27945diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27946index 1e572c5..2a162cd 100644
27947--- a/arch/x86/lib/cmpxchg16b_emu.S
27948+++ b/arch/x86/lib/cmpxchg16b_emu.S
27949@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27950
27951 popf
27952 mov $1, %al
27953+ pax_force_retaddr
27954 ret
27955
27956 not_same:
27957 popf
27958 xor %al,%al
27959+ pax_force_retaddr
27960 ret
27961
27962 CFI_ENDPROC
27963diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27964index 176cca6..1166c50 100644
27965--- a/arch/x86/lib/copy_page_64.S
27966+++ b/arch/x86/lib/copy_page_64.S
27967@@ -9,6 +9,7 @@ copy_page_rep:
27968 CFI_STARTPROC
27969 movl $4096/8, %ecx
27970 rep movsq
27971+ pax_force_retaddr
27972 ret
27973 CFI_ENDPROC
27974 ENDPROC(copy_page_rep)
27975@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27976
27977 ENTRY(copy_page)
27978 CFI_STARTPROC
27979- subq $2*8, %rsp
27980- CFI_ADJUST_CFA_OFFSET 2*8
27981+ subq $3*8, %rsp
27982+ CFI_ADJUST_CFA_OFFSET 3*8
27983 movq %rbx, (%rsp)
27984 CFI_REL_OFFSET rbx, 0
27985 movq %r12, 1*8(%rsp)
27986 CFI_REL_OFFSET r12, 1*8
27987+ movq %r13, 2*8(%rsp)
27988+ CFI_REL_OFFSET r13, 2*8
27989
27990 movl $(4096/64)-5, %ecx
27991 .p2align 4
27992@@ -36,7 +39,7 @@ ENTRY(copy_page)
27993 movq 0x8*2(%rsi), %rdx
27994 movq 0x8*3(%rsi), %r8
27995 movq 0x8*4(%rsi), %r9
27996- movq 0x8*5(%rsi), %r10
27997+ movq 0x8*5(%rsi), %r13
27998 movq 0x8*6(%rsi), %r11
27999 movq 0x8*7(%rsi), %r12
28000
28001@@ -47,7 +50,7 @@ ENTRY(copy_page)
28002 movq %rdx, 0x8*2(%rdi)
28003 movq %r8, 0x8*3(%rdi)
28004 movq %r9, 0x8*4(%rdi)
28005- movq %r10, 0x8*5(%rdi)
28006+ movq %r13, 0x8*5(%rdi)
28007 movq %r11, 0x8*6(%rdi)
28008 movq %r12, 0x8*7(%rdi)
28009
28010@@ -66,7 +69,7 @@ ENTRY(copy_page)
28011 movq 0x8*2(%rsi), %rdx
28012 movq 0x8*3(%rsi), %r8
28013 movq 0x8*4(%rsi), %r9
28014- movq 0x8*5(%rsi), %r10
28015+ movq 0x8*5(%rsi), %r13
28016 movq 0x8*6(%rsi), %r11
28017 movq 0x8*7(%rsi), %r12
28018
28019@@ -75,7 +78,7 @@ ENTRY(copy_page)
28020 movq %rdx, 0x8*2(%rdi)
28021 movq %r8, 0x8*3(%rdi)
28022 movq %r9, 0x8*4(%rdi)
28023- movq %r10, 0x8*5(%rdi)
28024+ movq %r13, 0x8*5(%rdi)
28025 movq %r11, 0x8*6(%rdi)
28026 movq %r12, 0x8*7(%rdi)
28027
28028@@ -87,8 +90,11 @@ ENTRY(copy_page)
28029 CFI_RESTORE rbx
28030 movq 1*8(%rsp), %r12
28031 CFI_RESTORE r12
28032- addq $2*8, %rsp
28033- CFI_ADJUST_CFA_OFFSET -2*8
28034+ movq 2*8(%rsp), %r13
28035+ CFI_RESTORE r13
28036+ addq $3*8, %rsp
28037+ CFI_ADJUST_CFA_OFFSET -3*8
28038+ pax_force_retaddr
28039 ret
28040 .Lcopy_page_end:
28041 CFI_ENDPROC
28042@@ -99,7 +105,7 @@ ENDPROC(copy_page)
28043
28044 #include <asm/cpufeature.h>
28045
28046- .section .altinstr_replacement,"ax"
28047+ .section .altinstr_replacement,"a"
28048 1: .byte 0xeb /* jmp <disp8> */
28049 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
28050 2:
28051diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
28052index a30ca15..6b3f4e1 100644
28053--- a/arch/x86/lib/copy_user_64.S
28054+++ b/arch/x86/lib/copy_user_64.S
28055@@ -18,31 +18,7 @@
28056 #include <asm/alternative-asm.h>
28057 #include <asm/asm.h>
28058 #include <asm/smap.h>
28059-
28060-/*
28061- * By placing feature2 after feature1 in altinstructions section, we logically
28062- * implement:
28063- * If CPU has feature2, jmp to alt2 is used
28064- * else if CPU has feature1, jmp to alt1 is used
28065- * else jmp to orig is used.
28066- */
28067- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
28068-0:
28069- .byte 0xe9 /* 32bit jump */
28070- .long \orig-1f /* by default jump to orig */
28071-1:
28072- .section .altinstr_replacement,"ax"
28073-2: .byte 0xe9 /* near jump with 32bit immediate */
28074- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
28075-3: .byte 0xe9 /* near jump with 32bit immediate */
28076- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
28077- .previous
28078-
28079- .section .altinstructions,"a"
28080- altinstruction_entry 0b,2b,\feature1,5,5
28081- altinstruction_entry 0b,3b,\feature2,5,5
28082- .previous
28083- .endm
28084+#include <asm/pgtable.h>
28085
28086 .macro ALIGN_DESTINATION
28087 #ifdef FIX_ALIGNMENT
28088@@ -70,52 +46,6 @@
28089 #endif
28090 .endm
28091
28092-/* Standard copy_to_user with segment limit checking */
28093-ENTRY(_copy_to_user)
28094- CFI_STARTPROC
28095- GET_THREAD_INFO(%rax)
28096- movq %rdi,%rcx
28097- addq %rdx,%rcx
28098- jc bad_to_user
28099- cmpq TI_addr_limit(%rax),%rcx
28100- ja bad_to_user
28101- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28102- copy_user_generic_unrolled,copy_user_generic_string, \
28103- copy_user_enhanced_fast_string
28104- CFI_ENDPROC
28105-ENDPROC(_copy_to_user)
28106-
28107-/* Standard copy_from_user with segment limit checking */
28108-ENTRY(_copy_from_user)
28109- CFI_STARTPROC
28110- GET_THREAD_INFO(%rax)
28111- movq %rsi,%rcx
28112- addq %rdx,%rcx
28113- jc bad_from_user
28114- cmpq TI_addr_limit(%rax),%rcx
28115- ja bad_from_user
28116- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28117- copy_user_generic_unrolled,copy_user_generic_string, \
28118- copy_user_enhanced_fast_string
28119- CFI_ENDPROC
28120-ENDPROC(_copy_from_user)
28121-
28122- .section .fixup,"ax"
28123- /* must zero dest */
28124-ENTRY(bad_from_user)
28125-bad_from_user:
28126- CFI_STARTPROC
28127- movl %edx,%ecx
28128- xorl %eax,%eax
28129- rep
28130- stosb
28131-bad_to_user:
28132- movl %edx,%eax
28133- ret
28134- CFI_ENDPROC
28135-ENDPROC(bad_from_user)
28136- .previous
28137-
28138 /*
28139 * copy_user_generic_unrolled - memory copy with exception handling.
28140 * This version is for CPUs like P4 that don't have efficient micro
28141@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
28142 */
28143 ENTRY(copy_user_generic_unrolled)
28144 CFI_STARTPROC
28145+ ASM_PAX_OPEN_USERLAND
28146 ASM_STAC
28147 cmpl $8,%edx
28148 jb 20f /* less then 8 bytes, go to byte copy loop */
28149@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
28150 jz 17f
28151 1: movq (%rsi),%r8
28152 2: movq 1*8(%rsi),%r9
28153-3: movq 2*8(%rsi),%r10
28154+3: movq 2*8(%rsi),%rax
28155 4: movq 3*8(%rsi),%r11
28156 5: movq %r8,(%rdi)
28157 6: movq %r9,1*8(%rdi)
28158-7: movq %r10,2*8(%rdi)
28159+7: movq %rax,2*8(%rdi)
28160 8: movq %r11,3*8(%rdi)
28161 9: movq 4*8(%rsi),%r8
28162 10: movq 5*8(%rsi),%r9
28163-11: movq 6*8(%rsi),%r10
28164+11: movq 6*8(%rsi),%rax
28165 12: movq 7*8(%rsi),%r11
28166 13: movq %r8,4*8(%rdi)
28167 14: movq %r9,5*8(%rdi)
28168-15: movq %r10,6*8(%rdi)
28169+15: movq %rax,6*8(%rdi)
28170 16: movq %r11,7*8(%rdi)
28171 leaq 64(%rsi),%rsi
28172 leaq 64(%rdi),%rdi
28173@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
28174 jnz 21b
28175 23: xor %eax,%eax
28176 ASM_CLAC
28177+ ASM_PAX_CLOSE_USERLAND
28178+ pax_force_retaddr
28179 ret
28180
28181 .section .fixup,"ax"
28182@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
28183 */
28184 ENTRY(copy_user_generic_string)
28185 CFI_STARTPROC
28186+ ASM_PAX_OPEN_USERLAND
28187 ASM_STAC
28188 andl %edx,%edx
28189 jz 4f
28190@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
28191 movsb
28192 4: xorl %eax,%eax
28193 ASM_CLAC
28194+ ASM_PAX_CLOSE_USERLAND
28195+ pax_force_retaddr
28196 ret
28197
28198 .section .fixup,"ax"
28199@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
28200 */
28201 ENTRY(copy_user_enhanced_fast_string)
28202 CFI_STARTPROC
28203+ ASM_PAX_OPEN_USERLAND
28204 ASM_STAC
28205 andl %edx,%edx
28206 jz 2f
28207@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
28208 movsb
28209 2: xorl %eax,%eax
28210 ASM_CLAC
28211+ ASM_PAX_CLOSE_USERLAND
28212+ pax_force_retaddr
28213 ret
28214
28215 .section .fixup,"ax"
28216diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
28217index 6a4f43c..55d26f2 100644
28218--- a/arch/x86/lib/copy_user_nocache_64.S
28219+++ b/arch/x86/lib/copy_user_nocache_64.S
28220@@ -8,6 +8,7 @@
28221
28222 #include <linux/linkage.h>
28223 #include <asm/dwarf2.h>
28224+#include <asm/alternative-asm.h>
28225
28226 #define FIX_ALIGNMENT 1
28227
28228@@ -16,6 +17,7 @@
28229 #include <asm/thread_info.h>
28230 #include <asm/asm.h>
28231 #include <asm/smap.h>
28232+#include <asm/pgtable.h>
28233
28234 .macro ALIGN_DESTINATION
28235 #ifdef FIX_ALIGNMENT
28236@@ -49,6 +51,16 @@
28237 */
28238 ENTRY(__copy_user_nocache)
28239 CFI_STARTPROC
28240+
28241+#ifdef CONFIG_PAX_MEMORY_UDEREF
28242+ mov pax_user_shadow_base,%rcx
28243+ cmp %rcx,%rsi
28244+ jae 1f
28245+ add %rcx,%rsi
28246+1:
28247+#endif
28248+
28249+ ASM_PAX_OPEN_USERLAND
28250 ASM_STAC
28251 cmpl $8,%edx
28252 jb 20f /* less then 8 bytes, go to byte copy loop */
28253@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
28254 jz 17f
28255 1: movq (%rsi),%r8
28256 2: movq 1*8(%rsi),%r9
28257-3: movq 2*8(%rsi),%r10
28258+3: movq 2*8(%rsi),%rax
28259 4: movq 3*8(%rsi),%r11
28260 5: movnti %r8,(%rdi)
28261 6: movnti %r9,1*8(%rdi)
28262-7: movnti %r10,2*8(%rdi)
28263+7: movnti %rax,2*8(%rdi)
28264 8: movnti %r11,3*8(%rdi)
28265 9: movq 4*8(%rsi),%r8
28266 10: movq 5*8(%rsi),%r9
28267-11: movq 6*8(%rsi),%r10
28268+11: movq 6*8(%rsi),%rax
28269 12: movq 7*8(%rsi),%r11
28270 13: movnti %r8,4*8(%rdi)
28271 14: movnti %r9,5*8(%rdi)
28272-15: movnti %r10,6*8(%rdi)
28273+15: movnti %rax,6*8(%rdi)
28274 16: movnti %r11,7*8(%rdi)
28275 leaq 64(%rsi),%rsi
28276 leaq 64(%rdi),%rdi
28277@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
28278 jnz 21b
28279 23: xorl %eax,%eax
28280 ASM_CLAC
28281+ ASM_PAX_CLOSE_USERLAND
28282 sfence
28283+ pax_force_retaddr
28284 ret
28285
28286 .section .fixup,"ax"
28287diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
28288index 2419d5f..953ee51 100644
28289--- a/arch/x86/lib/csum-copy_64.S
28290+++ b/arch/x86/lib/csum-copy_64.S
28291@@ -9,6 +9,7 @@
28292 #include <asm/dwarf2.h>
28293 #include <asm/errno.h>
28294 #include <asm/asm.h>
28295+#include <asm/alternative-asm.h>
28296
28297 /*
28298 * Checksum copy with exception handling.
28299@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
28300 CFI_RESTORE rbp
28301 addq $7*8, %rsp
28302 CFI_ADJUST_CFA_OFFSET -7*8
28303+ pax_force_retaddr 0, 1
28304 ret
28305 CFI_RESTORE_STATE
28306
28307diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
28308index 25b7ae8..c40113e 100644
28309--- a/arch/x86/lib/csum-wrappers_64.c
28310+++ b/arch/x86/lib/csum-wrappers_64.c
28311@@ -52,8 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
28312 len -= 2;
28313 }
28314 }
28315- isum = csum_partial_copy_generic((__force const void *)src,
28316+ pax_open_userland();
28317+ stac();
28318+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
28319 dst, len, isum, errp, NULL);
28320+ clac();
28321+ pax_close_userland();
28322 if (unlikely(*errp))
28323 goto out_err;
28324
28325@@ -105,8 +109,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
28326 }
28327
28328 *errp = 0;
28329- return csum_partial_copy_generic(src, (void __force *)dst,
28330+ pax_open_userland();
28331+ stac();
28332+ isum = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
28333 len, isum, NULL, errp);
28334+ clac();
28335+ pax_close_userland();
28336+ return isum;
28337 }
28338 EXPORT_SYMBOL(csum_partial_copy_to_user);
28339
28340diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
28341index a451235..1daa956 100644
28342--- a/arch/x86/lib/getuser.S
28343+++ b/arch/x86/lib/getuser.S
28344@@ -33,17 +33,40 @@
28345 #include <asm/thread_info.h>
28346 #include <asm/asm.h>
28347 #include <asm/smap.h>
28348+#include <asm/segment.h>
28349+#include <asm/pgtable.h>
28350+#include <asm/alternative-asm.h>
28351+
28352+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28353+#define __copyuser_seg gs;
28354+#else
28355+#define __copyuser_seg
28356+#endif
28357
28358 .text
28359 ENTRY(__get_user_1)
28360 CFI_STARTPROC
28361+
28362+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28363 GET_THREAD_INFO(%_ASM_DX)
28364 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28365 jae bad_get_user
28366 ASM_STAC
28367-1: movzbl (%_ASM_AX),%edx
28368+
28369+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28370+ mov pax_user_shadow_base,%_ASM_DX
28371+ cmp %_ASM_DX,%_ASM_AX
28372+ jae 1234f
28373+ add %_ASM_DX,%_ASM_AX
28374+1234:
28375+#endif
28376+
28377+#endif
28378+
28379+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28380 xor %eax,%eax
28381 ASM_CLAC
28382+ pax_force_retaddr
28383 ret
28384 CFI_ENDPROC
28385 ENDPROC(__get_user_1)
28386@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28387 ENTRY(__get_user_2)
28388 CFI_STARTPROC
28389 add $1,%_ASM_AX
28390+
28391+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28392 jc bad_get_user
28393 GET_THREAD_INFO(%_ASM_DX)
28394 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28395 jae bad_get_user
28396 ASM_STAC
28397-2: movzwl -1(%_ASM_AX),%edx
28398+
28399+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28400+ mov pax_user_shadow_base,%_ASM_DX
28401+ cmp %_ASM_DX,%_ASM_AX
28402+ jae 1234f
28403+ add %_ASM_DX,%_ASM_AX
28404+1234:
28405+#endif
28406+
28407+#endif
28408+
28409+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28410 xor %eax,%eax
28411 ASM_CLAC
28412+ pax_force_retaddr
28413 ret
28414 CFI_ENDPROC
28415 ENDPROC(__get_user_2)
28416@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
28417 ENTRY(__get_user_4)
28418 CFI_STARTPROC
28419 add $3,%_ASM_AX
28420+
28421+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28422 jc bad_get_user
28423 GET_THREAD_INFO(%_ASM_DX)
28424 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28425 jae bad_get_user
28426 ASM_STAC
28427-3: movl -3(%_ASM_AX),%edx
28428+
28429+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28430+ mov pax_user_shadow_base,%_ASM_DX
28431+ cmp %_ASM_DX,%_ASM_AX
28432+ jae 1234f
28433+ add %_ASM_DX,%_ASM_AX
28434+1234:
28435+#endif
28436+
28437+#endif
28438+
28439+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28440 xor %eax,%eax
28441 ASM_CLAC
28442+ pax_force_retaddr
28443 ret
28444 CFI_ENDPROC
28445 ENDPROC(__get_user_4)
28446@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28447 GET_THREAD_INFO(%_ASM_DX)
28448 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28449 jae bad_get_user
28450+
28451+#ifdef CONFIG_PAX_MEMORY_UDEREF
28452+ mov pax_user_shadow_base,%_ASM_DX
28453+ cmp %_ASM_DX,%_ASM_AX
28454+ jae 1234f
28455+ add %_ASM_DX,%_ASM_AX
28456+1234:
28457+#endif
28458+
28459 ASM_STAC
28460 4: movq -7(%_ASM_AX),%rdx
28461 xor %eax,%eax
28462 ASM_CLAC
28463+ pax_force_retaddr
28464 ret
28465 #else
28466 add $7,%_ASM_AX
28467@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28468 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28469 jae bad_get_user_8
28470 ASM_STAC
28471-4: movl -7(%_ASM_AX),%edx
28472-5: movl -3(%_ASM_AX),%ecx
28473+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28474+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28475 xor %eax,%eax
28476 ASM_CLAC
28477+ pax_force_retaddr
28478 ret
28479 #endif
28480 CFI_ENDPROC
28481@@ -113,6 +175,7 @@ bad_get_user:
28482 xor %edx,%edx
28483 mov $(-EFAULT),%_ASM_AX
28484 ASM_CLAC
28485+ pax_force_retaddr
28486 ret
28487 CFI_ENDPROC
28488 END(bad_get_user)
28489@@ -124,6 +187,7 @@ bad_get_user_8:
28490 xor %ecx,%ecx
28491 mov $(-EFAULT),%_ASM_AX
28492 ASM_CLAC
28493+ pax_force_retaddr
28494 ret
28495 CFI_ENDPROC
28496 END(bad_get_user_8)
28497diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28498index 54fcffe..7be149e 100644
28499--- a/arch/x86/lib/insn.c
28500+++ b/arch/x86/lib/insn.c
28501@@ -20,8 +20,10 @@
28502
28503 #ifdef __KERNEL__
28504 #include <linux/string.h>
28505+#include <asm/pgtable_types.h>
28506 #else
28507 #include <string.h>
28508+#define ktla_ktva(addr) addr
28509 #endif
28510 #include <asm/inat.h>
28511 #include <asm/insn.h>
28512@@ -53,8 +55,8 @@
28513 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28514 {
28515 memset(insn, 0, sizeof(*insn));
28516- insn->kaddr = kaddr;
28517- insn->next_byte = kaddr;
28518+ insn->kaddr = ktla_ktva(kaddr);
28519+ insn->next_byte = ktla_ktva(kaddr);
28520 insn->x86_64 = x86_64 ? 1 : 0;
28521 insn->opnd_bytes = 4;
28522 if (x86_64)
28523diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28524index 05a95e7..326f2fa 100644
28525--- a/arch/x86/lib/iomap_copy_64.S
28526+++ b/arch/x86/lib/iomap_copy_64.S
28527@@ -17,6 +17,7 @@
28528
28529 #include <linux/linkage.h>
28530 #include <asm/dwarf2.h>
28531+#include <asm/alternative-asm.h>
28532
28533 /*
28534 * override generic version in lib/iomap_copy.c
28535@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28536 CFI_STARTPROC
28537 movl %edx,%ecx
28538 rep movsd
28539+ pax_force_retaddr
28540 ret
28541 CFI_ENDPROC
28542 ENDPROC(__iowrite32_copy)
28543diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28544index 56313a3..9b59269 100644
28545--- a/arch/x86/lib/memcpy_64.S
28546+++ b/arch/x86/lib/memcpy_64.S
28547@@ -24,7 +24,7 @@
28548 * This gets patched over the unrolled variant (below) via the
28549 * alternative instructions framework:
28550 */
28551- .section .altinstr_replacement, "ax", @progbits
28552+ .section .altinstr_replacement, "a", @progbits
28553 .Lmemcpy_c:
28554 movq %rdi, %rax
28555 movq %rdx, %rcx
28556@@ -33,6 +33,7 @@
28557 rep movsq
28558 movl %edx, %ecx
28559 rep movsb
28560+ pax_force_retaddr
28561 ret
28562 .Lmemcpy_e:
28563 .previous
28564@@ -44,11 +45,12 @@
28565 * This gets patched over the unrolled variant (below) via the
28566 * alternative instructions framework:
28567 */
28568- .section .altinstr_replacement, "ax", @progbits
28569+ .section .altinstr_replacement, "a", @progbits
28570 .Lmemcpy_c_e:
28571 movq %rdi, %rax
28572 movq %rdx, %rcx
28573 rep movsb
28574+ pax_force_retaddr
28575 ret
28576 .Lmemcpy_e_e:
28577 .previous
28578@@ -76,13 +78,13 @@ ENTRY(memcpy)
28579 */
28580 movq 0*8(%rsi), %r8
28581 movq 1*8(%rsi), %r9
28582- movq 2*8(%rsi), %r10
28583+ movq 2*8(%rsi), %rcx
28584 movq 3*8(%rsi), %r11
28585 leaq 4*8(%rsi), %rsi
28586
28587 movq %r8, 0*8(%rdi)
28588 movq %r9, 1*8(%rdi)
28589- movq %r10, 2*8(%rdi)
28590+ movq %rcx, 2*8(%rdi)
28591 movq %r11, 3*8(%rdi)
28592 leaq 4*8(%rdi), %rdi
28593 jae .Lcopy_forward_loop
28594@@ -105,12 +107,12 @@ ENTRY(memcpy)
28595 subq $0x20, %rdx
28596 movq -1*8(%rsi), %r8
28597 movq -2*8(%rsi), %r9
28598- movq -3*8(%rsi), %r10
28599+ movq -3*8(%rsi), %rcx
28600 movq -4*8(%rsi), %r11
28601 leaq -4*8(%rsi), %rsi
28602 movq %r8, -1*8(%rdi)
28603 movq %r9, -2*8(%rdi)
28604- movq %r10, -3*8(%rdi)
28605+ movq %rcx, -3*8(%rdi)
28606 movq %r11, -4*8(%rdi)
28607 leaq -4*8(%rdi), %rdi
28608 jae .Lcopy_backward_loop
28609@@ -130,12 +132,13 @@ ENTRY(memcpy)
28610 */
28611 movq 0*8(%rsi), %r8
28612 movq 1*8(%rsi), %r9
28613- movq -2*8(%rsi, %rdx), %r10
28614+ movq -2*8(%rsi, %rdx), %rcx
28615 movq -1*8(%rsi, %rdx), %r11
28616 movq %r8, 0*8(%rdi)
28617 movq %r9, 1*8(%rdi)
28618- movq %r10, -2*8(%rdi, %rdx)
28619+ movq %rcx, -2*8(%rdi, %rdx)
28620 movq %r11, -1*8(%rdi, %rdx)
28621+ pax_force_retaddr
28622 retq
28623 .p2align 4
28624 .Lless_16bytes:
28625@@ -148,6 +151,7 @@ ENTRY(memcpy)
28626 movq -1*8(%rsi, %rdx), %r9
28627 movq %r8, 0*8(%rdi)
28628 movq %r9, -1*8(%rdi, %rdx)
28629+ pax_force_retaddr
28630 retq
28631 .p2align 4
28632 .Lless_8bytes:
28633@@ -161,6 +165,7 @@ ENTRY(memcpy)
28634 movl -4(%rsi, %rdx), %r8d
28635 movl %ecx, (%rdi)
28636 movl %r8d, -4(%rdi, %rdx)
28637+ pax_force_retaddr
28638 retq
28639 .p2align 4
28640 .Lless_3bytes:
28641@@ -179,6 +184,7 @@ ENTRY(memcpy)
28642 movb %cl, (%rdi)
28643
28644 .Lend:
28645+ pax_force_retaddr
28646 retq
28647 CFI_ENDPROC
28648 ENDPROC(memcpy)
28649diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28650index 65268a6..5aa7815 100644
28651--- a/arch/x86/lib/memmove_64.S
28652+++ b/arch/x86/lib/memmove_64.S
28653@@ -61,13 +61,13 @@ ENTRY(memmove)
28654 5:
28655 sub $0x20, %rdx
28656 movq 0*8(%rsi), %r11
28657- movq 1*8(%rsi), %r10
28658+ movq 1*8(%rsi), %rcx
28659 movq 2*8(%rsi), %r9
28660 movq 3*8(%rsi), %r8
28661 leaq 4*8(%rsi), %rsi
28662
28663 movq %r11, 0*8(%rdi)
28664- movq %r10, 1*8(%rdi)
28665+ movq %rcx, 1*8(%rdi)
28666 movq %r9, 2*8(%rdi)
28667 movq %r8, 3*8(%rdi)
28668 leaq 4*8(%rdi), %rdi
28669@@ -81,10 +81,10 @@ ENTRY(memmove)
28670 4:
28671 movq %rdx, %rcx
28672 movq -8(%rsi, %rdx), %r11
28673- lea -8(%rdi, %rdx), %r10
28674+ lea -8(%rdi, %rdx), %r9
28675 shrq $3, %rcx
28676 rep movsq
28677- movq %r11, (%r10)
28678+ movq %r11, (%r9)
28679 jmp 13f
28680 .Lmemmove_end_forward:
28681
28682@@ -95,14 +95,14 @@ ENTRY(memmove)
28683 7:
28684 movq %rdx, %rcx
28685 movq (%rsi), %r11
28686- movq %rdi, %r10
28687+ movq %rdi, %r9
28688 leaq -8(%rsi, %rdx), %rsi
28689 leaq -8(%rdi, %rdx), %rdi
28690 shrq $3, %rcx
28691 std
28692 rep movsq
28693 cld
28694- movq %r11, (%r10)
28695+ movq %r11, (%r9)
28696 jmp 13f
28697
28698 /*
28699@@ -127,13 +127,13 @@ ENTRY(memmove)
28700 8:
28701 subq $0x20, %rdx
28702 movq -1*8(%rsi), %r11
28703- movq -2*8(%rsi), %r10
28704+ movq -2*8(%rsi), %rcx
28705 movq -3*8(%rsi), %r9
28706 movq -4*8(%rsi), %r8
28707 leaq -4*8(%rsi), %rsi
28708
28709 movq %r11, -1*8(%rdi)
28710- movq %r10, -2*8(%rdi)
28711+ movq %rcx, -2*8(%rdi)
28712 movq %r9, -3*8(%rdi)
28713 movq %r8, -4*8(%rdi)
28714 leaq -4*8(%rdi), %rdi
28715@@ -151,11 +151,11 @@ ENTRY(memmove)
28716 * Move data from 16 bytes to 31 bytes.
28717 */
28718 movq 0*8(%rsi), %r11
28719- movq 1*8(%rsi), %r10
28720+ movq 1*8(%rsi), %rcx
28721 movq -2*8(%rsi, %rdx), %r9
28722 movq -1*8(%rsi, %rdx), %r8
28723 movq %r11, 0*8(%rdi)
28724- movq %r10, 1*8(%rdi)
28725+ movq %rcx, 1*8(%rdi)
28726 movq %r9, -2*8(%rdi, %rdx)
28727 movq %r8, -1*8(%rdi, %rdx)
28728 jmp 13f
28729@@ -167,9 +167,9 @@ ENTRY(memmove)
28730 * Move data from 8 bytes to 15 bytes.
28731 */
28732 movq 0*8(%rsi), %r11
28733- movq -1*8(%rsi, %rdx), %r10
28734+ movq -1*8(%rsi, %rdx), %r9
28735 movq %r11, 0*8(%rdi)
28736- movq %r10, -1*8(%rdi, %rdx)
28737+ movq %r9, -1*8(%rdi, %rdx)
28738 jmp 13f
28739 10:
28740 cmpq $4, %rdx
28741@@ -178,9 +178,9 @@ ENTRY(memmove)
28742 * Move data from 4 bytes to 7 bytes.
28743 */
28744 movl (%rsi), %r11d
28745- movl -4(%rsi, %rdx), %r10d
28746+ movl -4(%rsi, %rdx), %r9d
28747 movl %r11d, (%rdi)
28748- movl %r10d, -4(%rdi, %rdx)
28749+ movl %r9d, -4(%rdi, %rdx)
28750 jmp 13f
28751 11:
28752 cmp $2, %rdx
28753@@ -189,9 +189,9 @@ ENTRY(memmove)
28754 * Move data from 2 bytes to 3 bytes.
28755 */
28756 movw (%rsi), %r11w
28757- movw -2(%rsi, %rdx), %r10w
28758+ movw -2(%rsi, %rdx), %r9w
28759 movw %r11w, (%rdi)
28760- movw %r10w, -2(%rdi, %rdx)
28761+ movw %r9w, -2(%rdi, %rdx)
28762 jmp 13f
28763 12:
28764 cmp $1, %rdx
28765@@ -202,14 +202,16 @@ ENTRY(memmove)
28766 movb (%rsi), %r11b
28767 movb %r11b, (%rdi)
28768 13:
28769+ pax_force_retaddr
28770 retq
28771 CFI_ENDPROC
28772
28773- .section .altinstr_replacement,"ax"
28774+ .section .altinstr_replacement,"a"
28775 .Lmemmove_begin_forward_efs:
28776 /* Forward moving data. */
28777 movq %rdx, %rcx
28778 rep movsb
28779+ pax_force_retaddr
28780 retq
28781 .Lmemmove_end_forward_efs:
28782 .previous
28783diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28784index 2dcb380..50a78bc 100644
28785--- a/arch/x86/lib/memset_64.S
28786+++ b/arch/x86/lib/memset_64.S
28787@@ -16,7 +16,7 @@
28788 *
28789 * rax original destination
28790 */
28791- .section .altinstr_replacement, "ax", @progbits
28792+ .section .altinstr_replacement, "a", @progbits
28793 .Lmemset_c:
28794 movq %rdi,%r9
28795 movq %rdx,%rcx
28796@@ -30,6 +30,7 @@
28797 movl %edx,%ecx
28798 rep stosb
28799 movq %r9,%rax
28800+ pax_force_retaddr
28801 ret
28802 .Lmemset_e:
28803 .previous
28804@@ -45,13 +46,14 @@
28805 *
28806 * rax original destination
28807 */
28808- .section .altinstr_replacement, "ax", @progbits
28809+ .section .altinstr_replacement, "a", @progbits
28810 .Lmemset_c_e:
28811 movq %rdi,%r9
28812 movb %sil,%al
28813 movq %rdx,%rcx
28814 rep stosb
28815 movq %r9,%rax
28816+ pax_force_retaddr
28817 ret
28818 .Lmemset_e_e:
28819 .previous
28820@@ -59,7 +61,7 @@
28821 ENTRY(memset)
28822 ENTRY(__memset)
28823 CFI_STARTPROC
28824- movq %rdi,%r10
28825+ movq %rdi,%r11
28826
28827 /* expand byte value */
28828 movzbl %sil,%ecx
28829@@ -117,7 +119,8 @@ ENTRY(__memset)
28830 jnz .Lloop_1
28831
28832 .Lende:
28833- movq %r10,%rax
28834+ movq %r11,%rax
28835+ pax_force_retaddr
28836 ret
28837
28838 CFI_RESTORE_STATE
28839diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28840index c9f2d9b..e7fd2c0 100644
28841--- a/arch/x86/lib/mmx_32.c
28842+++ b/arch/x86/lib/mmx_32.c
28843@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28844 {
28845 void *p;
28846 int i;
28847+ unsigned long cr0;
28848
28849 if (unlikely(in_interrupt()))
28850 return __memcpy(to, from, len);
28851@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28852 kernel_fpu_begin();
28853
28854 __asm__ __volatile__ (
28855- "1: prefetch (%0)\n" /* This set is 28 bytes */
28856- " prefetch 64(%0)\n"
28857- " prefetch 128(%0)\n"
28858- " prefetch 192(%0)\n"
28859- " prefetch 256(%0)\n"
28860+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28861+ " prefetch 64(%1)\n"
28862+ " prefetch 128(%1)\n"
28863+ " prefetch 192(%1)\n"
28864+ " prefetch 256(%1)\n"
28865 "2: \n"
28866 ".section .fixup, \"ax\"\n"
28867- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28868+ "3: \n"
28869+
28870+#ifdef CONFIG_PAX_KERNEXEC
28871+ " movl %%cr0, %0\n"
28872+ " movl %0, %%eax\n"
28873+ " andl $0xFFFEFFFF, %%eax\n"
28874+ " movl %%eax, %%cr0\n"
28875+#endif
28876+
28877+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28878+
28879+#ifdef CONFIG_PAX_KERNEXEC
28880+ " movl %0, %%cr0\n"
28881+#endif
28882+
28883 " jmp 2b\n"
28884 ".previous\n"
28885 _ASM_EXTABLE(1b, 3b)
28886- : : "r" (from));
28887+ : "=&r" (cr0) : "r" (from) : "ax");
28888
28889 for ( ; i > 5; i--) {
28890 __asm__ __volatile__ (
28891- "1: prefetch 320(%0)\n"
28892- "2: movq (%0), %%mm0\n"
28893- " movq 8(%0), %%mm1\n"
28894- " movq 16(%0), %%mm2\n"
28895- " movq 24(%0), %%mm3\n"
28896- " movq %%mm0, (%1)\n"
28897- " movq %%mm1, 8(%1)\n"
28898- " movq %%mm2, 16(%1)\n"
28899- " movq %%mm3, 24(%1)\n"
28900- " movq 32(%0), %%mm0\n"
28901- " movq 40(%0), %%mm1\n"
28902- " movq 48(%0), %%mm2\n"
28903- " movq 56(%0), %%mm3\n"
28904- " movq %%mm0, 32(%1)\n"
28905- " movq %%mm1, 40(%1)\n"
28906- " movq %%mm2, 48(%1)\n"
28907- " movq %%mm3, 56(%1)\n"
28908+ "1: prefetch 320(%1)\n"
28909+ "2: movq (%1), %%mm0\n"
28910+ " movq 8(%1), %%mm1\n"
28911+ " movq 16(%1), %%mm2\n"
28912+ " movq 24(%1), %%mm3\n"
28913+ " movq %%mm0, (%2)\n"
28914+ " movq %%mm1, 8(%2)\n"
28915+ " movq %%mm2, 16(%2)\n"
28916+ " movq %%mm3, 24(%2)\n"
28917+ " movq 32(%1), %%mm0\n"
28918+ " movq 40(%1), %%mm1\n"
28919+ " movq 48(%1), %%mm2\n"
28920+ " movq 56(%1), %%mm3\n"
28921+ " movq %%mm0, 32(%2)\n"
28922+ " movq %%mm1, 40(%2)\n"
28923+ " movq %%mm2, 48(%2)\n"
28924+ " movq %%mm3, 56(%2)\n"
28925 ".section .fixup, \"ax\"\n"
28926- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28927+ "3:\n"
28928+
28929+#ifdef CONFIG_PAX_KERNEXEC
28930+ " movl %%cr0, %0\n"
28931+ " movl %0, %%eax\n"
28932+ " andl $0xFFFEFFFF, %%eax\n"
28933+ " movl %%eax, %%cr0\n"
28934+#endif
28935+
28936+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28937+
28938+#ifdef CONFIG_PAX_KERNEXEC
28939+ " movl %0, %%cr0\n"
28940+#endif
28941+
28942 " jmp 2b\n"
28943 ".previous\n"
28944 _ASM_EXTABLE(1b, 3b)
28945- : : "r" (from), "r" (to) : "memory");
28946+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28947
28948 from += 64;
28949 to += 64;
28950@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28951 static void fast_copy_page(void *to, void *from)
28952 {
28953 int i;
28954+ unsigned long cr0;
28955
28956 kernel_fpu_begin();
28957
28958@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28959 * but that is for later. -AV
28960 */
28961 __asm__ __volatile__(
28962- "1: prefetch (%0)\n"
28963- " prefetch 64(%0)\n"
28964- " prefetch 128(%0)\n"
28965- " prefetch 192(%0)\n"
28966- " prefetch 256(%0)\n"
28967+ "1: prefetch (%1)\n"
28968+ " prefetch 64(%1)\n"
28969+ " prefetch 128(%1)\n"
28970+ " prefetch 192(%1)\n"
28971+ " prefetch 256(%1)\n"
28972 "2: \n"
28973 ".section .fixup, \"ax\"\n"
28974- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28975+ "3: \n"
28976+
28977+#ifdef CONFIG_PAX_KERNEXEC
28978+ " movl %%cr0, %0\n"
28979+ " movl %0, %%eax\n"
28980+ " andl $0xFFFEFFFF, %%eax\n"
28981+ " movl %%eax, %%cr0\n"
28982+#endif
28983+
28984+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28985+
28986+#ifdef CONFIG_PAX_KERNEXEC
28987+ " movl %0, %%cr0\n"
28988+#endif
28989+
28990 " jmp 2b\n"
28991 ".previous\n"
28992- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28993+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28994
28995 for (i = 0; i < (4096-320)/64; i++) {
28996 __asm__ __volatile__ (
28997- "1: prefetch 320(%0)\n"
28998- "2: movq (%0), %%mm0\n"
28999- " movntq %%mm0, (%1)\n"
29000- " movq 8(%0), %%mm1\n"
29001- " movntq %%mm1, 8(%1)\n"
29002- " movq 16(%0), %%mm2\n"
29003- " movntq %%mm2, 16(%1)\n"
29004- " movq 24(%0), %%mm3\n"
29005- " movntq %%mm3, 24(%1)\n"
29006- " movq 32(%0), %%mm4\n"
29007- " movntq %%mm4, 32(%1)\n"
29008- " movq 40(%0), %%mm5\n"
29009- " movntq %%mm5, 40(%1)\n"
29010- " movq 48(%0), %%mm6\n"
29011- " movntq %%mm6, 48(%1)\n"
29012- " movq 56(%0), %%mm7\n"
29013- " movntq %%mm7, 56(%1)\n"
29014+ "1: prefetch 320(%1)\n"
29015+ "2: movq (%1), %%mm0\n"
29016+ " movntq %%mm0, (%2)\n"
29017+ " movq 8(%1), %%mm1\n"
29018+ " movntq %%mm1, 8(%2)\n"
29019+ " movq 16(%1), %%mm2\n"
29020+ " movntq %%mm2, 16(%2)\n"
29021+ " movq 24(%1), %%mm3\n"
29022+ " movntq %%mm3, 24(%2)\n"
29023+ " movq 32(%1), %%mm4\n"
29024+ " movntq %%mm4, 32(%2)\n"
29025+ " movq 40(%1), %%mm5\n"
29026+ " movntq %%mm5, 40(%2)\n"
29027+ " movq 48(%1), %%mm6\n"
29028+ " movntq %%mm6, 48(%2)\n"
29029+ " movq 56(%1), %%mm7\n"
29030+ " movntq %%mm7, 56(%2)\n"
29031 ".section .fixup, \"ax\"\n"
29032- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29033+ "3:\n"
29034+
29035+#ifdef CONFIG_PAX_KERNEXEC
29036+ " movl %%cr0, %0\n"
29037+ " movl %0, %%eax\n"
29038+ " andl $0xFFFEFFFF, %%eax\n"
29039+ " movl %%eax, %%cr0\n"
29040+#endif
29041+
29042+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29043+
29044+#ifdef CONFIG_PAX_KERNEXEC
29045+ " movl %0, %%cr0\n"
29046+#endif
29047+
29048 " jmp 2b\n"
29049 ".previous\n"
29050- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
29051+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29052
29053 from += 64;
29054 to += 64;
29055@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
29056 static void fast_copy_page(void *to, void *from)
29057 {
29058 int i;
29059+ unsigned long cr0;
29060
29061 kernel_fpu_begin();
29062
29063 __asm__ __volatile__ (
29064- "1: prefetch (%0)\n"
29065- " prefetch 64(%0)\n"
29066- " prefetch 128(%0)\n"
29067- " prefetch 192(%0)\n"
29068- " prefetch 256(%0)\n"
29069+ "1: prefetch (%1)\n"
29070+ " prefetch 64(%1)\n"
29071+ " prefetch 128(%1)\n"
29072+ " prefetch 192(%1)\n"
29073+ " prefetch 256(%1)\n"
29074 "2: \n"
29075 ".section .fixup, \"ax\"\n"
29076- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29077+ "3: \n"
29078+
29079+#ifdef CONFIG_PAX_KERNEXEC
29080+ " movl %%cr0, %0\n"
29081+ " movl %0, %%eax\n"
29082+ " andl $0xFFFEFFFF, %%eax\n"
29083+ " movl %%eax, %%cr0\n"
29084+#endif
29085+
29086+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29087+
29088+#ifdef CONFIG_PAX_KERNEXEC
29089+ " movl %0, %%cr0\n"
29090+#endif
29091+
29092 " jmp 2b\n"
29093 ".previous\n"
29094- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29095+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29096
29097 for (i = 0; i < 4096/64; i++) {
29098 __asm__ __volatile__ (
29099- "1: prefetch 320(%0)\n"
29100- "2: movq (%0), %%mm0\n"
29101- " movq 8(%0), %%mm1\n"
29102- " movq 16(%0), %%mm2\n"
29103- " movq 24(%0), %%mm3\n"
29104- " movq %%mm0, (%1)\n"
29105- " movq %%mm1, 8(%1)\n"
29106- " movq %%mm2, 16(%1)\n"
29107- " movq %%mm3, 24(%1)\n"
29108- " movq 32(%0), %%mm0\n"
29109- " movq 40(%0), %%mm1\n"
29110- " movq 48(%0), %%mm2\n"
29111- " movq 56(%0), %%mm3\n"
29112- " movq %%mm0, 32(%1)\n"
29113- " movq %%mm1, 40(%1)\n"
29114- " movq %%mm2, 48(%1)\n"
29115- " movq %%mm3, 56(%1)\n"
29116+ "1: prefetch 320(%1)\n"
29117+ "2: movq (%1), %%mm0\n"
29118+ " movq 8(%1), %%mm1\n"
29119+ " movq 16(%1), %%mm2\n"
29120+ " movq 24(%1), %%mm3\n"
29121+ " movq %%mm0, (%2)\n"
29122+ " movq %%mm1, 8(%2)\n"
29123+ " movq %%mm2, 16(%2)\n"
29124+ " movq %%mm3, 24(%2)\n"
29125+ " movq 32(%1), %%mm0\n"
29126+ " movq 40(%1), %%mm1\n"
29127+ " movq 48(%1), %%mm2\n"
29128+ " movq 56(%1), %%mm3\n"
29129+ " movq %%mm0, 32(%2)\n"
29130+ " movq %%mm1, 40(%2)\n"
29131+ " movq %%mm2, 48(%2)\n"
29132+ " movq %%mm3, 56(%2)\n"
29133 ".section .fixup, \"ax\"\n"
29134- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29135+ "3:\n"
29136+
29137+#ifdef CONFIG_PAX_KERNEXEC
29138+ " movl %%cr0, %0\n"
29139+ " movl %0, %%eax\n"
29140+ " andl $0xFFFEFFFF, %%eax\n"
29141+ " movl %%eax, %%cr0\n"
29142+#endif
29143+
29144+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29145+
29146+#ifdef CONFIG_PAX_KERNEXEC
29147+ " movl %0, %%cr0\n"
29148+#endif
29149+
29150 " jmp 2b\n"
29151 ".previous\n"
29152 _ASM_EXTABLE(1b, 3b)
29153- : : "r" (from), "r" (to) : "memory");
29154+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29155
29156 from += 64;
29157 to += 64;
29158diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
29159index f6d13ee..aca5f0b 100644
29160--- a/arch/x86/lib/msr-reg.S
29161+++ b/arch/x86/lib/msr-reg.S
29162@@ -3,6 +3,7 @@
29163 #include <asm/dwarf2.h>
29164 #include <asm/asm.h>
29165 #include <asm/msr.h>
29166+#include <asm/alternative-asm.h>
29167
29168 #ifdef CONFIG_X86_64
29169 /*
29170@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
29171 CFI_STARTPROC
29172 pushq_cfi %rbx
29173 pushq_cfi %rbp
29174- movq %rdi, %r10 /* Save pointer */
29175+ movq %rdi, %r9 /* Save pointer */
29176 xorl %r11d, %r11d /* Return value */
29177 movl (%rdi), %eax
29178 movl 4(%rdi), %ecx
29179@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
29180 movl 28(%rdi), %edi
29181 CFI_REMEMBER_STATE
29182 1: \op
29183-2: movl %eax, (%r10)
29184+2: movl %eax, (%r9)
29185 movl %r11d, %eax /* Return value */
29186- movl %ecx, 4(%r10)
29187- movl %edx, 8(%r10)
29188- movl %ebx, 12(%r10)
29189- movl %ebp, 20(%r10)
29190- movl %esi, 24(%r10)
29191- movl %edi, 28(%r10)
29192+ movl %ecx, 4(%r9)
29193+ movl %edx, 8(%r9)
29194+ movl %ebx, 12(%r9)
29195+ movl %ebp, 20(%r9)
29196+ movl %esi, 24(%r9)
29197+ movl %edi, 28(%r9)
29198 popq_cfi %rbp
29199 popq_cfi %rbx
29200+ pax_force_retaddr
29201 ret
29202 3:
29203 CFI_RESTORE_STATE
29204diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
29205index fc6ba17..d4d989d 100644
29206--- a/arch/x86/lib/putuser.S
29207+++ b/arch/x86/lib/putuser.S
29208@@ -16,7 +16,9 @@
29209 #include <asm/errno.h>
29210 #include <asm/asm.h>
29211 #include <asm/smap.h>
29212-
29213+#include <asm/segment.h>
29214+#include <asm/pgtable.h>
29215+#include <asm/alternative-asm.h>
29216
29217 /*
29218 * __put_user_X
29219@@ -30,57 +32,125 @@
29220 * as they get called from within inline assembly.
29221 */
29222
29223-#define ENTER CFI_STARTPROC ; \
29224- GET_THREAD_INFO(%_ASM_BX)
29225-#define EXIT ASM_CLAC ; \
29226- ret ; \
29227+#define ENTER CFI_STARTPROC
29228+#define EXIT ASM_CLAC ; \
29229+ pax_force_retaddr ; \
29230+ ret ; \
29231 CFI_ENDPROC
29232
29233+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29234+#define _DEST %_ASM_CX,%_ASM_BX
29235+#else
29236+#define _DEST %_ASM_CX
29237+#endif
29238+
29239+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29240+#define __copyuser_seg gs;
29241+#else
29242+#define __copyuser_seg
29243+#endif
29244+
29245 .text
29246 ENTRY(__put_user_1)
29247 ENTER
29248+
29249+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29250+ GET_THREAD_INFO(%_ASM_BX)
29251 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
29252 jae bad_put_user
29253 ASM_STAC
29254-1: movb %al,(%_ASM_CX)
29255+
29256+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29257+ mov pax_user_shadow_base,%_ASM_BX
29258+ cmp %_ASM_BX,%_ASM_CX
29259+ jb 1234f
29260+ xor %ebx,%ebx
29261+1234:
29262+#endif
29263+
29264+#endif
29265+
29266+1: __copyuser_seg movb %al,(_DEST)
29267 xor %eax,%eax
29268 EXIT
29269 ENDPROC(__put_user_1)
29270
29271 ENTRY(__put_user_2)
29272 ENTER
29273+
29274+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29275+ GET_THREAD_INFO(%_ASM_BX)
29276 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29277 sub $1,%_ASM_BX
29278 cmp %_ASM_BX,%_ASM_CX
29279 jae bad_put_user
29280 ASM_STAC
29281-2: movw %ax,(%_ASM_CX)
29282+
29283+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29284+ mov pax_user_shadow_base,%_ASM_BX
29285+ cmp %_ASM_BX,%_ASM_CX
29286+ jb 1234f
29287+ xor %ebx,%ebx
29288+1234:
29289+#endif
29290+
29291+#endif
29292+
29293+2: __copyuser_seg movw %ax,(_DEST)
29294 xor %eax,%eax
29295 EXIT
29296 ENDPROC(__put_user_2)
29297
29298 ENTRY(__put_user_4)
29299 ENTER
29300+
29301+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29302+ GET_THREAD_INFO(%_ASM_BX)
29303 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29304 sub $3,%_ASM_BX
29305 cmp %_ASM_BX,%_ASM_CX
29306 jae bad_put_user
29307 ASM_STAC
29308-3: movl %eax,(%_ASM_CX)
29309+
29310+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29311+ mov pax_user_shadow_base,%_ASM_BX
29312+ cmp %_ASM_BX,%_ASM_CX
29313+ jb 1234f
29314+ xor %ebx,%ebx
29315+1234:
29316+#endif
29317+
29318+#endif
29319+
29320+3: __copyuser_seg movl %eax,(_DEST)
29321 xor %eax,%eax
29322 EXIT
29323 ENDPROC(__put_user_4)
29324
29325 ENTRY(__put_user_8)
29326 ENTER
29327+
29328+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29329+ GET_THREAD_INFO(%_ASM_BX)
29330 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29331 sub $7,%_ASM_BX
29332 cmp %_ASM_BX,%_ASM_CX
29333 jae bad_put_user
29334 ASM_STAC
29335-4: mov %_ASM_AX,(%_ASM_CX)
29336+
29337+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29338+ mov pax_user_shadow_base,%_ASM_BX
29339+ cmp %_ASM_BX,%_ASM_CX
29340+ jb 1234f
29341+ xor %ebx,%ebx
29342+1234:
29343+#endif
29344+
29345+#endif
29346+
29347+4: __copyuser_seg mov %_ASM_AX,(_DEST)
29348 #ifdef CONFIG_X86_32
29349-5: movl %edx,4(%_ASM_CX)
29350+5: __copyuser_seg movl %edx,4(_DEST)
29351 #endif
29352 xor %eax,%eax
29353 EXIT
29354diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29355index 1cad221..de671ee 100644
29356--- a/arch/x86/lib/rwlock.S
29357+++ b/arch/x86/lib/rwlock.S
29358@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29359 FRAME
29360 0: LOCK_PREFIX
29361 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29362+
29363+#ifdef CONFIG_PAX_REFCOUNT
29364+ jno 1234f
29365+ LOCK_PREFIX
29366+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29367+ int $4
29368+1234:
29369+ _ASM_EXTABLE(1234b, 1234b)
29370+#endif
29371+
29372 1: rep; nop
29373 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29374 jne 1b
29375 LOCK_PREFIX
29376 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29377+
29378+#ifdef CONFIG_PAX_REFCOUNT
29379+ jno 1234f
29380+ LOCK_PREFIX
29381+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29382+ int $4
29383+1234:
29384+ _ASM_EXTABLE(1234b, 1234b)
29385+#endif
29386+
29387 jnz 0b
29388 ENDFRAME
29389+ pax_force_retaddr
29390 ret
29391 CFI_ENDPROC
29392 END(__write_lock_failed)
29393@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29394 FRAME
29395 0: LOCK_PREFIX
29396 READ_LOCK_SIZE(inc) (%__lock_ptr)
29397+
29398+#ifdef CONFIG_PAX_REFCOUNT
29399+ jno 1234f
29400+ LOCK_PREFIX
29401+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29402+ int $4
29403+1234:
29404+ _ASM_EXTABLE(1234b, 1234b)
29405+#endif
29406+
29407 1: rep; nop
29408 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29409 js 1b
29410 LOCK_PREFIX
29411 READ_LOCK_SIZE(dec) (%__lock_ptr)
29412+
29413+#ifdef CONFIG_PAX_REFCOUNT
29414+ jno 1234f
29415+ LOCK_PREFIX
29416+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29417+ int $4
29418+1234:
29419+ _ASM_EXTABLE(1234b, 1234b)
29420+#endif
29421+
29422 js 0b
29423 ENDFRAME
29424+ pax_force_retaddr
29425 ret
29426 CFI_ENDPROC
29427 END(__read_lock_failed)
29428diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29429index 5dff5f0..cadebf4 100644
29430--- a/arch/x86/lib/rwsem.S
29431+++ b/arch/x86/lib/rwsem.S
29432@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29433 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29434 CFI_RESTORE __ASM_REG(dx)
29435 restore_common_regs
29436+ pax_force_retaddr
29437 ret
29438 CFI_ENDPROC
29439 ENDPROC(call_rwsem_down_read_failed)
29440@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29441 movq %rax,%rdi
29442 call rwsem_down_write_failed
29443 restore_common_regs
29444+ pax_force_retaddr
29445 ret
29446 CFI_ENDPROC
29447 ENDPROC(call_rwsem_down_write_failed)
29448@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29449 movq %rax,%rdi
29450 call rwsem_wake
29451 restore_common_regs
29452-1: ret
29453+1: pax_force_retaddr
29454+ ret
29455 CFI_ENDPROC
29456 ENDPROC(call_rwsem_wake)
29457
29458@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29459 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29460 CFI_RESTORE __ASM_REG(dx)
29461 restore_common_regs
29462+ pax_force_retaddr
29463 ret
29464 CFI_ENDPROC
29465 ENDPROC(call_rwsem_downgrade_wake)
29466diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29467index a63efd6..ccecad8 100644
29468--- a/arch/x86/lib/thunk_64.S
29469+++ b/arch/x86/lib/thunk_64.S
29470@@ -8,6 +8,7 @@
29471 #include <linux/linkage.h>
29472 #include <asm/dwarf2.h>
29473 #include <asm/calling.h>
29474+#include <asm/alternative-asm.h>
29475
29476 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29477 .macro THUNK name, func, put_ret_addr_in_rdi=0
29478@@ -41,5 +42,6 @@
29479 SAVE_ARGS
29480 restore:
29481 RESTORE_ARGS
29482+ pax_force_retaddr
29483 ret
29484 CFI_ENDPROC
29485diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29486index 3eb18ac..6890bc3 100644
29487--- a/arch/x86/lib/usercopy_32.c
29488+++ b/arch/x86/lib/usercopy_32.c
29489@@ -42,11 +42,13 @@ do { \
29490 int __d0; \
29491 might_fault(); \
29492 __asm__ __volatile__( \
29493+ __COPYUSER_SET_ES \
29494 ASM_STAC "\n" \
29495 "0: rep; stosl\n" \
29496 " movl %2,%0\n" \
29497 "1: rep; stosb\n" \
29498 "2: " ASM_CLAC "\n" \
29499+ __COPYUSER_RESTORE_ES \
29500 ".section .fixup,\"ax\"\n" \
29501 "3: lea 0(%2,%0,4),%0\n" \
29502 " jmp 2b\n" \
29503@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29504
29505 #ifdef CONFIG_X86_INTEL_USERCOPY
29506 static unsigned long
29507-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29508+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29509 {
29510 int d0, d1;
29511 __asm__ __volatile__(
29512@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29513 " .align 2,0x90\n"
29514 "3: movl 0(%4), %%eax\n"
29515 "4: movl 4(%4), %%edx\n"
29516- "5: movl %%eax, 0(%3)\n"
29517- "6: movl %%edx, 4(%3)\n"
29518+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29519+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29520 "7: movl 8(%4), %%eax\n"
29521 "8: movl 12(%4),%%edx\n"
29522- "9: movl %%eax, 8(%3)\n"
29523- "10: movl %%edx, 12(%3)\n"
29524+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29525+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29526 "11: movl 16(%4), %%eax\n"
29527 "12: movl 20(%4), %%edx\n"
29528- "13: movl %%eax, 16(%3)\n"
29529- "14: movl %%edx, 20(%3)\n"
29530+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29531+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29532 "15: movl 24(%4), %%eax\n"
29533 "16: movl 28(%4), %%edx\n"
29534- "17: movl %%eax, 24(%3)\n"
29535- "18: movl %%edx, 28(%3)\n"
29536+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29537+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29538 "19: movl 32(%4), %%eax\n"
29539 "20: movl 36(%4), %%edx\n"
29540- "21: movl %%eax, 32(%3)\n"
29541- "22: movl %%edx, 36(%3)\n"
29542+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29543+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29544 "23: movl 40(%4), %%eax\n"
29545 "24: movl 44(%4), %%edx\n"
29546- "25: movl %%eax, 40(%3)\n"
29547- "26: movl %%edx, 44(%3)\n"
29548+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29549+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29550 "27: movl 48(%4), %%eax\n"
29551 "28: movl 52(%4), %%edx\n"
29552- "29: movl %%eax, 48(%3)\n"
29553- "30: movl %%edx, 52(%3)\n"
29554+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29555+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29556 "31: movl 56(%4), %%eax\n"
29557 "32: movl 60(%4), %%edx\n"
29558- "33: movl %%eax, 56(%3)\n"
29559- "34: movl %%edx, 60(%3)\n"
29560+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29561+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29562 " addl $-64, %0\n"
29563 " addl $64, %4\n"
29564 " addl $64, %3\n"
29565@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29566 " shrl $2, %0\n"
29567 " andl $3, %%eax\n"
29568 " cld\n"
29569+ __COPYUSER_SET_ES
29570 "99: rep; movsl\n"
29571 "36: movl %%eax, %0\n"
29572 "37: rep; movsb\n"
29573 "100:\n"
29574+ __COPYUSER_RESTORE_ES
29575 ".section .fixup,\"ax\"\n"
29576 "101: lea 0(%%eax,%0,4),%0\n"
29577 " jmp 100b\n"
29578@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29579 }
29580
29581 static unsigned long
29582+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29583+{
29584+ int d0, d1;
29585+ __asm__ __volatile__(
29586+ " .align 2,0x90\n"
29587+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29588+ " cmpl $67, %0\n"
29589+ " jbe 3f\n"
29590+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29591+ " .align 2,0x90\n"
29592+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29593+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29594+ "5: movl %%eax, 0(%3)\n"
29595+ "6: movl %%edx, 4(%3)\n"
29596+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29597+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29598+ "9: movl %%eax, 8(%3)\n"
29599+ "10: movl %%edx, 12(%3)\n"
29600+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29601+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29602+ "13: movl %%eax, 16(%3)\n"
29603+ "14: movl %%edx, 20(%3)\n"
29604+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29605+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29606+ "17: movl %%eax, 24(%3)\n"
29607+ "18: movl %%edx, 28(%3)\n"
29608+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29609+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29610+ "21: movl %%eax, 32(%3)\n"
29611+ "22: movl %%edx, 36(%3)\n"
29612+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29613+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29614+ "25: movl %%eax, 40(%3)\n"
29615+ "26: movl %%edx, 44(%3)\n"
29616+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29617+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29618+ "29: movl %%eax, 48(%3)\n"
29619+ "30: movl %%edx, 52(%3)\n"
29620+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29621+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29622+ "33: movl %%eax, 56(%3)\n"
29623+ "34: movl %%edx, 60(%3)\n"
29624+ " addl $-64, %0\n"
29625+ " addl $64, %4\n"
29626+ " addl $64, %3\n"
29627+ " cmpl $63, %0\n"
29628+ " ja 1b\n"
29629+ "35: movl %0, %%eax\n"
29630+ " shrl $2, %0\n"
29631+ " andl $3, %%eax\n"
29632+ " cld\n"
29633+ "99: rep; "__copyuser_seg" movsl\n"
29634+ "36: movl %%eax, %0\n"
29635+ "37: rep; "__copyuser_seg" movsb\n"
29636+ "100:\n"
29637+ ".section .fixup,\"ax\"\n"
29638+ "101: lea 0(%%eax,%0,4),%0\n"
29639+ " jmp 100b\n"
29640+ ".previous\n"
29641+ _ASM_EXTABLE(1b,100b)
29642+ _ASM_EXTABLE(2b,100b)
29643+ _ASM_EXTABLE(3b,100b)
29644+ _ASM_EXTABLE(4b,100b)
29645+ _ASM_EXTABLE(5b,100b)
29646+ _ASM_EXTABLE(6b,100b)
29647+ _ASM_EXTABLE(7b,100b)
29648+ _ASM_EXTABLE(8b,100b)
29649+ _ASM_EXTABLE(9b,100b)
29650+ _ASM_EXTABLE(10b,100b)
29651+ _ASM_EXTABLE(11b,100b)
29652+ _ASM_EXTABLE(12b,100b)
29653+ _ASM_EXTABLE(13b,100b)
29654+ _ASM_EXTABLE(14b,100b)
29655+ _ASM_EXTABLE(15b,100b)
29656+ _ASM_EXTABLE(16b,100b)
29657+ _ASM_EXTABLE(17b,100b)
29658+ _ASM_EXTABLE(18b,100b)
29659+ _ASM_EXTABLE(19b,100b)
29660+ _ASM_EXTABLE(20b,100b)
29661+ _ASM_EXTABLE(21b,100b)
29662+ _ASM_EXTABLE(22b,100b)
29663+ _ASM_EXTABLE(23b,100b)
29664+ _ASM_EXTABLE(24b,100b)
29665+ _ASM_EXTABLE(25b,100b)
29666+ _ASM_EXTABLE(26b,100b)
29667+ _ASM_EXTABLE(27b,100b)
29668+ _ASM_EXTABLE(28b,100b)
29669+ _ASM_EXTABLE(29b,100b)
29670+ _ASM_EXTABLE(30b,100b)
29671+ _ASM_EXTABLE(31b,100b)
29672+ _ASM_EXTABLE(32b,100b)
29673+ _ASM_EXTABLE(33b,100b)
29674+ _ASM_EXTABLE(34b,100b)
29675+ _ASM_EXTABLE(35b,100b)
29676+ _ASM_EXTABLE(36b,100b)
29677+ _ASM_EXTABLE(37b,100b)
29678+ _ASM_EXTABLE(99b,101b)
29679+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29680+ : "1"(to), "2"(from), "0"(size)
29681+ : "eax", "edx", "memory");
29682+ return size;
29683+}
29684+
29685+static unsigned long __size_overflow(3)
29686 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29687 {
29688 int d0, d1;
29689 __asm__ __volatile__(
29690 " .align 2,0x90\n"
29691- "0: movl 32(%4), %%eax\n"
29692+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29693 " cmpl $67, %0\n"
29694 " jbe 2f\n"
29695- "1: movl 64(%4), %%eax\n"
29696+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29697 " .align 2,0x90\n"
29698- "2: movl 0(%4), %%eax\n"
29699- "21: movl 4(%4), %%edx\n"
29700+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29701+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29702 " movl %%eax, 0(%3)\n"
29703 " movl %%edx, 4(%3)\n"
29704- "3: movl 8(%4), %%eax\n"
29705- "31: movl 12(%4),%%edx\n"
29706+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29707+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29708 " movl %%eax, 8(%3)\n"
29709 " movl %%edx, 12(%3)\n"
29710- "4: movl 16(%4), %%eax\n"
29711- "41: movl 20(%4), %%edx\n"
29712+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29713+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29714 " movl %%eax, 16(%3)\n"
29715 " movl %%edx, 20(%3)\n"
29716- "10: movl 24(%4), %%eax\n"
29717- "51: movl 28(%4), %%edx\n"
29718+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29719+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29720 " movl %%eax, 24(%3)\n"
29721 " movl %%edx, 28(%3)\n"
29722- "11: movl 32(%4), %%eax\n"
29723- "61: movl 36(%4), %%edx\n"
29724+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29725+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29726 " movl %%eax, 32(%3)\n"
29727 " movl %%edx, 36(%3)\n"
29728- "12: movl 40(%4), %%eax\n"
29729- "71: movl 44(%4), %%edx\n"
29730+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29731+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29732 " movl %%eax, 40(%3)\n"
29733 " movl %%edx, 44(%3)\n"
29734- "13: movl 48(%4), %%eax\n"
29735- "81: movl 52(%4), %%edx\n"
29736+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29737+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29738 " movl %%eax, 48(%3)\n"
29739 " movl %%edx, 52(%3)\n"
29740- "14: movl 56(%4), %%eax\n"
29741- "91: movl 60(%4), %%edx\n"
29742+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29743+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29744 " movl %%eax, 56(%3)\n"
29745 " movl %%edx, 60(%3)\n"
29746 " addl $-64, %0\n"
29747@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29748 " shrl $2, %0\n"
29749 " andl $3, %%eax\n"
29750 " cld\n"
29751- "6: rep; movsl\n"
29752+ "6: rep; "__copyuser_seg" movsl\n"
29753 " movl %%eax,%0\n"
29754- "7: rep; movsb\n"
29755+ "7: rep; "__copyuser_seg" movsb\n"
29756 "8:\n"
29757 ".section .fixup,\"ax\"\n"
29758 "9: lea 0(%%eax,%0,4),%0\n"
29759@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29760 * hyoshiok@miraclelinux.com
29761 */
29762
29763-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29764+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
29765 const void __user *from, unsigned long size)
29766 {
29767 int d0, d1;
29768
29769 __asm__ __volatile__(
29770 " .align 2,0x90\n"
29771- "0: movl 32(%4), %%eax\n"
29772+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29773 " cmpl $67, %0\n"
29774 " jbe 2f\n"
29775- "1: movl 64(%4), %%eax\n"
29776+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29777 " .align 2,0x90\n"
29778- "2: movl 0(%4), %%eax\n"
29779- "21: movl 4(%4), %%edx\n"
29780+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29781+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29782 " movnti %%eax, 0(%3)\n"
29783 " movnti %%edx, 4(%3)\n"
29784- "3: movl 8(%4), %%eax\n"
29785- "31: movl 12(%4),%%edx\n"
29786+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29787+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29788 " movnti %%eax, 8(%3)\n"
29789 " movnti %%edx, 12(%3)\n"
29790- "4: movl 16(%4), %%eax\n"
29791- "41: movl 20(%4), %%edx\n"
29792+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29793+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29794 " movnti %%eax, 16(%3)\n"
29795 " movnti %%edx, 20(%3)\n"
29796- "10: movl 24(%4), %%eax\n"
29797- "51: movl 28(%4), %%edx\n"
29798+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29799+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29800 " movnti %%eax, 24(%3)\n"
29801 " movnti %%edx, 28(%3)\n"
29802- "11: movl 32(%4), %%eax\n"
29803- "61: movl 36(%4), %%edx\n"
29804+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29805+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29806 " movnti %%eax, 32(%3)\n"
29807 " movnti %%edx, 36(%3)\n"
29808- "12: movl 40(%4), %%eax\n"
29809- "71: movl 44(%4), %%edx\n"
29810+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29811+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29812 " movnti %%eax, 40(%3)\n"
29813 " movnti %%edx, 44(%3)\n"
29814- "13: movl 48(%4), %%eax\n"
29815- "81: movl 52(%4), %%edx\n"
29816+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29817+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29818 " movnti %%eax, 48(%3)\n"
29819 " movnti %%edx, 52(%3)\n"
29820- "14: movl 56(%4), %%eax\n"
29821- "91: movl 60(%4), %%edx\n"
29822+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29823+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29824 " movnti %%eax, 56(%3)\n"
29825 " movnti %%edx, 60(%3)\n"
29826 " addl $-64, %0\n"
29827@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29828 " shrl $2, %0\n"
29829 " andl $3, %%eax\n"
29830 " cld\n"
29831- "6: rep; movsl\n"
29832+ "6: rep; "__copyuser_seg" movsl\n"
29833 " movl %%eax,%0\n"
29834- "7: rep; movsb\n"
29835+ "7: rep; "__copyuser_seg" movsb\n"
29836 "8:\n"
29837 ".section .fixup,\"ax\"\n"
29838 "9: lea 0(%%eax,%0,4),%0\n"
29839@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29840 return size;
29841 }
29842
29843-static unsigned long __copy_user_intel_nocache(void *to,
29844+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
29845 const void __user *from, unsigned long size)
29846 {
29847 int d0, d1;
29848
29849 __asm__ __volatile__(
29850 " .align 2,0x90\n"
29851- "0: movl 32(%4), %%eax\n"
29852+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29853 " cmpl $67, %0\n"
29854 " jbe 2f\n"
29855- "1: movl 64(%4), %%eax\n"
29856+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29857 " .align 2,0x90\n"
29858- "2: movl 0(%4), %%eax\n"
29859- "21: movl 4(%4), %%edx\n"
29860+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29861+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29862 " movnti %%eax, 0(%3)\n"
29863 " movnti %%edx, 4(%3)\n"
29864- "3: movl 8(%4), %%eax\n"
29865- "31: movl 12(%4),%%edx\n"
29866+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29867+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29868 " movnti %%eax, 8(%3)\n"
29869 " movnti %%edx, 12(%3)\n"
29870- "4: movl 16(%4), %%eax\n"
29871- "41: movl 20(%4), %%edx\n"
29872+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29873+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29874 " movnti %%eax, 16(%3)\n"
29875 " movnti %%edx, 20(%3)\n"
29876- "10: movl 24(%4), %%eax\n"
29877- "51: movl 28(%4), %%edx\n"
29878+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29879+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29880 " movnti %%eax, 24(%3)\n"
29881 " movnti %%edx, 28(%3)\n"
29882- "11: movl 32(%4), %%eax\n"
29883- "61: movl 36(%4), %%edx\n"
29884+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29885+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29886 " movnti %%eax, 32(%3)\n"
29887 " movnti %%edx, 36(%3)\n"
29888- "12: movl 40(%4), %%eax\n"
29889- "71: movl 44(%4), %%edx\n"
29890+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29891+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29892 " movnti %%eax, 40(%3)\n"
29893 " movnti %%edx, 44(%3)\n"
29894- "13: movl 48(%4), %%eax\n"
29895- "81: movl 52(%4), %%edx\n"
29896+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29897+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29898 " movnti %%eax, 48(%3)\n"
29899 " movnti %%edx, 52(%3)\n"
29900- "14: movl 56(%4), %%eax\n"
29901- "91: movl 60(%4), %%edx\n"
29902+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29903+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29904 " movnti %%eax, 56(%3)\n"
29905 " movnti %%edx, 60(%3)\n"
29906 " addl $-64, %0\n"
29907@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29908 " shrl $2, %0\n"
29909 " andl $3, %%eax\n"
29910 " cld\n"
29911- "6: rep; movsl\n"
29912+ "6: rep; "__copyuser_seg" movsl\n"
29913 " movl %%eax,%0\n"
29914- "7: rep; movsb\n"
29915+ "7: rep; "__copyuser_seg" movsb\n"
29916 "8:\n"
29917 ".section .fixup,\"ax\"\n"
29918 "9: lea 0(%%eax,%0,4),%0\n"
29919@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29920 */
29921 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29922 unsigned long size);
29923-unsigned long __copy_user_intel(void __user *to, const void *from,
29924+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29925+ unsigned long size);
29926+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29927 unsigned long size);
29928 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29929 const void __user *from, unsigned long size);
29930 #endif /* CONFIG_X86_INTEL_USERCOPY */
29931
29932 /* Generic arbitrary sized copy. */
29933-#define __copy_user(to, from, size) \
29934+#define __copy_user(to, from, size, prefix, set, restore) \
29935 do { \
29936 int __d0, __d1, __d2; \
29937 __asm__ __volatile__( \
29938+ set \
29939 " cmp $7,%0\n" \
29940 " jbe 1f\n" \
29941 " movl %1,%0\n" \
29942 " negl %0\n" \
29943 " andl $7,%0\n" \
29944 " subl %0,%3\n" \
29945- "4: rep; movsb\n" \
29946+ "4: rep; "prefix"movsb\n" \
29947 " movl %3,%0\n" \
29948 " shrl $2,%0\n" \
29949 " andl $3,%3\n" \
29950 " .align 2,0x90\n" \
29951- "0: rep; movsl\n" \
29952+ "0: rep; "prefix"movsl\n" \
29953 " movl %3,%0\n" \
29954- "1: rep; movsb\n" \
29955+ "1: rep; "prefix"movsb\n" \
29956 "2:\n" \
29957+ restore \
29958 ".section .fixup,\"ax\"\n" \
29959 "5: addl %3,%0\n" \
29960 " jmp 2b\n" \
29961@@ -538,14 +650,14 @@ do { \
29962 " negl %0\n" \
29963 " andl $7,%0\n" \
29964 " subl %0,%3\n" \
29965- "4: rep; movsb\n" \
29966+ "4: rep; "__copyuser_seg"movsb\n" \
29967 " movl %3,%0\n" \
29968 " shrl $2,%0\n" \
29969 " andl $3,%3\n" \
29970 " .align 2,0x90\n" \
29971- "0: rep; movsl\n" \
29972+ "0: rep; "__copyuser_seg"movsl\n" \
29973 " movl %3,%0\n" \
29974- "1: rep; movsb\n" \
29975+ "1: rep; "__copyuser_seg"movsb\n" \
29976 "2:\n" \
29977 ".section .fixup,\"ax\"\n" \
29978 "5: addl %3,%0\n" \
29979@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29980 {
29981 stac();
29982 if (movsl_is_ok(to, from, n))
29983- __copy_user(to, from, n);
29984+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29985 else
29986- n = __copy_user_intel(to, from, n);
29987+ n = __generic_copy_to_user_intel(to, from, n);
29988 clac();
29989 return n;
29990 }
29991@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29992 {
29993 stac();
29994 if (movsl_is_ok(to, from, n))
29995- __copy_user(to, from, n);
29996+ __copy_user(to, from, n, __copyuser_seg, "", "");
29997 else
29998- n = __copy_user_intel((void __user *)to,
29999- (const void *)from, n);
30000+ n = __generic_copy_from_user_intel(to, from, n);
30001 clac();
30002 return n;
30003 }
30004@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30005 if (n > 64 && cpu_has_xmm2)
30006 n = __copy_user_intel_nocache(to, from, n);
30007 else
30008- __copy_user(to, from, n);
30009+ __copy_user(to, from, n, __copyuser_seg, "", "");
30010 #else
30011- __copy_user(to, from, n);
30012+ __copy_user(to, from, n, __copyuser_seg, "", "");
30013 #endif
30014 clac();
30015 return n;
30016 }
30017 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30018
30019-/**
30020- * copy_to_user: - Copy a block of data into user space.
30021- * @to: Destination address, in user space.
30022- * @from: Source address, in kernel space.
30023- * @n: Number of bytes to copy.
30024- *
30025- * Context: User context only. This function may sleep.
30026- *
30027- * Copy data from kernel space to user space.
30028- *
30029- * Returns number of bytes that could not be copied.
30030- * On success, this will be zero.
30031- */
30032-unsigned long
30033-copy_to_user(void __user *to, const void *from, unsigned long n)
30034+#ifdef CONFIG_PAX_MEMORY_UDEREF
30035+void __set_fs(mm_segment_t x)
30036 {
30037- if (access_ok(VERIFY_WRITE, to, n))
30038- n = __copy_to_user(to, from, n);
30039- return n;
30040+ switch (x.seg) {
30041+ case 0:
30042+ loadsegment(gs, 0);
30043+ break;
30044+ case TASK_SIZE_MAX:
30045+ loadsegment(gs, __USER_DS);
30046+ break;
30047+ case -1UL:
30048+ loadsegment(gs, __KERNEL_DS);
30049+ break;
30050+ default:
30051+ BUG();
30052+ }
30053 }
30054-EXPORT_SYMBOL(copy_to_user);
30055+EXPORT_SYMBOL(__set_fs);
30056
30057-/**
30058- * copy_from_user: - Copy a block of data from user space.
30059- * @to: Destination address, in kernel space.
30060- * @from: Source address, in user space.
30061- * @n: Number of bytes to copy.
30062- *
30063- * Context: User context only. This function may sleep.
30064- *
30065- * Copy data from user space to kernel space.
30066- *
30067- * Returns number of bytes that could not be copied.
30068- * On success, this will be zero.
30069- *
30070- * If some data could not be copied, this function will pad the copied
30071- * data to the requested size using zero bytes.
30072- */
30073-unsigned long
30074-_copy_from_user(void *to, const void __user *from, unsigned long n)
30075+void set_fs(mm_segment_t x)
30076 {
30077- if (access_ok(VERIFY_READ, from, n))
30078- n = __copy_from_user(to, from, n);
30079- else
30080- memset(to, 0, n);
30081- return n;
30082+ current_thread_info()->addr_limit = x;
30083+ __set_fs(x);
30084 }
30085-EXPORT_SYMBOL(_copy_from_user);
30086+EXPORT_SYMBOL(set_fs);
30087+#endif
30088diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
30089index 906fea3..0194a18 100644
30090--- a/arch/x86/lib/usercopy_64.c
30091+++ b/arch/x86/lib/usercopy_64.c
30092@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30093 might_fault();
30094 /* no memory constraint because it doesn't change any memory gcc knows
30095 about */
30096+ pax_open_userland();
30097 stac();
30098 asm volatile(
30099 " testq %[size8],%[size8]\n"
30100@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30101 _ASM_EXTABLE(0b,3b)
30102 _ASM_EXTABLE(1b,2b)
30103 : [size8] "=&c"(size), [dst] "=&D" (__d0)
30104- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
30105+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
30106 [zero] "r" (0UL), [eight] "r" (8UL));
30107 clac();
30108+ pax_close_userland();
30109 return size;
30110 }
30111 EXPORT_SYMBOL(__clear_user);
30112@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
30113 }
30114 EXPORT_SYMBOL(clear_user);
30115
30116-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
30117+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
30118 {
30119- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
30120- return copy_user_generic((__force void *)to, (__force void *)from, len);
30121- }
30122- return len;
30123+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
30124+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
30125+ return len;
30126 }
30127 EXPORT_SYMBOL(copy_in_user);
30128
30129@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
30130 * it is not necessary to optimize tail handling.
30131 */
30132 unsigned long
30133-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30134+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
30135 {
30136 char c;
30137 unsigned zero_len;
30138
30139+ clac();
30140+ pax_close_userland();
30141 for (; len; --len, to++) {
30142 if (__get_user_nocheck(c, from++, sizeof(char)))
30143 break;
30144@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30145 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
30146 if (__put_user_nocheck(c, to++, sizeof(char)))
30147 break;
30148- clac();
30149 return len;
30150 }
30151diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
30152index 23d8e5f..9ccc13a 100644
30153--- a/arch/x86/mm/Makefile
30154+++ b/arch/x86/mm/Makefile
30155@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
30156 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
30157
30158 obj-$(CONFIG_MEMTEST) += memtest.o
30159+
30160+quote:="
30161+obj-$(CONFIG_X86_64) += uderef_64.o
30162+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
30163diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
30164index 903ec1e..c4166b2 100644
30165--- a/arch/x86/mm/extable.c
30166+++ b/arch/x86/mm/extable.c
30167@@ -6,12 +6,24 @@
30168 static inline unsigned long
30169 ex_insn_addr(const struct exception_table_entry *x)
30170 {
30171- return (unsigned long)&x->insn + x->insn;
30172+ unsigned long reloc = 0;
30173+
30174+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30175+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30176+#endif
30177+
30178+ return (unsigned long)&x->insn + x->insn + reloc;
30179 }
30180 static inline unsigned long
30181 ex_fixup_addr(const struct exception_table_entry *x)
30182 {
30183- return (unsigned long)&x->fixup + x->fixup;
30184+ unsigned long reloc = 0;
30185+
30186+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30187+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30188+#endif
30189+
30190+ return (unsigned long)&x->fixup + x->fixup + reloc;
30191 }
30192
30193 int fixup_exception(struct pt_regs *regs)
30194@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
30195 unsigned long new_ip;
30196
30197 #ifdef CONFIG_PNPBIOS
30198- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
30199+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
30200 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
30201 extern u32 pnp_bios_is_utter_crap;
30202 pnp_bios_is_utter_crap = 1;
30203@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
30204 i += 4;
30205 p->fixup -= i;
30206 i += 4;
30207+
30208+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30209+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
30210+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30211+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30212+#endif
30213+
30214 }
30215 }
30216
30217diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
30218index 654be4a..a4a3da1 100644
30219--- a/arch/x86/mm/fault.c
30220+++ b/arch/x86/mm/fault.c
30221@@ -14,11 +14,18 @@
30222 #include <linux/hugetlb.h> /* hstate_index_to_shift */
30223 #include <linux/prefetch.h> /* prefetchw */
30224 #include <linux/context_tracking.h> /* exception_enter(), ... */
30225+#include <linux/unistd.h>
30226+#include <linux/compiler.h>
30227
30228 #include <asm/traps.h> /* dotraplinkage, ... */
30229 #include <asm/pgalloc.h> /* pgd_*(), ... */
30230 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
30231 #include <asm/fixmap.h> /* VSYSCALL_START */
30232+#include <asm/tlbflush.h>
30233+
30234+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30235+#include <asm/stacktrace.h>
30236+#endif
30237
30238 /*
30239 * Page fault error code bits:
30240@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
30241 int ret = 0;
30242
30243 /* kprobe_running() needs smp_processor_id() */
30244- if (kprobes_built_in() && !user_mode_vm(regs)) {
30245+ if (kprobes_built_in() && !user_mode(regs)) {
30246 preempt_disable();
30247 if (kprobe_running() && kprobe_fault_handler(regs, 14))
30248 ret = 1;
30249@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
30250 return !instr_lo || (instr_lo>>1) == 1;
30251 case 0x00:
30252 /* Prefetch instruction is 0x0F0D or 0x0F18 */
30253- if (probe_kernel_address(instr, opcode))
30254+ if (user_mode(regs)) {
30255+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30256+ return 0;
30257+ } else if (probe_kernel_address(instr, opcode))
30258 return 0;
30259
30260 *prefetch = (instr_lo == 0xF) &&
30261@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
30262 while (instr < max_instr) {
30263 unsigned char opcode;
30264
30265- if (probe_kernel_address(instr, opcode))
30266+ if (user_mode(regs)) {
30267+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30268+ break;
30269+ } else if (probe_kernel_address(instr, opcode))
30270 break;
30271
30272 instr++;
30273@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
30274 force_sig_info(si_signo, &info, tsk);
30275 }
30276
30277+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30278+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
30279+#endif
30280+
30281+#ifdef CONFIG_PAX_EMUTRAMP
30282+static int pax_handle_fetch_fault(struct pt_regs *regs);
30283+#endif
30284+
30285+#ifdef CONFIG_PAX_PAGEEXEC
30286+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
30287+{
30288+ pgd_t *pgd;
30289+ pud_t *pud;
30290+ pmd_t *pmd;
30291+
30292+ pgd = pgd_offset(mm, address);
30293+ if (!pgd_present(*pgd))
30294+ return NULL;
30295+ pud = pud_offset(pgd, address);
30296+ if (!pud_present(*pud))
30297+ return NULL;
30298+ pmd = pmd_offset(pud, address);
30299+ if (!pmd_present(*pmd))
30300+ return NULL;
30301+ return pmd;
30302+}
30303+#endif
30304+
30305 DEFINE_SPINLOCK(pgd_lock);
30306 LIST_HEAD(pgd_list);
30307
30308@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
30309 for (address = VMALLOC_START & PMD_MASK;
30310 address >= TASK_SIZE && address < FIXADDR_TOP;
30311 address += PMD_SIZE) {
30312+
30313+#ifdef CONFIG_PAX_PER_CPU_PGD
30314+ unsigned long cpu;
30315+#else
30316 struct page *page;
30317+#endif
30318
30319 spin_lock(&pgd_lock);
30320+
30321+#ifdef CONFIG_PAX_PER_CPU_PGD
30322+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30323+ pgd_t *pgd = get_cpu_pgd(cpu, user);
30324+ pmd_t *ret;
30325+
30326+ ret = vmalloc_sync_one(pgd, address);
30327+ if (!ret)
30328+ break;
30329+ pgd = get_cpu_pgd(cpu, kernel);
30330+#else
30331 list_for_each_entry(page, &pgd_list, lru) {
30332+ pgd_t *pgd;
30333 spinlock_t *pgt_lock;
30334 pmd_t *ret;
30335
30336@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
30337 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
30338
30339 spin_lock(pgt_lock);
30340- ret = vmalloc_sync_one(page_address(page), address);
30341+ pgd = page_address(page);
30342+#endif
30343+
30344+ ret = vmalloc_sync_one(pgd, address);
30345+
30346+#ifndef CONFIG_PAX_PER_CPU_PGD
30347 spin_unlock(pgt_lock);
30348+#endif
30349
30350 if (!ret)
30351 break;
30352@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30353 * an interrupt in the middle of a task switch..
30354 */
30355 pgd_paddr = read_cr3();
30356+
30357+#ifdef CONFIG_PAX_PER_CPU_PGD
30358+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30359+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30360+#endif
30361+
30362 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30363 if (!pmd_k)
30364 return -1;
30365@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30366 * happen within a race in page table update. In the later
30367 * case just flush:
30368 */
30369- pgd = pgd_offset(current->active_mm, address);
30370+
30371 pgd_ref = pgd_offset_k(address);
30372 if (pgd_none(*pgd_ref))
30373 return -1;
30374
30375+#ifdef CONFIG_PAX_PER_CPU_PGD
30376+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30377+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30378+ if (pgd_none(*pgd)) {
30379+ set_pgd(pgd, *pgd_ref);
30380+ arch_flush_lazy_mmu_mode();
30381+ } else {
30382+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30383+ }
30384+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30385+#else
30386+ pgd = pgd_offset(current->active_mm, address);
30387+#endif
30388+
30389 if (pgd_none(*pgd)) {
30390 set_pgd(pgd, *pgd_ref);
30391 arch_flush_lazy_mmu_mode();
30392@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30393 static int is_errata100(struct pt_regs *regs, unsigned long address)
30394 {
30395 #ifdef CONFIG_X86_64
30396- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30397+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30398 return 1;
30399 #endif
30400 return 0;
30401@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30402 }
30403
30404 static const char nx_warning[] = KERN_CRIT
30405-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30406+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30407
30408 static void
30409 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30410@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30411 if (!oops_may_print())
30412 return;
30413
30414- if (error_code & PF_INSTR) {
30415+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30416 unsigned int level;
30417
30418 pte_t *pte = lookup_address(address, &level);
30419
30420 if (pte && pte_present(*pte) && !pte_exec(*pte))
30421- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30422+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30423 }
30424
30425+#ifdef CONFIG_PAX_KERNEXEC
30426+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30427+ if (current->signal->curr_ip)
30428+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30429+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30430+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30431+ else
30432+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30433+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30434+ }
30435+#endif
30436+
30437 printk(KERN_ALERT "BUG: unable to handle kernel ");
30438 if (address < PAGE_SIZE)
30439 printk(KERN_CONT "NULL pointer dereference");
30440@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30441 return;
30442 }
30443 #endif
30444+
30445+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30446+ if (pax_is_fetch_fault(regs, error_code, address)) {
30447+
30448+#ifdef CONFIG_PAX_EMUTRAMP
30449+ switch (pax_handle_fetch_fault(regs)) {
30450+ case 2:
30451+ return;
30452+ }
30453+#endif
30454+
30455+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30456+ do_group_exit(SIGKILL);
30457+ }
30458+#endif
30459+
30460 /* Kernel addresses are always protection faults: */
30461 if (address >= TASK_SIZE)
30462 error_code |= PF_PROT;
30463@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30464 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30465 printk(KERN_ERR
30466 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30467- tsk->comm, tsk->pid, address);
30468+ tsk->comm, task_pid_nr(tsk), address);
30469 code = BUS_MCEERR_AR;
30470 }
30471 #endif
30472@@ -898,6 +1010,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30473 return 1;
30474 }
30475
30476+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30477+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30478+{
30479+ pte_t *pte;
30480+ pmd_t *pmd;
30481+ spinlock_t *ptl;
30482+ unsigned char pte_mask;
30483+
30484+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30485+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30486+ return 0;
30487+
30488+ /* PaX: it's our fault, let's handle it if we can */
30489+
30490+ /* PaX: take a look at read faults before acquiring any locks */
30491+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30492+ /* instruction fetch attempt from a protected page in user mode */
30493+ up_read(&mm->mmap_sem);
30494+
30495+#ifdef CONFIG_PAX_EMUTRAMP
30496+ switch (pax_handle_fetch_fault(regs)) {
30497+ case 2:
30498+ return 1;
30499+ }
30500+#endif
30501+
30502+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30503+ do_group_exit(SIGKILL);
30504+ }
30505+
30506+ pmd = pax_get_pmd(mm, address);
30507+ if (unlikely(!pmd))
30508+ return 0;
30509+
30510+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30511+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30512+ pte_unmap_unlock(pte, ptl);
30513+ return 0;
30514+ }
30515+
30516+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30517+ /* write attempt to a protected page in user mode */
30518+ pte_unmap_unlock(pte, ptl);
30519+ return 0;
30520+ }
30521+
30522+#ifdef CONFIG_SMP
30523+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30524+#else
30525+ if (likely(address > get_limit(regs->cs)))
30526+#endif
30527+ {
30528+ set_pte(pte, pte_mkread(*pte));
30529+ __flush_tlb_one(address);
30530+ pte_unmap_unlock(pte, ptl);
30531+ up_read(&mm->mmap_sem);
30532+ return 1;
30533+ }
30534+
30535+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30536+
30537+ /*
30538+ * PaX: fill DTLB with user rights and retry
30539+ */
30540+ __asm__ __volatile__ (
30541+ "orb %2,(%1)\n"
30542+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30543+/*
30544+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30545+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30546+ * page fault when examined during a TLB load attempt. this is true not only
30547+ * for PTEs holding a non-present entry but also present entries that will
30548+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30549+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30550+ * for our target pages since their PTEs are simply not in the TLBs at all.
30551+
30552+ * the best thing in omitting it is that we gain around 15-20% speed in the
30553+ * fast path of the page fault handler and can get rid of tracing since we
30554+ * can no longer flush unintended entries.
30555+ */
30556+ "invlpg (%0)\n"
30557+#endif
30558+ __copyuser_seg"testb $0,(%0)\n"
30559+ "xorb %3,(%1)\n"
30560+ :
30561+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30562+ : "memory", "cc");
30563+ pte_unmap_unlock(pte, ptl);
30564+ up_read(&mm->mmap_sem);
30565+ return 1;
30566+}
30567+#endif
30568+
30569 /*
30570 * Handle a spurious fault caused by a stale TLB entry.
30571 *
30572@@ -964,6 +1169,9 @@ int show_unhandled_signals = 1;
30573 static inline int
30574 access_error(unsigned long error_code, struct vm_area_struct *vma)
30575 {
30576+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30577+ return 1;
30578+
30579 if (error_code & PF_WRITE) {
30580 /* write, present and write, not present: */
30581 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30582@@ -992,7 +1200,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30583 if (error_code & PF_USER)
30584 return false;
30585
30586- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30587+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30588 return false;
30589
30590 return true;
30591@@ -1008,18 +1216,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30592 {
30593 struct vm_area_struct *vma;
30594 struct task_struct *tsk;
30595- unsigned long address;
30596 struct mm_struct *mm;
30597 int fault;
30598 int write = error_code & PF_WRITE;
30599 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
30600 (write ? FAULT_FLAG_WRITE : 0);
30601
30602- tsk = current;
30603- mm = tsk->mm;
30604-
30605 /* Get the faulting address: */
30606- address = read_cr2();
30607+ unsigned long address = read_cr2();
30608+
30609+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30610+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30611+ if (!search_exception_tables(regs->ip)) {
30612+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30613+ bad_area_nosemaphore(regs, error_code, address);
30614+ return;
30615+ }
30616+ if (address < pax_user_shadow_base) {
30617+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30618+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30619+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30620+ } else
30621+ address -= pax_user_shadow_base;
30622+ }
30623+#endif
30624+
30625+ tsk = current;
30626+ mm = tsk->mm;
30627
30628 /*
30629 * Detect and handle instructions that would cause a page fault for
30630@@ -1080,7 +1303,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30631 * User-mode registers count as a user access even for any
30632 * potential system fault or CPU buglet:
30633 */
30634- if (user_mode_vm(regs)) {
30635+ if (user_mode(regs)) {
30636 local_irq_enable();
30637 error_code |= PF_USER;
30638 } else {
30639@@ -1142,6 +1365,11 @@ retry:
30640 might_sleep();
30641 }
30642
30643+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30644+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30645+ return;
30646+#endif
30647+
30648 vma = find_vma(mm, address);
30649 if (unlikely(!vma)) {
30650 bad_area(regs, error_code, address);
30651@@ -1153,18 +1381,24 @@ retry:
30652 bad_area(regs, error_code, address);
30653 return;
30654 }
30655- if (error_code & PF_USER) {
30656- /*
30657- * Accessing the stack below %sp is always a bug.
30658- * The large cushion allows instructions like enter
30659- * and pusha to work. ("enter $65535, $31" pushes
30660- * 32 pointers and then decrements %sp by 65535.)
30661- */
30662- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30663- bad_area(regs, error_code, address);
30664- return;
30665- }
30666+ /*
30667+ * Accessing the stack below %sp is always a bug.
30668+ * The large cushion allows instructions like enter
30669+ * and pusha to work. ("enter $65535, $31" pushes
30670+ * 32 pointers and then decrements %sp by 65535.)
30671+ */
30672+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30673+ bad_area(regs, error_code, address);
30674+ return;
30675 }
30676+
30677+#ifdef CONFIG_PAX_SEGMEXEC
30678+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30679+ bad_area(regs, error_code, address);
30680+ return;
30681+ }
30682+#endif
30683+
30684 if (unlikely(expand_stack(vma, address))) {
30685 bad_area(regs, error_code, address);
30686 return;
30687@@ -1230,3 +1464,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30688 __do_page_fault(regs, error_code);
30689 exception_exit(prev_state);
30690 }
30691+
30692+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30693+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30694+{
30695+ struct mm_struct *mm = current->mm;
30696+ unsigned long ip = regs->ip;
30697+
30698+ if (v8086_mode(regs))
30699+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30700+
30701+#ifdef CONFIG_PAX_PAGEEXEC
30702+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30703+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30704+ return true;
30705+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30706+ return true;
30707+ return false;
30708+ }
30709+#endif
30710+
30711+#ifdef CONFIG_PAX_SEGMEXEC
30712+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30713+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30714+ return true;
30715+ return false;
30716+ }
30717+#endif
30718+
30719+ return false;
30720+}
30721+#endif
30722+
30723+#ifdef CONFIG_PAX_EMUTRAMP
30724+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30725+{
30726+ int err;
30727+
30728+ do { /* PaX: libffi trampoline emulation */
30729+ unsigned char mov, jmp;
30730+ unsigned int addr1, addr2;
30731+
30732+#ifdef CONFIG_X86_64
30733+ if ((regs->ip + 9) >> 32)
30734+ break;
30735+#endif
30736+
30737+ err = get_user(mov, (unsigned char __user *)regs->ip);
30738+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30739+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30740+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30741+
30742+ if (err)
30743+ break;
30744+
30745+ if (mov == 0xB8 && jmp == 0xE9) {
30746+ regs->ax = addr1;
30747+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30748+ return 2;
30749+ }
30750+ } while (0);
30751+
30752+ do { /* PaX: gcc trampoline emulation #1 */
30753+ unsigned char mov1, mov2;
30754+ unsigned short jmp;
30755+ unsigned int addr1, addr2;
30756+
30757+#ifdef CONFIG_X86_64
30758+ if ((regs->ip + 11) >> 32)
30759+ break;
30760+#endif
30761+
30762+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30763+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30764+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30765+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30766+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30767+
30768+ if (err)
30769+ break;
30770+
30771+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30772+ regs->cx = addr1;
30773+ regs->ax = addr2;
30774+ regs->ip = addr2;
30775+ return 2;
30776+ }
30777+ } while (0);
30778+
30779+ do { /* PaX: gcc trampoline emulation #2 */
30780+ unsigned char mov, jmp;
30781+ unsigned int addr1, addr2;
30782+
30783+#ifdef CONFIG_X86_64
30784+ if ((regs->ip + 9) >> 32)
30785+ break;
30786+#endif
30787+
30788+ err = get_user(mov, (unsigned char __user *)regs->ip);
30789+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30790+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30791+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30792+
30793+ if (err)
30794+ break;
30795+
30796+ if (mov == 0xB9 && jmp == 0xE9) {
30797+ regs->cx = addr1;
30798+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30799+ return 2;
30800+ }
30801+ } while (0);
30802+
30803+ return 1; /* PaX in action */
30804+}
30805+
30806+#ifdef CONFIG_X86_64
30807+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30808+{
30809+ int err;
30810+
30811+ do { /* PaX: libffi trampoline emulation */
30812+ unsigned short mov1, mov2, jmp1;
30813+ unsigned char stcclc, jmp2;
30814+ unsigned long addr1, addr2;
30815+
30816+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30817+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30818+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30819+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30820+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
30821+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30822+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30823+
30824+ if (err)
30825+ break;
30826+
30827+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30828+ regs->r11 = addr1;
30829+ regs->r10 = addr2;
30830+ if (stcclc == 0xF8)
30831+ regs->flags &= ~X86_EFLAGS_CF;
30832+ else
30833+ regs->flags |= X86_EFLAGS_CF;
30834+ regs->ip = addr1;
30835+ return 2;
30836+ }
30837+ } while (0);
30838+
30839+ do { /* PaX: gcc trampoline emulation #1 */
30840+ unsigned short mov1, mov2, jmp1;
30841+ unsigned char jmp2;
30842+ unsigned int addr1;
30843+ unsigned long addr2;
30844+
30845+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30846+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30847+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30848+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30849+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30850+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30851+
30852+ if (err)
30853+ break;
30854+
30855+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30856+ regs->r11 = addr1;
30857+ regs->r10 = addr2;
30858+ regs->ip = addr1;
30859+ return 2;
30860+ }
30861+ } while (0);
30862+
30863+ do { /* PaX: gcc trampoline emulation #2 */
30864+ unsigned short mov1, mov2, jmp1;
30865+ unsigned char jmp2;
30866+ unsigned long addr1, addr2;
30867+
30868+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30869+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30870+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30871+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30872+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30873+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30874+
30875+ if (err)
30876+ break;
30877+
30878+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30879+ regs->r11 = addr1;
30880+ regs->r10 = addr2;
30881+ regs->ip = addr1;
30882+ return 2;
30883+ }
30884+ } while (0);
30885+
30886+ return 1; /* PaX in action */
30887+}
30888+#endif
30889+
30890+/*
30891+ * PaX: decide what to do with offenders (regs->ip = fault address)
30892+ *
30893+ * returns 1 when task should be killed
30894+ * 2 when gcc trampoline was detected
30895+ */
30896+static int pax_handle_fetch_fault(struct pt_regs *regs)
30897+{
30898+ if (v8086_mode(regs))
30899+ return 1;
30900+
30901+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30902+ return 1;
30903+
30904+#ifdef CONFIG_X86_32
30905+ return pax_handle_fetch_fault_32(regs);
30906+#else
30907+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30908+ return pax_handle_fetch_fault_32(regs);
30909+ else
30910+ return pax_handle_fetch_fault_64(regs);
30911+#endif
30912+}
30913+#endif
30914+
30915+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30916+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30917+{
30918+ long i;
30919+
30920+ printk(KERN_ERR "PAX: bytes at PC: ");
30921+ for (i = 0; i < 20; i++) {
30922+ unsigned char c;
30923+ if (get_user(c, (unsigned char __force_user *)pc+i))
30924+ printk(KERN_CONT "?? ");
30925+ else
30926+ printk(KERN_CONT "%02x ", c);
30927+ }
30928+ printk("\n");
30929+
30930+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30931+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30932+ unsigned long c;
30933+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30934+#ifdef CONFIG_X86_32
30935+ printk(KERN_CONT "???????? ");
30936+#else
30937+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30938+ printk(KERN_CONT "???????? ???????? ");
30939+ else
30940+ printk(KERN_CONT "???????????????? ");
30941+#endif
30942+ } else {
30943+#ifdef CONFIG_X86_64
30944+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30945+ printk(KERN_CONT "%08x ", (unsigned int)c);
30946+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30947+ } else
30948+#endif
30949+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30950+ }
30951+ }
30952+ printk("\n");
30953+}
30954+#endif
30955+
30956+/**
30957+ * probe_kernel_write(): safely attempt to write to a location
30958+ * @dst: address to write to
30959+ * @src: pointer to the data that shall be written
30960+ * @size: size of the data chunk
30961+ *
30962+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30963+ * happens, handle that and return -EFAULT.
30964+ */
30965+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30966+{
30967+ long ret;
30968+ mm_segment_t old_fs = get_fs();
30969+
30970+ set_fs(KERNEL_DS);
30971+ pagefault_disable();
30972+ pax_open_kernel();
30973+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30974+ pax_close_kernel();
30975+ pagefault_enable();
30976+ set_fs(old_fs);
30977+
30978+ return ret ? -EFAULT : 0;
30979+}
30980diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30981index dd74e46..7d26398 100644
30982--- a/arch/x86/mm/gup.c
30983+++ b/arch/x86/mm/gup.c
30984@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30985 addr = start;
30986 len = (unsigned long) nr_pages << PAGE_SHIFT;
30987 end = start + len;
30988- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30989+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30990 (void __user *)start, len)))
30991 return 0;
30992
30993diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30994index 252b8f5..4dcfdc1 100644
30995--- a/arch/x86/mm/highmem_32.c
30996+++ b/arch/x86/mm/highmem_32.c
30997@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30998 idx = type + KM_TYPE_NR*smp_processor_id();
30999 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31000 BUG_ON(!pte_none(*(kmap_pte-idx)));
31001+
31002+ pax_open_kernel();
31003 set_pte(kmap_pte-idx, mk_pte(page, prot));
31004+ pax_close_kernel();
31005+
31006 arch_flush_lazy_mmu_mode();
31007
31008 return (void *)vaddr;
31009diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31010index ae1aa71..d9bea75 100644
31011--- a/arch/x86/mm/hugetlbpage.c
31012+++ b/arch/x86/mm/hugetlbpage.c
31013@@ -271,23 +271,30 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
31014 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31015 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31016 unsigned long addr, unsigned long len,
31017- unsigned long pgoff, unsigned long flags)
31018+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31019 {
31020 struct hstate *h = hstate_file(file);
31021 struct vm_unmapped_area_info info;
31022-
31023+
31024 info.flags = 0;
31025 info.length = len;
31026 info.low_limit = TASK_UNMAPPED_BASE;
31027+
31028+#ifdef CONFIG_PAX_RANDMMAP
31029+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31030+ info.low_limit += current->mm->delta_mmap;
31031+#endif
31032+
31033 info.high_limit = TASK_SIZE;
31034 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31035 info.align_offset = 0;
31036+ info.threadstack_offset = offset;
31037 return vm_unmapped_area(&info);
31038 }
31039
31040 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31041 unsigned long addr0, unsigned long len,
31042- unsigned long pgoff, unsigned long flags)
31043+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31044 {
31045 struct hstate *h = hstate_file(file);
31046 struct vm_unmapped_area_info info;
31047@@ -299,6 +306,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31048 info.high_limit = current->mm->mmap_base;
31049 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31050 info.align_offset = 0;
31051+ info.threadstack_offset = offset;
31052 addr = vm_unmapped_area(&info);
31053
31054 /*
31055@@ -311,6 +319,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31056 VM_BUG_ON(addr != -ENOMEM);
31057 info.flags = 0;
31058 info.low_limit = TASK_UNMAPPED_BASE;
31059+
31060+#ifdef CONFIG_PAX_RANDMMAP
31061+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31062+ info.low_limit += current->mm->delta_mmap;
31063+#endif
31064+
31065 info.high_limit = TASK_SIZE;
31066 addr = vm_unmapped_area(&info);
31067 }
31068@@ -325,10 +339,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31069 struct hstate *h = hstate_file(file);
31070 struct mm_struct *mm = current->mm;
31071 struct vm_area_struct *vma;
31072+ unsigned long pax_task_size = TASK_SIZE;
31073+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
31074
31075 if (len & ~huge_page_mask(h))
31076 return -EINVAL;
31077- if (len > TASK_SIZE)
31078+
31079+#ifdef CONFIG_PAX_SEGMEXEC
31080+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31081+ pax_task_size = SEGMEXEC_TASK_SIZE;
31082+#endif
31083+
31084+ pax_task_size -= PAGE_SIZE;
31085+
31086+ if (len > pax_task_size)
31087 return -ENOMEM;
31088
31089 if (flags & MAP_FIXED) {
31090@@ -337,19 +361,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31091 return addr;
31092 }
31093
31094+#ifdef CONFIG_PAX_RANDMMAP
31095+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31096+#endif
31097+
31098 if (addr) {
31099 addr = ALIGN(addr, huge_page_size(h));
31100 vma = find_vma(mm, addr);
31101- if (TASK_SIZE - len >= addr &&
31102- (!vma || addr + len <= vma->vm_start))
31103+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
31104 return addr;
31105 }
31106 if (mm->get_unmapped_area == arch_get_unmapped_area)
31107 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
31108- pgoff, flags);
31109+ pgoff, flags, offset);
31110 else
31111 return hugetlb_get_unmapped_area_topdown(file, addr, len,
31112- pgoff, flags);
31113+ pgoff, flags, offset);
31114 }
31115
31116 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
31117diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
31118index 7a5bf1b..c96ab0d 100644
31119--- a/arch/x86/mm/init.c
31120+++ b/arch/x86/mm/init.c
31121@@ -4,6 +4,7 @@
31122 #include <linux/swap.h>
31123 #include <linux/memblock.h>
31124 #include <linux/bootmem.h> /* for max_low_pfn */
31125+#include <linux/tboot.h>
31126
31127 #include <asm/cacheflush.h>
31128 #include <asm/e820.h>
31129@@ -17,6 +18,8 @@
31130 #include <asm/proto.h>
31131 #include <asm/dma.h> /* for MAX_DMA_PFN */
31132 #include <asm/microcode.h>
31133+#include <asm/desc.h>
31134+#include <asm/bios_ebda.h>
31135
31136 #include "mm_internal.h"
31137
31138@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
31139 early_ioremap_page_table_range_init();
31140 #endif
31141
31142+#ifdef CONFIG_PAX_PER_CPU_PGD
31143+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
31144+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31145+ KERNEL_PGD_PTRS);
31146+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
31147+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31148+ KERNEL_PGD_PTRS);
31149+ load_cr3(get_cpu_pgd(0, kernel));
31150+#else
31151 load_cr3(swapper_pg_dir);
31152+#endif
31153+
31154 __flush_tlb_all();
31155
31156 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
31157@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
31158 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
31159 * mmio resources as well as potential bios/acpi data regions.
31160 */
31161+
31162+#ifdef CONFIG_GRKERNSEC_KMEM
31163+static unsigned int ebda_start __read_only;
31164+static unsigned int ebda_end __read_only;
31165+#endif
31166+
31167 int devmem_is_allowed(unsigned long pagenr)
31168 {
31169- if (pagenr < 256)
31170+#ifdef CONFIG_GRKERNSEC_KMEM
31171+ /* allow BDA */
31172+ if (!pagenr)
31173 return 1;
31174+ /* allow EBDA */
31175+ if (pagenr >= ebda_start && pagenr < ebda_end)
31176+ return 1;
31177+ /* if tboot is in use, allow access to its hardcoded serial log range */
31178+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
31179+ return 1;
31180+#else
31181+ if (!pagenr)
31182+ return 1;
31183+#ifdef CONFIG_VM86
31184+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
31185+ return 1;
31186+#endif
31187+#endif
31188+
31189+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
31190+ return 1;
31191+#ifdef CONFIG_GRKERNSEC_KMEM
31192+ /* throw out everything else below 1MB */
31193+ if (pagenr <= 256)
31194+ return 0;
31195+#endif
31196 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
31197 return 0;
31198 if (!page_is_ram(pagenr))
31199@@ -538,8 +582,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
31200 #endif
31201 }
31202
31203+#ifdef CONFIG_GRKERNSEC_KMEM
31204+static inline void gr_init_ebda(void)
31205+{
31206+ unsigned int ebda_addr;
31207+ unsigned int ebda_size = 0;
31208+
31209+ ebda_addr = get_bios_ebda();
31210+ if (ebda_addr) {
31211+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
31212+ ebda_size <<= 10;
31213+ }
31214+ if (ebda_addr && ebda_size) {
31215+ ebda_start = ebda_addr >> PAGE_SHIFT;
31216+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
31217+ } else {
31218+ ebda_start = 0x9f000 >> PAGE_SHIFT;
31219+ ebda_end = 0xa0000 >> PAGE_SHIFT;
31220+ }
31221+}
31222+#else
31223+static inline void gr_init_ebda(void) { }
31224+#endif
31225+
31226 void free_initmem(void)
31227 {
31228+#ifdef CONFIG_PAX_KERNEXEC
31229+#ifdef CONFIG_X86_32
31230+ /* PaX: limit KERNEL_CS to actual size */
31231+ unsigned long addr, limit;
31232+ struct desc_struct d;
31233+ int cpu;
31234+#else
31235+ pgd_t *pgd;
31236+ pud_t *pud;
31237+ pmd_t *pmd;
31238+ unsigned long addr, end;
31239+#endif
31240+#endif
31241+
31242+ gr_init_ebda();
31243+
31244+#ifdef CONFIG_PAX_KERNEXEC
31245+#ifdef CONFIG_X86_32
31246+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
31247+ limit = (limit - 1UL) >> PAGE_SHIFT;
31248+
31249+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
31250+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
31251+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
31252+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
31253+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
31254+ }
31255+
31256+ /* PaX: make KERNEL_CS read-only */
31257+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
31258+ if (!paravirt_enabled())
31259+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
31260+/*
31261+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
31262+ pgd = pgd_offset_k(addr);
31263+ pud = pud_offset(pgd, addr);
31264+ pmd = pmd_offset(pud, addr);
31265+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31266+ }
31267+*/
31268+#ifdef CONFIG_X86_PAE
31269+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
31270+/*
31271+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
31272+ pgd = pgd_offset_k(addr);
31273+ pud = pud_offset(pgd, addr);
31274+ pmd = pmd_offset(pud, addr);
31275+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31276+ }
31277+*/
31278+#endif
31279+
31280+#ifdef CONFIG_MODULES
31281+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
31282+#endif
31283+
31284+#else
31285+ /* PaX: make kernel code/rodata read-only, rest non-executable */
31286+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
31287+ pgd = pgd_offset_k(addr);
31288+ pud = pud_offset(pgd, addr);
31289+ pmd = pmd_offset(pud, addr);
31290+ if (!pmd_present(*pmd))
31291+ continue;
31292+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
31293+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31294+ else
31295+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31296+ }
31297+
31298+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
31299+ end = addr + KERNEL_IMAGE_SIZE;
31300+ for (; addr < end; addr += PMD_SIZE) {
31301+ pgd = pgd_offset_k(addr);
31302+ pud = pud_offset(pgd, addr);
31303+ pmd = pmd_offset(pud, addr);
31304+ if (!pmd_present(*pmd))
31305+ continue;
31306+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
31307+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31308+ }
31309+#endif
31310+
31311+ flush_tlb_all();
31312+#endif
31313+
31314 free_init_pages("unused kernel memory",
31315 (unsigned long)(&__init_begin),
31316 (unsigned long)(&__init_end));
31317diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
31318index 3ac7e31..89611b7 100644
31319--- a/arch/x86/mm/init_32.c
31320+++ b/arch/x86/mm/init_32.c
31321@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
31322 bool __read_mostly __vmalloc_start_set = false;
31323
31324 /*
31325- * Creates a middle page table and puts a pointer to it in the
31326- * given global directory entry. This only returns the gd entry
31327- * in non-PAE compilation mode, since the middle layer is folded.
31328- */
31329-static pmd_t * __init one_md_table_init(pgd_t *pgd)
31330-{
31331- pud_t *pud;
31332- pmd_t *pmd_table;
31333-
31334-#ifdef CONFIG_X86_PAE
31335- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
31336- pmd_table = (pmd_t *)alloc_low_page();
31337- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
31338- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
31339- pud = pud_offset(pgd, 0);
31340- BUG_ON(pmd_table != pmd_offset(pud, 0));
31341-
31342- return pmd_table;
31343- }
31344-#endif
31345- pud = pud_offset(pgd, 0);
31346- pmd_table = pmd_offset(pud, 0);
31347-
31348- return pmd_table;
31349-}
31350-
31351-/*
31352 * Create a page table and place a pointer to it in a middle page
31353 * directory entry:
31354 */
31355@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31356 pte_t *page_table = (pte_t *)alloc_low_page();
31357
31358 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31359+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31360+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31361+#else
31362 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31363+#endif
31364 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31365 }
31366
31367 return pte_offset_kernel(pmd, 0);
31368 }
31369
31370+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31371+{
31372+ pud_t *pud;
31373+ pmd_t *pmd_table;
31374+
31375+ pud = pud_offset(pgd, 0);
31376+ pmd_table = pmd_offset(pud, 0);
31377+
31378+ return pmd_table;
31379+}
31380+
31381 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31382 {
31383 int pgd_idx = pgd_index(vaddr);
31384@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31385 int pgd_idx, pmd_idx;
31386 unsigned long vaddr;
31387 pgd_t *pgd;
31388+ pud_t *pud;
31389 pmd_t *pmd;
31390 pte_t *pte = NULL;
31391 unsigned long count = page_table_range_init_count(start, end);
31392@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31393 pgd = pgd_base + pgd_idx;
31394
31395 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31396- pmd = one_md_table_init(pgd);
31397- pmd = pmd + pmd_index(vaddr);
31398+ pud = pud_offset(pgd, vaddr);
31399+ pmd = pmd_offset(pud, vaddr);
31400+
31401+#ifdef CONFIG_X86_PAE
31402+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31403+#endif
31404+
31405 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31406 pmd++, pmd_idx++) {
31407 pte = page_table_kmap_check(one_page_table_init(pmd),
31408@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31409 }
31410 }
31411
31412-static inline int is_kernel_text(unsigned long addr)
31413+static inline int is_kernel_text(unsigned long start, unsigned long end)
31414 {
31415- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31416- return 1;
31417- return 0;
31418+ if ((start > ktla_ktva((unsigned long)_etext) ||
31419+ end <= ktla_ktva((unsigned long)_stext)) &&
31420+ (start > ktla_ktva((unsigned long)_einittext) ||
31421+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31422+
31423+#ifdef CONFIG_ACPI_SLEEP
31424+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31425+#endif
31426+
31427+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31428+ return 0;
31429+ return 1;
31430 }
31431
31432 /*
31433@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31434 unsigned long last_map_addr = end;
31435 unsigned long start_pfn, end_pfn;
31436 pgd_t *pgd_base = swapper_pg_dir;
31437- int pgd_idx, pmd_idx, pte_ofs;
31438+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31439 unsigned long pfn;
31440 pgd_t *pgd;
31441+ pud_t *pud;
31442 pmd_t *pmd;
31443 pte_t *pte;
31444 unsigned pages_2m, pages_4k;
31445@@ -291,8 +295,13 @@ repeat:
31446 pfn = start_pfn;
31447 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31448 pgd = pgd_base + pgd_idx;
31449- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31450- pmd = one_md_table_init(pgd);
31451+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31452+ pud = pud_offset(pgd, 0);
31453+ pmd = pmd_offset(pud, 0);
31454+
31455+#ifdef CONFIG_X86_PAE
31456+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31457+#endif
31458
31459 if (pfn >= end_pfn)
31460 continue;
31461@@ -304,14 +313,13 @@ repeat:
31462 #endif
31463 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31464 pmd++, pmd_idx++) {
31465- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31466+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31467
31468 /*
31469 * Map with big pages if possible, otherwise
31470 * create normal page tables:
31471 */
31472 if (use_pse) {
31473- unsigned int addr2;
31474 pgprot_t prot = PAGE_KERNEL_LARGE;
31475 /*
31476 * first pass will use the same initial
31477@@ -322,11 +330,7 @@ repeat:
31478 _PAGE_PSE);
31479
31480 pfn &= PMD_MASK >> PAGE_SHIFT;
31481- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31482- PAGE_OFFSET + PAGE_SIZE-1;
31483-
31484- if (is_kernel_text(addr) ||
31485- is_kernel_text(addr2))
31486+ if (is_kernel_text(address, address + PMD_SIZE))
31487 prot = PAGE_KERNEL_LARGE_EXEC;
31488
31489 pages_2m++;
31490@@ -343,7 +347,7 @@ repeat:
31491 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31492 pte += pte_ofs;
31493 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31494- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31495+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31496 pgprot_t prot = PAGE_KERNEL;
31497 /*
31498 * first pass will use the same initial
31499@@ -351,7 +355,7 @@ repeat:
31500 */
31501 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31502
31503- if (is_kernel_text(addr))
31504+ if (is_kernel_text(address, address + PAGE_SIZE))
31505 prot = PAGE_KERNEL_EXEC;
31506
31507 pages_4k++;
31508@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31509
31510 pud = pud_offset(pgd, va);
31511 pmd = pmd_offset(pud, va);
31512- if (!pmd_present(*pmd))
31513+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31514 break;
31515
31516 /* should not be large page here */
31517@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31518
31519 static void __init pagetable_init(void)
31520 {
31521- pgd_t *pgd_base = swapper_pg_dir;
31522-
31523- permanent_kmaps_init(pgd_base);
31524+ permanent_kmaps_init(swapper_pg_dir);
31525 }
31526
31527-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31528+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31529 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31530
31531 /* user-defined highmem size */
31532@@ -772,7 +774,7 @@ void __init mem_init(void)
31533 after_bootmem = 1;
31534
31535 codesize = (unsigned long) &_etext - (unsigned long) &_text;
31536- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
31537+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
31538 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
31539
31540 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
31541@@ -813,10 +815,10 @@ void __init mem_init(void)
31542 ((unsigned long)&__init_end -
31543 (unsigned long)&__init_begin) >> 10,
31544
31545- (unsigned long)&_etext, (unsigned long)&_edata,
31546- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31547+ (unsigned long)&_sdata, (unsigned long)&_edata,
31548+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31549
31550- (unsigned long)&_text, (unsigned long)&_etext,
31551+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31552 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31553
31554 /*
31555@@ -906,6 +908,7 @@ void set_kernel_text_rw(void)
31556 if (!kernel_set_to_readonly)
31557 return;
31558
31559+ start = ktla_ktva(start);
31560 pr_debug("Set kernel text: %lx - %lx for read write\n",
31561 start, start+size);
31562
31563@@ -920,6 +923,7 @@ void set_kernel_text_ro(void)
31564 if (!kernel_set_to_readonly)
31565 return;
31566
31567+ start = ktla_ktva(start);
31568 pr_debug("Set kernel text: %lx - %lx for read only\n",
31569 start, start+size);
31570
31571@@ -948,6 +952,7 @@ void mark_rodata_ro(void)
31572 unsigned long start = PFN_ALIGN(_text);
31573 unsigned long size = PFN_ALIGN(_etext) - start;
31574
31575+ start = ktla_ktva(start);
31576 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31577 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31578 size >> 10);
31579diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31580index bb00c46..bf91a67 100644
31581--- a/arch/x86/mm/init_64.c
31582+++ b/arch/x86/mm/init_64.c
31583@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31584 * around without checking the pgd every time.
31585 */
31586
31587-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31588+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31589 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31590
31591 int force_personality32;
31592@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31593
31594 for (address = start; address <= end; address += PGDIR_SIZE) {
31595 const pgd_t *pgd_ref = pgd_offset_k(address);
31596+
31597+#ifdef CONFIG_PAX_PER_CPU_PGD
31598+ unsigned long cpu;
31599+#else
31600 struct page *page;
31601+#endif
31602
31603 if (pgd_none(*pgd_ref))
31604 continue;
31605
31606 spin_lock(&pgd_lock);
31607+
31608+#ifdef CONFIG_PAX_PER_CPU_PGD
31609+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31610+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31611+
31612+ if (pgd_none(*pgd))
31613+ set_pgd(pgd, *pgd_ref);
31614+ else
31615+ BUG_ON(pgd_page_vaddr(*pgd)
31616+ != pgd_page_vaddr(*pgd_ref));
31617+ pgd = pgd_offset_cpu(cpu, kernel, address);
31618+#else
31619 list_for_each_entry(page, &pgd_list, lru) {
31620 pgd_t *pgd;
31621 spinlock_t *pgt_lock;
31622@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31623 /* the pgt_lock only for Xen */
31624 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31625 spin_lock(pgt_lock);
31626+#endif
31627
31628 if (pgd_none(*pgd))
31629 set_pgd(pgd, *pgd_ref);
31630@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31631 BUG_ON(pgd_page_vaddr(*pgd)
31632 != pgd_page_vaddr(*pgd_ref));
31633
31634+#ifndef CONFIG_PAX_PER_CPU_PGD
31635 spin_unlock(pgt_lock);
31636+#endif
31637+
31638 }
31639 spin_unlock(&pgd_lock);
31640 }
31641@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31642 {
31643 if (pgd_none(*pgd)) {
31644 pud_t *pud = (pud_t *)spp_getpage();
31645- pgd_populate(&init_mm, pgd, pud);
31646+ pgd_populate_kernel(&init_mm, pgd, pud);
31647 if (pud != pud_offset(pgd, 0))
31648 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31649 pud, pud_offset(pgd, 0));
31650@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31651 {
31652 if (pud_none(*pud)) {
31653 pmd_t *pmd = (pmd_t *) spp_getpage();
31654- pud_populate(&init_mm, pud, pmd);
31655+ pud_populate_kernel(&init_mm, pud, pmd);
31656 if (pmd != pmd_offset(pud, 0))
31657 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31658 pmd, pmd_offset(pud, 0));
31659@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31660 pmd = fill_pmd(pud, vaddr);
31661 pte = fill_pte(pmd, vaddr);
31662
31663+ pax_open_kernel();
31664 set_pte(pte, new_pte);
31665+ pax_close_kernel();
31666
31667 /*
31668 * It's enough to flush this one mapping.
31669@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31670 pgd = pgd_offset_k((unsigned long)__va(phys));
31671 if (pgd_none(*pgd)) {
31672 pud = (pud_t *) spp_getpage();
31673- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31674- _PAGE_USER));
31675+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31676 }
31677 pud = pud_offset(pgd, (unsigned long)__va(phys));
31678 if (pud_none(*pud)) {
31679 pmd = (pmd_t *) spp_getpage();
31680- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31681- _PAGE_USER));
31682+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31683 }
31684 pmd = pmd_offset(pud, phys);
31685 BUG_ON(!pmd_none(*pmd));
31686@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31687 prot);
31688
31689 spin_lock(&init_mm.page_table_lock);
31690- pud_populate(&init_mm, pud, pmd);
31691+ pud_populate_kernel(&init_mm, pud, pmd);
31692 spin_unlock(&init_mm.page_table_lock);
31693 }
31694 __flush_tlb_all();
31695@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31696 page_size_mask);
31697
31698 spin_lock(&init_mm.page_table_lock);
31699- pgd_populate(&init_mm, pgd, pud);
31700+ pgd_populate_kernel(&init_mm, pgd, pud);
31701 spin_unlock(&init_mm.page_table_lock);
31702 pgd_changed = true;
31703 }
31704@@ -1221,8 +1242,8 @@ int kern_addr_valid(unsigned long addr)
31705 static struct vm_area_struct gate_vma = {
31706 .vm_start = VSYSCALL_START,
31707 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31708- .vm_page_prot = PAGE_READONLY_EXEC,
31709- .vm_flags = VM_READ | VM_EXEC
31710+ .vm_page_prot = PAGE_READONLY,
31711+ .vm_flags = VM_READ
31712 };
31713
31714 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31715@@ -1256,7 +1277,7 @@ int in_gate_area_no_mm(unsigned long addr)
31716
31717 const char *arch_vma_name(struct vm_area_struct *vma)
31718 {
31719- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31720+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31721 return "[vdso]";
31722 if (vma == &gate_vma)
31723 return "[vsyscall]";
31724diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31725index 7b179b4..6bd17777 100644
31726--- a/arch/x86/mm/iomap_32.c
31727+++ b/arch/x86/mm/iomap_32.c
31728@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31729 type = kmap_atomic_idx_push();
31730 idx = type + KM_TYPE_NR * smp_processor_id();
31731 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31732+
31733+ pax_open_kernel();
31734 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31735+ pax_close_kernel();
31736+
31737 arch_flush_lazy_mmu_mode();
31738
31739 return (void *)vaddr;
31740diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31741index 9a1e658..da003f3 100644
31742--- a/arch/x86/mm/ioremap.c
31743+++ b/arch/x86/mm/ioremap.c
31744@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31745 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31746 int is_ram = page_is_ram(pfn);
31747
31748- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31749+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31750 return NULL;
31751 WARN_ON_ONCE(is_ram);
31752 }
31753@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31754 *
31755 * Caller must ensure there is only one unmapping for the same pointer.
31756 */
31757-void iounmap(volatile void __iomem *addr)
31758+void iounmap(const volatile void __iomem *addr)
31759 {
31760 struct vm_struct *p, *o;
31761
31762@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31763
31764 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31765 if (page_is_ram(start >> PAGE_SHIFT))
31766+#ifdef CONFIG_HIGHMEM
31767+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31768+#endif
31769 return __va(phys);
31770
31771 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31772@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31773 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31774 {
31775 if (page_is_ram(phys >> PAGE_SHIFT))
31776+#ifdef CONFIG_HIGHMEM
31777+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31778+#endif
31779 return;
31780
31781 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31782@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31783 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31784
31785 static __initdata int after_paging_init;
31786-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31787+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31788
31789 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31790 {
31791@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31792 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31793
31794 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31795- memset(bm_pte, 0, sizeof(bm_pte));
31796- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31797+ pmd_populate_user(&init_mm, pmd, bm_pte);
31798
31799 /*
31800 * The boot-ioremap range spans multiple pmds, for which
31801diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31802index d87dd6d..bf3fa66 100644
31803--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31804+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31805@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31806 * memory (e.g. tracked pages)? For now, we need this to avoid
31807 * invoking kmemcheck for PnP BIOS calls.
31808 */
31809- if (regs->flags & X86_VM_MASK)
31810+ if (v8086_mode(regs))
31811 return false;
31812- if (regs->cs != __KERNEL_CS)
31813+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31814 return false;
31815
31816 pte = kmemcheck_pte_lookup(address);
31817diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31818index 5c1ae28..45f4ac9 100644
31819--- a/arch/x86/mm/mmap.c
31820+++ b/arch/x86/mm/mmap.c
31821@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31822 * Leave an at least ~128 MB hole with possible stack randomization.
31823 */
31824 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31825-#define MAX_GAP (TASK_SIZE/6*5)
31826+#define MAX_GAP (pax_task_size/6*5)
31827
31828 static int mmap_is_legacy(void)
31829 {
31830@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31831 return rnd << PAGE_SHIFT;
31832 }
31833
31834-static unsigned long mmap_base(void)
31835+static unsigned long mmap_base(struct mm_struct *mm)
31836 {
31837 unsigned long gap = rlimit(RLIMIT_STACK);
31838+ unsigned long pax_task_size = TASK_SIZE;
31839+
31840+#ifdef CONFIG_PAX_SEGMEXEC
31841+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31842+ pax_task_size = SEGMEXEC_TASK_SIZE;
31843+#endif
31844
31845 if (gap < MIN_GAP)
31846 gap = MIN_GAP;
31847 else if (gap > MAX_GAP)
31848 gap = MAX_GAP;
31849
31850- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31851+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31852 }
31853
31854 /*
31855 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31856 * does, but not when emulating X86_32
31857 */
31858-static unsigned long mmap_legacy_base(void)
31859+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31860 {
31861- if (mmap_is_ia32())
31862+ if (mmap_is_ia32()) {
31863+
31864+#ifdef CONFIG_PAX_SEGMEXEC
31865+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31866+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31867+ else
31868+#endif
31869+
31870 return TASK_UNMAPPED_BASE;
31871- else
31872+ } else
31873 return TASK_UNMAPPED_BASE + mmap_rnd();
31874 }
31875
31876@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31877 */
31878 void arch_pick_mmap_layout(struct mm_struct *mm)
31879 {
31880- mm->mmap_legacy_base = mmap_legacy_base();
31881- mm->mmap_base = mmap_base();
31882+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31883+ mm->mmap_base = mmap_base(mm);
31884+
31885+#ifdef CONFIG_PAX_RANDMMAP
31886+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31887+ mm->mmap_legacy_base += mm->delta_mmap;
31888+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31889+ }
31890+#endif
31891
31892 if (mmap_is_legacy()) {
31893 mm->mmap_base = mm->mmap_legacy_base;
31894diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31895index dc0b727..f612039 100644
31896--- a/arch/x86/mm/mmio-mod.c
31897+++ b/arch/x86/mm/mmio-mod.c
31898@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31899 break;
31900 default:
31901 {
31902- unsigned char *ip = (unsigned char *)instptr;
31903+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31904 my_trace->opcode = MMIO_UNKNOWN_OP;
31905 my_trace->width = 0;
31906 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31907@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31908 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31909 void __iomem *addr)
31910 {
31911- static atomic_t next_id;
31912+ static atomic_unchecked_t next_id;
31913 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31914 /* These are page-unaligned. */
31915 struct mmiotrace_map map = {
31916@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31917 .private = trace
31918 },
31919 .phys = offset,
31920- .id = atomic_inc_return(&next_id)
31921+ .id = atomic_inc_return_unchecked(&next_id)
31922 };
31923 map.map_id = trace->id;
31924
31925@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31926 ioremap_trace_core(offset, size, addr);
31927 }
31928
31929-static void iounmap_trace_core(volatile void __iomem *addr)
31930+static void iounmap_trace_core(const volatile void __iomem *addr)
31931 {
31932 struct mmiotrace_map map = {
31933 .phys = 0,
31934@@ -328,7 +328,7 @@ not_enabled:
31935 }
31936 }
31937
31938-void mmiotrace_iounmap(volatile void __iomem *addr)
31939+void mmiotrace_iounmap(const volatile void __iomem *addr)
31940 {
31941 might_sleep();
31942 if (is_enabled()) /* recheck and proper locking in *_core() */
31943diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31944index a71c4e2..301ae44 100644
31945--- a/arch/x86/mm/numa.c
31946+++ b/arch/x86/mm/numa.c
31947@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31948 return true;
31949 }
31950
31951-static int __init numa_register_memblks(struct numa_meminfo *mi)
31952+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31953 {
31954 unsigned long uninitialized_var(pfn_align);
31955 int i, nid;
31956diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31957index d0b1773..4c3327c 100644
31958--- a/arch/x86/mm/pageattr-test.c
31959+++ b/arch/x86/mm/pageattr-test.c
31960@@ -36,7 +36,7 @@ enum {
31961
31962 static int pte_testbit(pte_t pte)
31963 {
31964- return pte_flags(pte) & _PAGE_UNUSED1;
31965+ return pte_flags(pte) & _PAGE_CPA_TEST;
31966 }
31967
31968 struct split_state {
31969diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31970index bb32480..75f2f5e 100644
31971--- a/arch/x86/mm/pageattr.c
31972+++ b/arch/x86/mm/pageattr.c
31973@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31974 */
31975 #ifdef CONFIG_PCI_BIOS
31976 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31977- pgprot_val(forbidden) |= _PAGE_NX;
31978+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31979 #endif
31980
31981 /*
31982@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31983 * Does not cover __inittext since that is gone later on. On
31984 * 64bit we do not enforce !NX on the low mapping
31985 */
31986- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31987- pgprot_val(forbidden) |= _PAGE_NX;
31988+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31989+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31990
31991+#ifdef CONFIG_DEBUG_RODATA
31992 /*
31993 * The .rodata section needs to be read-only. Using the pfn
31994 * catches all aliases.
31995@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31996 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31997 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31998 pgprot_val(forbidden) |= _PAGE_RW;
31999+#endif
32000
32001 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32002 /*
32003@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32004 }
32005 #endif
32006
32007+#ifdef CONFIG_PAX_KERNEXEC
32008+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32009+ pgprot_val(forbidden) |= _PAGE_RW;
32010+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32011+ }
32012+#endif
32013+
32014 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32015
32016 return prot;
32017@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32018 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32019 {
32020 /* change init_mm */
32021+ pax_open_kernel();
32022 set_pte_atomic(kpte, pte);
32023+
32024 #ifdef CONFIG_X86_32
32025 if (!SHARED_KERNEL_PMD) {
32026+
32027+#ifdef CONFIG_PAX_PER_CPU_PGD
32028+ unsigned long cpu;
32029+#else
32030 struct page *page;
32031+#endif
32032
32033+#ifdef CONFIG_PAX_PER_CPU_PGD
32034+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32035+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32036+#else
32037 list_for_each_entry(page, &pgd_list, lru) {
32038- pgd_t *pgd;
32039+ pgd_t *pgd = (pgd_t *)page_address(page);
32040+#endif
32041+
32042 pud_t *pud;
32043 pmd_t *pmd;
32044
32045- pgd = (pgd_t *)page_address(page) + pgd_index(address);
32046+ pgd += pgd_index(address);
32047 pud = pud_offset(pgd, address);
32048 pmd = pmd_offset(pud, address);
32049 set_pte_atomic((pte_t *)pmd, pte);
32050 }
32051 }
32052 #endif
32053+ pax_close_kernel();
32054 }
32055
32056 static int
32057diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32058index 6574388..87e9bef 100644
32059--- a/arch/x86/mm/pat.c
32060+++ b/arch/x86/mm/pat.c
32061@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
32062
32063 if (!entry) {
32064 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
32065- current->comm, current->pid, start, end - 1);
32066+ current->comm, task_pid_nr(current), start, end - 1);
32067 return -EINVAL;
32068 }
32069
32070@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32071
32072 while (cursor < to) {
32073 if (!devmem_is_allowed(pfn)) {
32074- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
32075- current->comm, from, to - 1);
32076+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
32077+ current->comm, from, to - 1, cursor);
32078 return 0;
32079 }
32080 cursor += PAGE_SIZE;
32081@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
32082 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
32083 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
32084 "for [mem %#010Lx-%#010Lx]\n",
32085- current->comm, current->pid,
32086+ current->comm, task_pid_nr(current),
32087 cattr_name(flags),
32088 base, (unsigned long long)(base + size-1));
32089 return -EINVAL;
32090@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32091 flags = lookup_memtype(paddr);
32092 if (want_flags != flags) {
32093 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
32094- current->comm, current->pid,
32095+ current->comm, task_pid_nr(current),
32096 cattr_name(want_flags),
32097 (unsigned long long)paddr,
32098 (unsigned long long)(paddr + size - 1),
32099@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32100 free_memtype(paddr, paddr + size);
32101 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
32102 " for [mem %#010Lx-%#010Lx], got %s\n",
32103- current->comm, current->pid,
32104+ current->comm, task_pid_nr(current),
32105 cattr_name(want_flags),
32106 (unsigned long long)paddr,
32107 (unsigned long long)(paddr + size - 1),
32108diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
32109index 415f6c4..d319983 100644
32110--- a/arch/x86/mm/pat_rbtree.c
32111+++ b/arch/x86/mm/pat_rbtree.c
32112@@ -160,7 +160,7 @@ success:
32113
32114 failure:
32115 printk(KERN_INFO "%s:%d conflicting memory types "
32116- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
32117+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
32118 end, cattr_name(found_type), cattr_name(match->type));
32119 return -EBUSY;
32120 }
32121diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
32122index 9f0614d..92ae64a 100644
32123--- a/arch/x86/mm/pf_in.c
32124+++ b/arch/x86/mm/pf_in.c
32125@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
32126 int i;
32127 enum reason_type rv = OTHERS;
32128
32129- p = (unsigned char *)ins_addr;
32130+ p = (unsigned char *)ktla_ktva(ins_addr);
32131 p += skip_prefix(p, &prf);
32132 p += get_opcode(p, &opcode);
32133
32134@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
32135 struct prefix_bits prf;
32136 int i;
32137
32138- p = (unsigned char *)ins_addr;
32139+ p = (unsigned char *)ktla_ktva(ins_addr);
32140 p += skip_prefix(p, &prf);
32141 p += get_opcode(p, &opcode);
32142
32143@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
32144 struct prefix_bits prf;
32145 int i;
32146
32147- p = (unsigned char *)ins_addr;
32148+ p = (unsigned char *)ktla_ktva(ins_addr);
32149 p += skip_prefix(p, &prf);
32150 p += get_opcode(p, &opcode);
32151
32152@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
32153 struct prefix_bits prf;
32154 int i;
32155
32156- p = (unsigned char *)ins_addr;
32157+ p = (unsigned char *)ktla_ktva(ins_addr);
32158 p += skip_prefix(p, &prf);
32159 p += get_opcode(p, &opcode);
32160 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
32161@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
32162 struct prefix_bits prf;
32163 int i;
32164
32165- p = (unsigned char *)ins_addr;
32166+ p = (unsigned char *)ktla_ktva(ins_addr);
32167 p += skip_prefix(p, &prf);
32168 p += get_opcode(p, &opcode);
32169 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
32170diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
32171index 17fda6a..f7d54a0 100644
32172--- a/arch/x86/mm/pgtable.c
32173+++ b/arch/x86/mm/pgtable.c
32174@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
32175 list_del(&page->lru);
32176 }
32177
32178-#define UNSHARED_PTRS_PER_PGD \
32179- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32180+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32181+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
32182
32183+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
32184+{
32185+ unsigned int count = USER_PGD_PTRS;
32186
32187+ if (!pax_user_shadow_base)
32188+ return;
32189+
32190+ while (count--)
32191+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
32192+}
32193+#endif
32194+
32195+#ifdef CONFIG_PAX_PER_CPU_PGD
32196+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
32197+{
32198+ unsigned int count = USER_PGD_PTRS;
32199+
32200+ while (count--) {
32201+ pgd_t pgd;
32202+
32203+#ifdef CONFIG_X86_64
32204+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
32205+#else
32206+ pgd = *src++;
32207+#endif
32208+
32209+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32210+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
32211+#endif
32212+
32213+ *dst++ = pgd;
32214+ }
32215+
32216+}
32217+#endif
32218+
32219+#ifdef CONFIG_X86_64
32220+#define pxd_t pud_t
32221+#define pyd_t pgd_t
32222+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
32223+#define pxd_free(mm, pud) pud_free((mm), (pud))
32224+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
32225+#define pyd_offset(mm, address) pgd_offset((mm), (address))
32226+#define PYD_SIZE PGDIR_SIZE
32227+#else
32228+#define pxd_t pmd_t
32229+#define pyd_t pud_t
32230+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
32231+#define pxd_free(mm, pud) pmd_free((mm), (pud))
32232+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
32233+#define pyd_offset(mm, address) pud_offset((mm), (address))
32234+#define PYD_SIZE PUD_SIZE
32235+#endif
32236+
32237+#ifdef CONFIG_PAX_PER_CPU_PGD
32238+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
32239+static inline void pgd_dtor(pgd_t *pgd) {}
32240+#else
32241 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
32242 {
32243 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
32244@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
32245 pgd_list_del(pgd);
32246 spin_unlock(&pgd_lock);
32247 }
32248+#endif
32249
32250 /*
32251 * List of all pgd's needed for non-PAE so it can invalidate entries
32252@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
32253 * -- nyc
32254 */
32255
32256-#ifdef CONFIG_X86_PAE
32257+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
32258 /*
32259 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
32260 * updating the top-level pagetable entries to guarantee the
32261@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
32262 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
32263 * and initialize the kernel pmds here.
32264 */
32265-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
32266+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32267
32268 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32269 {
32270@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32271 */
32272 flush_tlb_mm(mm);
32273 }
32274+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
32275+#define PREALLOCATED_PXDS USER_PGD_PTRS
32276 #else /* !CONFIG_X86_PAE */
32277
32278 /* No need to prepopulate any pagetable entries in non-PAE modes. */
32279-#define PREALLOCATED_PMDS 0
32280+#define PREALLOCATED_PXDS 0
32281
32282 #endif /* CONFIG_X86_PAE */
32283
32284-static void free_pmds(pmd_t *pmds[])
32285+static void free_pxds(pxd_t *pxds[])
32286 {
32287 int i;
32288
32289- for(i = 0; i < PREALLOCATED_PMDS; i++)
32290- if (pmds[i])
32291- free_page((unsigned long)pmds[i]);
32292+ for(i = 0; i < PREALLOCATED_PXDS; i++)
32293+ if (pxds[i])
32294+ free_page((unsigned long)pxds[i]);
32295 }
32296
32297-static int preallocate_pmds(pmd_t *pmds[])
32298+static int preallocate_pxds(pxd_t *pxds[])
32299 {
32300 int i;
32301 bool failed = false;
32302
32303- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32304- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
32305- if (pmd == NULL)
32306+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32307+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
32308+ if (pxd == NULL)
32309 failed = true;
32310- pmds[i] = pmd;
32311+ pxds[i] = pxd;
32312 }
32313
32314 if (failed) {
32315- free_pmds(pmds);
32316+ free_pxds(pxds);
32317 return -ENOMEM;
32318 }
32319
32320@@ -219,51 +279,55 @@ static int preallocate_pmds(pmd_t *pmds[])
32321 * preallocate which never got a corresponding vma will need to be
32322 * freed manually.
32323 */
32324-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
32325+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
32326 {
32327 int i;
32328
32329- for(i = 0; i < PREALLOCATED_PMDS; i++) {
32330+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
32331 pgd_t pgd = pgdp[i];
32332
32333 if (pgd_val(pgd) != 0) {
32334- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
32335+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
32336
32337- pgdp[i] = native_make_pgd(0);
32338+ set_pgd(pgdp + i, native_make_pgd(0));
32339
32340- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
32341- pmd_free(mm, pmd);
32342+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
32343+ pxd_free(mm, pxd);
32344 }
32345 }
32346 }
32347
32348-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
32349+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
32350 {
32351- pud_t *pud;
32352+ pyd_t *pyd;
32353 unsigned long addr;
32354 int i;
32355
32356- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
32357+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
32358 return;
32359
32360- pud = pud_offset(pgd, 0);
32361+#ifdef CONFIG_X86_64
32362+ pyd = pyd_offset(mm, 0L);
32363+#else
32364+ pyd = pyd_offset(pgd, 0L);
32365+#endif
32366
32367- for (addr = i = 0; i < PREALLOCATED_PMDS;
32368- i++, pud++, addr += PUD_SIZE) {
32369- pmd_t *pmd = pmds[i];
32370+ for (addr = i = 0; i < PREALLOCATED_PXDS;
32371+ i++, pyd++, addr += PYD_SIZE) {
32372+ pxd_t *pxd = pxds[i];
32373
32374 if (i >= KERNEL_PGD_BOUNDARY)
32375- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32376- sizeof(pmd_t) * PTRS_PER_PMD);
32377+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32378+ sizeof(pxd_t) * PTRS_PER_PMD);
32379
32380- pud_populate(mm, pud, pmd);
32381+ pyd_populate(mm, pyd, pxd);
32382 }
32383 }
32384
32385 pgd_t *pgd_alloc(struct mm_struct *mm)
32386 {
32387 pgd_t *pgd;
32388- pmd_t *pmds[PREALLOCATED_PMDS];
32389+ pxd_t *pxds[PREALLOCATED_PXDS];
32390
32391 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32392
32393@@ -272,11 +336,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32394
32395 mm->pgd = pgd;
32396
32397- if (preallocate_pmds(pmds) != 0)
32398+ if (preallocate_pxds(pxds) != 0)
32399 goto out_free_pgd;
32400
32401 if (paravirt_pgd_alloc(mm) != 0)
32402- goto out_free_pmds;
32403+ goto out_free_pxds;
32404
32405 /*
32406 * Make sure that pre-populating the pmds is atomic with
32407@@ -286,14 +350,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32408 spin_lock(&pgd_lock);
32409
32410 pgd_ctor(mm, pgd);
32411- pgd_prepopulate_pmd(mm, pgd, pmds);
32412+ pgd_prepopulate_pxd(mm, pgd, pxds);
32413
32414 spin_unlock(&pgd_lock);
32415
32416 return pgd;
32417
32418-out_free_pmds:
32419- free_pmds(pmds);
32420+out_free_pxds:
32421+ free_pxds(pxds);
32422 out_free_pgd:
32423 free_page((unsigned long)pgd);
32424 out:
32425@@ -302,7 +366,7 @@ out:
32426
32427 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32428 {
32429- pgd_mop_up_pmds(mm, pgd);
32430+ pgd_mop_up_pxds(mm, pgd);
32431 pgd_dtor(pgd);
32432 paravirt_pgd_free(mm, pgd);
32433 free_page((unsigned long)pgd);
32434diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32435index a69bcb8..19068ab 100644
32436--- a/arch/x86/mm/pgtable_32.c
32437+++ b/arch/x86/mm/pgtable_32.c
32438@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32439 return;
32440 }
32441 pte = pte_offset_kernel(pmd, vaddr);
32442+
32443+ pax_open_kernel();
32444 if (pte_val(pteval))
32445 set_pte_at(&init_mm, vaddr, pte, pteval);
32446 else
32447 pte_clear(&init_mm, vaddr, pte);
32448+ pax_close_kernel();
32449
32450 /*
32451 * It's enough to flush this one mapping.
32452diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32453index e666cbb..61788c45 100644
32454--- a/arch/x86/mm/physaddr.c
32455+++ b/arch/x86/mm/physaddr.c
32456@@ -10,7 +10,7 @@
32457 #ifdef CONFIG_X86_64
32458
32459 #ifdef CONFIG_DEBUG_VIRTUAL
32460-unsigned long __phys_addr(unsigned long x)
32461+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32462 {
32463 unsigned long y = x - __START_KERNEL_map;
32464
32465@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32466 #else
32467
32468 #ifdef CONFIG_DEBUG_VIRTUAL
32469-unsigned long __phys_addr(unsigned long x)
32470+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32471 {
32472 unsigned long phys_addr = x - PAGE_OFFSET;
32473 /* VMALLOC_* aren't constants */
32474diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32475index 410531d..0f16030 100644
32476--- a/arch/x86/mm/setup_nx.c
32477+++ b/arch/x86/mm/setup_nx.c
32478@@ -5,8 +5,10 @@
32479 #include <asm/pgtable.h>
32480 #include <asm/proto.h>
32481
32482+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32483 static int disable_nx __cpuinitdata;
32484
32485+#ifndef CONFIG_PAX_PAGEEXEC
32486 /*
32487 * noexec = on|off
32488 *
32489@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32490 return 0;
32491 }
32492 early_param("noexec", noexec_setup);
32493+#endif
32494+
32495+#endif
32496
32497 void __cpuinit x86_configure_nx(void)
32498 {
32499+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32500 if (cpu_has_nx && !disable_nx)
32501 __supported_pte_mask |= _PAGE_NX;
32502 else
32503+#endif
32504 __supported_pte_mask &= ~_PAGE_NX;
32505 }
32506
32507diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32508index 282375f..e03a98f 100644
32509--- a/arch/x86/mm/tlb.c
32510+++ b/arch/x86/mm/tlb.c
32511@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32512 BUG();
32513 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32514 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32515+
32516+#ifndef CONFIG_PAX_PER_CPU_PGD
32517 load_cr3(swapper_pg_dir);
32518+#endif
32519+
32520 }
32521 }
32522 EXPORT_SYMBOL_GPL(leave_mm);
32523diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32524new file mode 100644
32525index 0000000..dace51c
32526--- /dev/null
32527+++ b/arch/x86/mm/uderef_64.c
32528@@ -0,0 +1,37 @@
32529+#include <linux/mm.h>
32530+#include <asm/pgtable.h>
32531+#include <asm/uaccess.h>
32532+
32533+#ifdef CONFIG_PAX_MEMORY_UDEREF
32534+/* PaX: due to the special call convention these functions must
32535+ * - remain leaf functions under all configurations,
32536+ * - never be called directly, only dereferenced from the wrappers.
32537+ */
32538+void __pax_open_userland(void)
32539+{
32540+ unsigned int cpu;
32541+
32542+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32543+ return;
32544+
32545+ cpu = raw_get_cpu();
32546+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32547+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32548+ raw_put_cpu_no_resched();
32549+}
32550+EXPORT_SYMBOL(__pax_open_userland);
32551+
32552+void __pax_close_userland(void)
32553+{
32554+ unsigned int cpu;
32555+
32556+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32557+ return;
32558+
32559+ cpu = raw_get_cpu();
32560+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32561+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32562+ raw_put_cpu_no_resched();
32563+}
32564+EXPORT_SYMBOL(__pax_close_userland);
32565+#endif
32566diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32567index 877b9a1..a8ecf42 100644
32568--- a/arch/x86/net/bpf_jit.S
32569+++ b/arch/x86/net/bpf_jit.S
32570@@ -9,6 +9,7 @@
32571 */
32572 #include <linux/linkage.h>
32573 #include <asm/dwarf2.h>
32574+#include <asm/alternative-asm.h>
32575
32576 /*
32577 * Calling convention :
32578@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32579 jle bpf_slow_path_word
32580 mov (SKBDATA,%rsi),%eax
32581 bswap %eax /* ntohl() */
32582+ pax_force_retaddr
32583 ret
32584
32585 sk_load_half:
32586@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32587 jle bpf_slow_path_half
32588 movzwl (SKBDATA,%rsi),%eax
32589 rol $8,%ax # ntohs()
32590+ pax_force_retaddr
32591 ret
32592
32593 sk_load_byte:
32594@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32595 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32596 jle bpf_slow_path_byte
32597 movzbl (SKBDATA,%rsi),%eax
32598+ pax_force_retaddr
32599 ret
32600
32601 /**
32602@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32603 movzbl (SKBDATA,%rsi),%ebx
32604 and $15,%bl
32605 shl $2,%bl
32606+ pax_force_retaddr
32607 ret
32608
32609 /* rsi contains offset and can be scratched */
32610@@ -109,6 +114,7 @@ bpf_slow_path_word:
32611 js bpf_error
32612 mov -12(%rbp),%eax
32613 bswap %eax
32614+ pax_force_retaddr
32615 ret
32616
32617 bpf_slow_path_half:
32618@@ -117,12 +123,14 @@ bpf_slow_path_half:
32619 mov -12(%rbp),%ax
32620 rol $8,%ax
32621 movzwl %ax,%eax
32622+ pax_force_retaddr
32623 ret
32624
32625 bpf_slow_path_byte:
32626 bpf_slow_path_common(1)
32627 js bpf_error
32628 movzbl -12(%rbp),%eax
32629+ pax_force_retaddr
32630 ret
32631
32632 bpf_slow_path_byte_msh:
32633@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32634 and $15,%al
32635 shl $2,%al
32636 xchg %eax,%ebx
32637+ pax_force_retaddr
32638 ret
32639
32640 #define sk_negative_common(SIZE) \
32641@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32642 sk_negative_common(4)
32643 mov (%rax), %eax
32644 bswap %eax
32645+ pax_force_retaddr
32646 ret
32647
32648 bpf_slow_path_half_neg:
32649@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32650 mov (%rax),%ax
32651 rol $8,%ax
32652 movzwl %ax,%eax
32653+ pax_force_retaddr
32654 ret
32655
32656 bpf_slow_path_byte_neg:
32657@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32658 .globl sk_load_byte_negative_offset
32659 sk_negative_common(1)
32660 movzbl (%rax), %eax
32661+ pax_force_retaddr
32662 ret
32663
32664 bpf_slow_path_byte_msh_neg:
32665@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32666 and $15,%al
32667 shl $2,%al
32668 xchg %eax,%ebx
32669+ pax_force_retaddr
32670 ret
32671
32672 bpf_error:
32673@@ -197,4 +210,5 @@ bpf_error:
32674 xor %eax,%eax
32675 mov -8(%rbp),%rbx
32676 leaveq
32677+ pax_force_retaddr
32678 ret
32679diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32680index f66b540..3e88dfb 100644
32681--- a/arch/x86/net/bpf_jit_comp.c
32682+++ b/arch/x86/net/bpf_jit_comp.c
32683@@ -12,6 +12,7 @@
32684 #include <linux/netdevice.h>
32685 #include <linux/filter.h>
32686 #include <linux/if_vlan.h>
32687+#include <linux/random.h>
32688
32689 /*
32690 * Conventions :
32691@@ -49,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32692 return ptr + len;
32693 }
32694
32695+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32696+#define MAX_INSTR_CODE_SIZE 96
32697+#else
32698+#define MAX_INSTR_CODE_SIZE 64
32699+#endif
32700+
32701 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32702
32703 #define EMIT1(b1) EMIT(b1, 1)
32704 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32705 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32706 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32707+
32708+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32709+/* original constant will appear in ecx */
32710+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32711+do { \
32712+ /* mov ecx, randkey */ \
32713+ EMIT1(0xb9); \
32714+ EMIT(_key, 4); \
32715+ /* xor ecx, randkey ^ off */ \
32716+ EMIT2(0x81, 0xf1); \
32717+ EMIT((_key) ^ (_off), 4); \
32718+} while (0)
32719+
32720+#define EMIT1_off32(b1, _off) \
32721+do { \
32722+ switch (b1) { \
32723+ case 0x05: /* add eax, imm32 */ \
32724+ case 0x2d: /* sub eax, imm32 */ \
32725+ case 0x25: /* and eax, imm32 */ \
32726+ case 0x0d: /* or eax, imm32 */ \
32727+ case 0xb8: /* mov eax, imm32 */ \
32728+ case 0x35: /* xor eax, imm32 */ \
32729+ case 0x3d: /* cmp eax, imm32 */ \
32730+ case 0xa9: /* test eax, imm32 */ \
32731+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32732+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32733+ break; \
32734+ case 0xbb: /* mov ebx, imm32 */ \
32735+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32736+ /* mov ebx, ecx */ \
32737+ EMIT2(0x89, 0xcb); \
32738+ break; \
32739+ case 0xbe: /* mov esi, imm32 */ \
32740+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32741+ /* mov esi, ecx */ \
32742+ EMIT2(0x89, 0xce); \
32743+ break; \
32744+ case 0xe8: /* call rel imm32, always to known funcs */ \
32745+ EMIT1(b1); \
32746+ EMIT(_off, 4); \
32747+ break; \
32748+ case 0xe9: /* jmp rel imm32 */ \
32749+ EMIT1(b1); \
32750+ EMIT(_off, 4); \
32751+ /* prevent fall-through, we're not called if off = 0 */ \
32752+ EMIT(0xcccccccc, 4); \
32753+ EMIT(0xcccccccc, 4); \
32754+ break; \
32755+ default: \
32756+ BUILD_BUG(); \
32757+ } \
32758+} while (0)
32759+
32760+#define EMIT2_off32(b1, b2, _off) \
32761+do { \
32762+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32763+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32764+ EMIT(randkey, 4); \
32765+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32766+ EMIT((_off) - randkey, 4); \
32767+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32768+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32769+ /* imul eax, ecx */ \
32770+ EMIT3(0x0f, 0xaf, 0xc1); \
32771+ } else { \
32772+ BUILD_BUG(); \
32773+ } \
32774+} while (0)
32775+#else
32776 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32777+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32778+#endif
32779
32780 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32781 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32782@@ -90,6 +168,24 @@ do { \
32783 #define X86_JBE 0x76
32784 #define X86_JA 0x77
32785
32786+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32787+#define APPEND_FLOW_VERIFY() \
32788+do { \
32789+ /* mov ecx, randkey */ \
32790+ EMIT1(0xb9); \
32791+ EMIT(randkey, 4); \
32792+ /* cmp ecx, randkey */ \
32793+ EMIT2(0x81, 0xf9); \
32794+ EMIT(randkey, 4); \
32795+ /* jz after 8 int 3s */ \
32796+ EMIT2(0x74, 0x08); \
32797+ EMIT(0xcccccccc, 4); \
32798+ EMIT(0xcccccccc, 4); \
32799+} while (0)
32800+#else
32801+#define APPEND_FLOW_VERIFY() do { } while (0)
32802+#endif
32803+
32804 #define EMIT_COND_JMP(op, offset) \
32805 do { \
32806 if (is_near(offset)) \
32807@@ -97,6 +193,7 @@ do { \
32808 else { \
32809 EMIT2(0x0f, op + 0x10); \
32810 EMIT(offset, 4); /* jxx .+off32 */ \
32811+ APPEND_FLOW_VERIFY(); \
32812 } \
32813 } while (0)
32814
32815@@ -121,6 +218,11 @@ static inline void bpf_flush_icache(void *start, void *end)
32816 set_fs(old_fs);
32817 }
32818
32819+struct bpf_jit_work {
32820+ struct work_struct work;
32821+ void *image;
32822+};
32823+
32824 #define CHOOSE_LOAD_FUNC(K, func) \
32825 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
32826
32827@@ -146,7 +248,7 @@ static int pkt_type_offset(void)
32828
32829 void bpf_jit_compile(struct sk_filter *fp)
32830 {
32831- u8 temp[64];
32832+ u8 temp[MAX_INSTR_CODE_SIZE];
32833 u8 *prog;
32834 unsigned int proglen, oldproglen = 0;
32835 int ilen, i;
32836@@ -159,6 +261,9 @@ void bpf_jit_compile(struct sk_filter *fp)
32837 unsigned int *addrs;
32838 const struct sock_filter *filter = fp->insns;
32839 int flen = fp->len;
32840+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32841+ unsigned int randkey;
32842+#endif
32843
32844 if (!bpf_jit_enable)
32845 return;
32846@@ -167,11 +272,19 @@ void bpf_jit_compile(struct sk_filter *fp)
32847 if (addrs == NULL)
32848 return;
32849
32850+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
32851+ if (!fp->work)
32852+ goto out;
32853+
32854+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32855+ randkey = get_random_int();
32856+#endif
32857+
32858 /* Before first pass, make a rough estimation of addrs[]
32859- * each bpf instruction is translated to less than 64 bytes
32860+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32861 */
32862 for (proglen = 0, i = 0; i < flen; i++) {
32863- proglen += 64;
32864+ proglen += MAX_INSTR_CODE_SIZE;
32865 addrs[i] = proglen;
32866 }
32867 cleanup_addr = proglen; /* epilogue address */
32868@@ -282,10 +395,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32869 case BPF_S_ALU_MUL_K: /* A *= K */
32870 if (is_imm8(K))
32871 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32872- else {
32873- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32874- EMIT(K, 4);
32875- }
32876+ else
32877+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32878 break;
32879 case BPF_S_ALU_DIV_X: /* A /= X; */
32880 seen |= SEEN_XREG;
32881@@ -325,13 +436,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32882 break;
32883 case BPF_S_ALU_MOD_K: /* A %= K; */
32884 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32885+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32886+ DILUTE_CONST_SEQUENCE(K, randkey);
32887+#else
32888 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32889+#endif
32890 EMIT2(0xf7, 0xf1); /* div %ecx */
32891 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32892 break;
32893 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32894+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32895+ DILUTE_CONST_SEQUENCE(K, randkey);
32896+ // imul rax, rcx
32897+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32898+#else
32899 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32900 EMIT(K, 4);
32901+#endif
32902 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32903 break;
32904 case BPF_S_ALU_AND_X:
32905@@ -602,8 +723,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32906 if (is_imm8(K)) {
32907 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32908 } else {
32909- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32910- EMIT(K, 4);
32911+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32912 }
32913 } else {
32914 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32915@@ -686,17 +806,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32916 break;
32917 default:
32918 /* hmm, too complex filter, give up with jit compiler */
32919- goto out;
32920+ goto error;
32921 }
32922 ilen = prog - temp;
32923 if (image) {
32924 if (unlikely(proglen + ilen > oldproglen)) {
32925 pr_err("bpb_jit_compile fatal error\n");
32926- kfree(addrs);
32927- module_free(NULL, image);
32928- return;
32929+ module_free_exec(NULL, image);
32930+ goto error;
32931 }
32932+ pax_open_kernel();
32933 memcpy(image + proglen, temp, ilen);
32934+ pax_close_kernel();
32935 }
32936 proglen += ilen;
32937 addrs[i] = proglen;
32938@@ -717,11 +838,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32939 break;
32940 }
32941 if (proglen == oldproglen) {
32942- image = module_alloc(max_t(unsigned int,
32943- proglen,
32944- sizeof(struct work_struct)));
32945+ image = module_alloc_exec(proglen);
32946 if (!image)
32947- goto out;
32948+ goto error;
32949 }
32950 oldproglen = proglen;
32951 }
32952@@ -732,7 +851,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32953 if (image) {
32954 bpf_flush_icache(image, image + proglen);
32955 fp->bpf_func = (void *)image;
32956- }
32957+ } else
32958+error:
32959+ kfree(fp->work);
32960+
32961 out:
32962 kfree(addrs);
32963 return;
32964@@ -740,18 +862,20 @@ out:
32965
32966 static void jit_free_defer(struct work_struct *arg)
32967 {
32968- module_free(NULL, arg);
32969+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
32970+ kfree(arg);
32971 }
32972
32973 /* run from softirq, we must use a work_struct to call
32974- * module_free() from process context
32975+ * module_free_exec() from process context
32976 */
32977 void bpf_jit_free(struct sk_filter *fp)
32978 {
32979 if (fp->bpf_func != sk_run_filter) {
32980- struct work_struct *work = (struct work_struct *)fp->bpf_func;
32981+ struct work_struct *work = &fp->work->work;
32982
32983 INIT_WORK(work, jit_free_defer);
32984+ fp->work->image = fp->bpf_func;
32985 schedule_work(work);
32986 }
32987 }
32988diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32989index d6aa6e8..266395a 100644
32990--- a/arch/x86/oprofile/backtrace.c
32991+++ b/arch/x86/oprofile/backtrace.c
32992@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32993 struct stack_frame_ia32 *fp;
32994 unsigned long bytes;
32995
32996- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32997+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32998 if (bytes != sizeof(bufhead))
32999 return NULL;
33000
33001- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33002+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33003
33004 oprofile_add_trace(bufhead[0].return_address);
33005
33006@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33007 struct stack_frame bufhead[2];
33008 unsigned long bytes;
33009
33010- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33011+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33012 if (bytes != sizeof(bufhead))
33013 return NULL;
33014
33015@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33016 {
33017 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33018
33019- if (!user_mode_vm(regs)) {
33020+ if (!user_mode(regs)) {
33021 unsigned long stack = kernel_stack_pointer(regs);
33022 if (depth)
33023 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33024diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33025index 48768df..ba9143c 100644
33026--- a/arch/x86/oprofile/nmi_int.c
33027+++ b/arch/x86/oprofile/nmi_int.c
33028@@ -23,6 +23,7 @@
33029 #include <asm/nmi.h>
33030 #include <asm/msr.h>
33031 #include <asm/apic.h>
33032+#include <asm/pgtable.h>
33033
33034 #include "op_counter.h"
33035 #include "op_x86_model.h"
33036@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33037 if (ret)
33038 return ret;
33039
33040- if (!model->num_virt_counters)
33041- model->num_virt_counters = model->num_counters;
33042+ if (!model->num_virt_counters) {
33043+ pax_open_kernel();
33044+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
33045+ pax_close_kernel();
33046+ }
33047
33048 mux_init(ops);
33049
33050diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
33051index b2b9443..be58856 100644
33052--- a/arch/x86/oprofile/op_model_amd.c
33053+++ b/arch/x86/oprofile/op_model_amd.c
33054@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
33055 num_counters = AMD64_NUM_COUNTERS;
33056 }
33057
33058- op_amd_spec.num_counters = num_counters;
33059- op_amd_spec.num_controls = num_counters;
33060- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33061+ pax_open_kernel();
33062+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
33063+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
33064+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33065+ pax_close_kernel();
33066
33067 return 0;
33068 }
33069diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
33070index d90528e..0127e2b 100644
33071--- a/arch/x86/oprofile/op_model_ppro.c
33072+++ b/arch/x86/oprofile/op_model_ppro.c
33073@@ -19,6 +19,7 @@
33074 #include <asm/msr.h>
33075 #include <asm/apic.h>
33076 #include <asm/nmi.h>
33077+#include <asm/pgtable.h>
33078
33079 #include "op_x86_model.h"
33080 #include "op_counter.h"
33081@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
33082
33083 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
33084
33085- op_arch_perfmon_spec.num_counters = num_counters;
33086- op_arch_perfmon_spec.num_controls = num_counters;
33087+ pax_open_kernel();
33088+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
33089+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
33090+ pax_close_kernel();
33091 }
33092
33093 static int arch_perfmon_init(struct oprofile_operations *ignore)
33094diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
33095index 71e8a67..6a313bb 100644
33096--- a/arch/x86/oprofile/op_x86_model.h
33097+++ b/arch/x86/oprofile/op_x86_model.h
33098@@ -52,7 +52,7 @@ struct op_x86_model_spec {
33099 void (*switch_ctrl)(struct op_x86_model_spec const *model,
33100 struct op_msrs const * const msrs);
33101 #endif
33102-};
33103+} __do_const;
33104
33105 struct op_counter_config;
33106
33107diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
33108index e9e6ed5..e47ae67 100644
33109--- a/arch/x86/pci/amd_bus.c
33110+++ b/arch/x86/pci/amd_bus.c
33111@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
33112 return NOTIFY_OK;
33113 }
33114
33115-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
33116+static struct notifier_block amd_cpu_notifier = {
33117 .notifier_call = amd_cpu_notify,
33118 };
33119
33120diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
33121index 372e9b8..e775a6c 100644
33122--- a/arch/x86/pci/irq.c
33123+++ b/arch/x86/pci/irq.c
33124@@ -50,7 +50,7 @@ struct irq_router {
33125 struct irq_router_handler {
33126 u16 vendor;
33127 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
33128-};
33129+} __do_const;
33130
33131 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
33132 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
33133@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
33134 return 0;
33135 }
33136
33137-static __initdata struct irq_router_handler pirq_routers[] = {
33138+static __initconst const struct irq_router_handler pirq_routers[] = {
33139 { PCI_VENDOR_ID_INTEL, intel_router_probe },
33140 { PCI_VENDOR_ID_AL, ali_router_probe },
33141 { PCI_VENDOR_ID_ITE, ite_router_probe },
33142@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
33143 static void __init pirq_find_router(struct irq_router *r)
33144 {
33145 struct irq_routing_table *rt = pirq_table;
33146- struct irq_router_handler *h;
33147+ const struct irq_router_handler *h;
33148
33149 #ifdef CONFIG_PCI_BIOS
33150 if (!rt->signature) {
33151@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
33152 return 0;
33153 }
33154
33155-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
33156+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
33157 {
33158 .callback = fix_broken_hp_bios_irq9,
33159 .ident = "HP Pavilion N5400 Series Laptop",
33160diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
33161index 6eb18c4..20d83de 100644
33162--- a/arch/x86/pci/mrst.c
33163+++ b/arch/x86/pci/mrst.c
33164@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
33165 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
33166 pci_mmcfg_late_init();
33167 pcibios_enable_irq = mrst_pci_irq_enable;
33168- pci_root_ops = pci_mrst_ops;
33169+ pax_open_kernel();
33170+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
33171+ pax_close_kernel();
33172 pci_soc_mode = 1;
33173 /* Continue with standard init */
33174 return 1;
33175diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
33176index c77b24a..c979855 100644
33177--- a/arch/x86/pci/pcbios.c
33178+++ b/arch/x86/pci/pcbios.c
33179@@ -79,7 +79,7 @@ union bios32 {
33180 static struct {
33181 unsigned long address;
33182 unsigned short segment;
33183-} bios32_indirect = { 0, __KERNEL_CS };
33184+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
33185
33186 /*
33187 * Returns the entry point for the given service, NULL on error
33188@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
33189 unsigned long length; /* %ecx */
33190 unsigned long entry; /* %edx */
33191 unsigned long flags;
33192+ struct desc_struct d, *gdt;
33193
33194 local_irq_save(flags);
33195- __asm__("lcall *(%%edi); cld"
33196+
33197+ gdt = get_cpu_gdt_table(smp_processor_id());
33198+
33199+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
33200+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33201+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
33202+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33203+
33204+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
33205 : "=a" (return_code),
33206 "=b" (address),
33207 "=c" (length),
33208 "=d" (entry)
33209 : "0" (service),
33210 "1" (0),
33211- "D" (&bios32_indirect));
33212+ "D" (&bios32_indirect),
33213+ "r"(__PCIBIOS_DS)
33214+ : "memory");
33215+
33216+ pax_open_kernel();
33217+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
33218+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
33219+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
33220+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
33221+ pax_close_kernel();
33222+
33223 local_irq_restore(flags);
33224
33225 switch (return_code) {
33226- case 0:
33227- return address + entry;
33228- case 0x80: /* Not present */
33229- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33230- return 0;
33231- default: /* Shouldn't happen */
33232- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33233- service, return_code);
33234+ case 0: {
33235+ int cpu;
33236+ unsigned char flags;
33237+
33238+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
33239+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
33240+ printk(KERN_WARNING "bios32_service: not valid\n");
33241 return 0;
33242+ }
33243+ address = address + PAGE_OFFSET;
33244+ length += 16UL; /* some BIOSs underreport this... */
33245+ flags = 4;
33246+ if (length >= 64*1024*1024) {
33247+ length >>= PAGE_SHIFT;
33248+ flags |= 8;
33249+ }
33250+
33251+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33252+ gdt = get_cpu_gdt_table(cpu);
33253+ pack_descriptor(&d, address, length, 0x9b, flags);
33254+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33255+ pack_descriptor(&d, address, length, 0x93, flags);
33256+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33257+ }
33258+ return entry;
33259+ }
33260+ case 0x80: /* Not present */
33261+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33262+ return 0;
33263+ default: /* Shouldn't happen */
33264+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33265+ service, return_code);
33266+ return 0;
33267 }
33268 }
33269
33270 static struct {
33271 unsigned long address;
33272 unsigned short segment;
33273-} pci_indirect = { 0, __KERNEL_CS };
33274+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
33275
33276-static int pci_bios_present;
33277+static int pci_bios_present __read_only;
33278
33279 static int check_pcibios(void)
33280 {
33281@@ -131,11 +174,13 @@ static int check_pcibios(void)
33282 unsigned long flags, pcibios_entry;
33283
33284 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
33285- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
33286+ pci_indirect.address = pcibios_entry;
33287
33288 local_irq_save(flags);
33289- __asm__(
33290- "lcall *(%%edi); cld\n\t"
33291+ __asm__("movw %w6, %%ds\n\t"
33292+ "lcall *%%ss:(%%edi); cld\n\t"
33293+ "push %%ss\n\t"
33294+ "pop %%ds\n\t"
33295 "jc 1f\n\t"
33296 "xor %%ah, %%ah\n"
33297 "1:"
33298@@ -144,7 +189,8 @@ static int check_pcibios(void)
33299 "=b" (ebx),
33300 "=c" (ecx)
33301 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
33302- "D" (&pci_indirect)
33303+ "D" (&pci_indirect),
33304+ "r" (__PCIBIOS_DS)
33305 : "memory");
33306 local_irq_restore(flags);
33307
33308@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33309
33310 switch (len) {
33311 case 1:
33312- __asm__("lcall *(%%esi); cld\n\t"
33313+ __asm__("movw %w6, %%ds\n\t"
33314+ "lcall *%%ss:(%%esi); cld\n\t"
33315+ "push %%ss\n\t"
33316+ "pop %%ds\n\t"
33317 "jc 1f\n\t"
33318 "xor %%ah, %%ah\n"
33319 "1:"
33320@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33321 : "1" (PCIBIOS_READ_CONFIG_BYTE),
33322 "b" (bx),
33323 "D" ((long)reg),
33324- "S" (&pci_indirect));
33325+ "S" (&pci_indirect),
33326+ "r" (__PCIBIOS_DS));
33327 /*
33328 * Zero-extend the result beyond 8 bits, do not trust the
33329 * BIOS having done it:
33330@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33331 *value &= 0xff;
33332 break;
33333 case 2:
33334- __asm__("lcall *(%%esi); cld\n\t"
33335+ __asm__("movw %w6, %%ds\n\t"
33336+ "lcall *%%ss:(%%esi); cld\n\t"
33337+ "push %%ss\n\t"
33338+ "pop %%ds\n\t"
33339 "jc 1f\n\t"
33340 "xor %%ah, %%ah\n"
33341 "1:"
33342@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33343 : "1" (PCIBIOS_READ_CONFIG_WORD),
33344 "b" (bx),
33345 "D" ((long)reg),
33346- "S" (&pci_indirect));
33347+ "S" (&pci_indirect),
33348+ "r" (__PCIBIOS_DS));
33349 /*
33350 * Zero-extend the result beyond 16 bits, do not trust the
33351 * BIOS having done it:
33352@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33353 *value &= 0xffff;
33354 break;
33355 case 4:
33356- __asm__("lcall *(%%esi); cld\n\t"
33357+ __asm__("movw %w6, %%ds\n\t"
33358+ "lcall *%%ss:(%%esi); cld\n\t"
33359+ "push %%ss\n\t"
33360+ "pop %%ds\n\t"
33361 "jc 1f\n\t"
33362 "xor %%ah, %%ah\n"
33363 "1:"
33364@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33365 : "1" (PCIBIOS_READ_CONFIG_DWORD),
33366 "b" (bx),
33367 "D" ((long)reg),
33368- "S" (&pci_indirect));
33369+ "S" (&pci_indirect),
33370+ "r" (__PCIBIOS_DS));
33371 break;
33372 }
33373
33374@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33375
33376 switch (len) {
33377 case 1:
33378- __asm__("lcall *(%%esi); cld\n\t"
33379+ __asm__("movw %w6, %%ds\n\t"
33380+ "lcall *%%ss:(%%esi); cld\n\t"
33381+ "push %%ss\n\t"
33382+ "pop %%ds\n\t"
33383 "jc 1f\n\t"
33384 "xor %%ah, %%ah\n"
33385 "1:"
33386@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33387 "c" (value),
33388 "b" (bx),
33389 "D" ((long)reg),
33390- "S" (&pci_indirect));
33391+ "S" (&pci_indirect),
33392+ "r" (__PCIBIOS_DS));
33393 break;
33394 case 2:
33395- __asm__("lcall *(%%esi); cld\n\t"
33396+ __asm__("movw %w6, %%ds\n\t"
33397+ "lcall *%%ss:(%%esi); cld\n\t"
33398+ "push %%ss\n\t"
33399+ "pop %%ds\n\t"
33400 "jc 1f\n\t"
33401 "xor %%ah, %%ah\n"
33402 "1:"
33403@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33404 "c" (value),
33405 "b" (bx),
33406 "D" ((long)reg),
33407- "S" (&pci_indirect));
33408+ "S" (&pci_indirect),
33409+ "r" (__PCIBIOS_DS));
33410 break;
33411 case 4:
33412- __asm__("lcall *(%%esi); cld\n\t"
33413+ __asm__("movw %w6, %%ds\n\t"
33414+ "lcall *%%ss:(%%esi); cld\n\t"
33415+ "push %%ss\n\t"
33416+ "pop %%ds\n\t"
33417 "jc 1f\n\t"
33418 "xor %%ah, %%ah\n"
33419 "1:"
33420@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33421 "c" (value),
33422 "b" (bx),
33423 "D" ((long)reg),
33424- "S" (&pci_indirect));
33425+ "S" (&pci_indirect),
33426+ "r" (__PCIBIOS_DS));
33427 break;
33428 }
33429
33430@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33431
33432 DBG("PCI: Fetching IRQ routing table... ");
33433 __asm__("push %%es\n\t"
33434+ "movw %w8, %%ds\n\t"
33435 "push %%ds\n\t"
33436 "pop %%es\n\t"
33437- "lcall *(%%esi); cld\n\t"
33438+ "lcall *%%ss:(%%esi); cld\n\t"
33439 "pop %%es\n\t"
33440+ "push %%ss\n\t"
33441+ "pop %%ds\n"
33442 "jc 1f\n\t"
33443 "xor %%ah, %%ah\n"
33444 "1:"
33445@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33446 "1" (0),
33447 "D" ((long) &opt),
33448 "S" (&pci_indirect),
33449- "m" (opt)
33450+ "m" (opt),
33451+ "r" (__PCIBIOS_DS)
33452 : "memory");
33453 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33454 if (ret & 0xff00)
33455@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33456 {
33457 int ret;
33458
33459- __asm__("lcall *(%%esi); cld\n\t"
33460+ __asm__("movw %w5, %%ds\n\t"
33461+ "lcall *%%ss:(%%esi); cld\n\t"
33462+ "push %%ss\n\t"
33463+ "pop %%ds\n"
33464 "jc 1f\n\t"
33465 "xor %%ah, %%ah\n"
33466 "1:"
33467@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33468 : "0" (PCIBIOS_SET_PCI_HW_INT),
33469 "b" ((dev->bus->number << 8) | dev->devfn),
33470 "c" ((irq << 8) | (pin + 10)),
33471- "S" (&pci_indirect));
33472+ "S" (&pci_indirect),
33473+ "r" (__PCIBIOS_DS));
33474 return !(ret & 0xff00);
33475 }
33476 EXPORT_SYMBOL(pcibios_set_irq_routing);
33477diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33478index 40e4469..d915bf9 100644
33479--- a/arch/x86/platform/efi/efi_32.c
33480+++ b/arch/x86/platform/efi/efi_32.c
33481@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33482 {
33483 struct desc_ptr gdt_descr;
33484
33485+#ifdef CONFIG_PAX_KERNEXEC
33486+ struct desc_struct d;
33487+#endif
33488+
33489 local_irq_save(efi_rt_eflags);
33490
33491 load_cr3(initial_page_table);
33492 __flush_tlb_all();
33493
33494+#ifdef CONFIG_PAX_KERNEXEC
33495+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33496+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33497+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33498+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33499+#endif
33500+
33501 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33502 gdt_descr.size = GDT_SIZE - 1;
33503 load_gdt(&gdt_descr);
33504@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33505 {
33506 struct desc_ptr gdt_descr;
33507
33508+#ifdef CONFIG_PAX_KERNEXEC
33509+ struct desc_struct d;
33510+
33511+ memset(&d, 0, sizeof d);
33512+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33513+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33514+#endif
33515+
33516 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33517 gdt_descr.size = GDT_SIZE - 1;
33518 load_gdt(&gdt_descr);
33519
33520+#ifdef CONFIG_PAX_PER_CPU_PGD
33521+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33522+#else
33523 load_cr3(swapper_pg_dir);
33524+#endif
33525+
33526 __flush_tlb_all();
33527
33528 local_irq_restore(efi_rt_eflags);
33529diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33530index 39a0e7f1..872396e 100644
33531--- a/arch/x86/platform/efi/efi_64.c
33532+++ b/arch/x86/platform/efi/efi_64.c
33533@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33534 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33535 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33536 }
33537+
33538+#ifdef CONFIG_PAX_PER_CPU_PGD
33539+ load_cr3(swapper_pg_dir);
33540+#endif
33541+
33542 __flush_tlb_all();
33543 }
33544
33545@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33546 for (pgd = 0; pgd < n_pgds; pgd++)
33547 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33548 kfree(save_pgd);
33549+
33550+#ifdef CONFIG_PAX_PER_CPU_PGD
33551+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33552+#endif
33553+
33554 __flush_tlb_all();
33555 local_irq_restore(efi_flags);
33556 early_code_mapping_set_exec(0);
33557diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33558index fbe66e6..eae5e38 100644
33559--- a/arch/x86/platform/efi/efi_stub_32.S
33560+++ b/arch/x86/platform/efi/efi_stub_32.S
33561@@ -6,7 +6,9 @@
33562 */
33563
33564 #include <linux/linkage.h>
33565+#include <linux/init.h>
33566 #include <asm/page_types.h>
33567+#include <asm/segment.h>
33568
33569 /*
33570 * efi_call_phys(void *, ...) is a function with variable parameters.
33571@@ -20,7 +22,7 @@
33572 * service functions will comply with gcc calling convention, too.
33573 */
33574
33575-.text
33576+__INIT
33577 ENTRY(efi_call_phys)
33578 /*
33579 * 0. The function can only be called in Linux kernel. So CS has been
33580@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33581 * The mapping of lower virtual memory has been created in prelog and
33582 * epilog.
33583 */
33584- movl $1f, %edx
33585- subl $__PAGE_OFFSET, %edx
33586- jmp *%edx
33587+#ifdef CONFIG_PAX_KERNEXEC
33588+ movl $(__KERNEXEC_EFI_DS), %edx
33589+ mov %edx, %ds
33590+ mov %edx, %es
33591+ mov %edx, %ss
33592+ addl $2f,(1f)
33593+ ljmp *(1f)
33594+
33595+__INITDATA
33596+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33597+.previous
33598+
33599+2:
33600+ subl $2b,(1b)
33601+#else
33602+ jmp 1f-__PAGE_OFFSET
33603 1:
33604+#endif
33605
33606 /*
33607 * 2. Now on the top of stack is the return
33608@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33609 * parameter 2, ..., param n. To make things easy, we save the return
33610 * address of efi_call_phys in a global variable.
33611 */
33612- popl %edx
33613- movl %edx, saved_return_addr
33614- /* get the function pointer into ECX*/
33615- popl %ecx
33616- movl %ecx, efi_rt_function_ptr
33617- movl $2f, %edx
33618- subl $__PAGE_OFFSET, %edx
33619- pushl %edx
33620+ popl (saved_return_addr)
33621+ popl (efi_rt_function_ptr)
33622
33623 /*
33624 * 3. Clear PG bit in %CR0.
33625@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33626 /*
33627 * 5. Call the physical function.
33628 */
33629- jmp *%ecx
33630+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33631
33632-2:
33633 /*
33634 * 6. After EFI runtime service returns, control will return to
33635 * following instruction. We'd better readjust stack pointer first.
33636@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33637 movl %cr0, %edx
33638 orl $0x80000000, %edx
33639 movl %edx, %cr0
33640- jmp 1f
33641-1:
33642+
33643 /*
33644 * 8. Now restore the virtual mode from flat mode by
33645 * adding EIP with PAGE_OFFSET.
33646 */
33647- movl $1f, %edx
33648- jmp *%edx
33649+#ifdef CONFIG_PAX_KERNEXEC
33650+ movl $(__KERNEL_DS), %edx
33651+ mov %edx, %ds
33652+ mov %edx, %es
33653+ mov %edx, %ss
33654+ ljmp $(__KERNEL_CS),$1f
33655+#else
33656+ jmp 1f+__PAGE_OFFSET
33657+#endif
33658 1:
33659
33660 /*
33661 * 9. Balance the stack. And because EAX contain the return value,
33662 * we'd better not clobber it.
33663 */
33664- leal efi_rt_function_ptr, %edx
33665- movl (%edx), %ecx
33666- pushl %ecx
33667+ pushl (efi_rt_function_ptr)
33668
33669 /*
33670- * 10. Push the saved return address onto the stack and return.
33671+ * 10. Return to the saved return address.
33672 */
33673- leal saved_return_addr, %edx
33674- movl (%edx), %ecx
33675- pushl %ecx
33676- ret
33677+ jmpl *(saved_return_addr)
33678 ENDPROC(efi_call_phys)
33679 .previous
33680
33681-.data
33682+__INITDATA
33683 saved_return_addr:
33684 .long 0
33685 efi_rt_function_ptr:
33686diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33687index 4c07cca..2c8427d 100644
33688--- a/arch/x86/platform/efi/efi_stub_64.S
33689+++ b/arch/x86/platform/efi/efi_stub_64.S
33690@@ -7,6 +7,7 @@
33691 */
33692
33693 #include <linux/linkage.h>
33694+#include <asm/alternative-asm.h>
33695
33696 #define SAVE_XMM \
33697 mov %rsp, %rax; \
33698@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33699 call *%rdi
33700 addq $32, %rsp
33701 RESTORE_XMM
33702+ pax_force_retaddr 0, 1
33703 ret
33704 ENDPROC(efi_call0)
33705
33706@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33707 call *%rdi
33708 addq $32, %rsp
33709 RESTORE_XMM
33710+ pax_force_retaddr 0, 1
33711 ret
33712 ENDPROC(efi_call1)
33713
33714@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33715 call *%rdi
33716 addq $32, %rsp
33717 RESTORE_XMM
33718+ pax_force_retaddr 0, 1
33719 ret
33720 ENDPROC(efi_call2)
33721
33722@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33723 call *%rdi
33724 addq $32, %rsp
33725 RESTORE_XMM
33726+ pax_force_retaddr 0, 1
33727 ret
33728 ENDPROC(efi_call3)
33729
33730@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33731 call *%rdi
33732 addq $32, %rsp
33733 RESTORE_XMM
33734+ pax_force_retaddr 0, 1
33735 ret
33736 ENDPROC(efi_call4)
33737
33738@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33739 call *%rdi
33740 addq $48, %rsp
33741 RESTORE_XMM
33742+ pax_force_retaddr 0, 1
33743 ret
33744 ENDPROC(efi_call5)
33745
33746@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33747 call *%rdi
33748 addq $48, %rsp
33749 RESTORE_XMM
33750+ pax_force_retaddr 0, 1
33751 ret
33752 ENDPROC(efi_call6)
33753diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33754index a0a0a43..a48e233 100644
33755--- a/arch/x86/platform/mrst/mrst.c
33756+++ b/arch/x86/platform/mrst/mrst.c
33757@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33758 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33759 int sfi_mrtc_num;
33760
33761-static void mrst_power_off(void)
33762+static __noreturn void mrst_power_off(void)
33763 {
33764+ BUG();
33765 }
33766
33767-static void mrst_reboot(void)
33768+static __noreturn void mrst_reboot(void)
33769 {
33770 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33771+ BUG();
33772 }
33773
33774 /* parse all the mtimer info to a static mtimer array */
33775diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33776index d6ee929..3637cb5 100644
33777--- a/arch/x86/platform/olpc/olpc_dt.c
33778+++ b/arch/x86/platform/olpc/olpc_dt.c
33779@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33780 return res;
33781 }
33782
33783-static struct of_pdt_ops prom_olpc_ops __initdata = {
33784+static struct of_pdt_ops prom_olpc_ops __initconst = {
33785 .nextprop = olpc_dt_nextprop,
33786 .getproplen = olpc_dt_getproplen,
33787 .getproperty = olpc_dt_getproperty,
33788diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33789index 1cf5b30..fd45732 100644
33790--- a/arch/x86/power/cpu.c
33791+++ b/arch/x86/power/cpu.c
33792@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33793 static void fix_processor_context(void)
33794 {
33795 int cpu = smp_processor_id();
33796- struct tss_struct *t = &per_cpu(init_tss, cpu);
33797-#ifdef CONFIG_X86_64
33798- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33799- tss_desc tss;
33800-#endif
33801+ struct tss_struct *t = init_tss + cpu;
33802+
33803 set_tss_desc(cpu, t); /*
33804 * This just modifies memory; should not be
33805 * necessary. But... This is necessary, because
33806@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33807 */
33808
33809 #ifdef CONFIG_X86_64
33810- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33811- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33812- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33813-
33814 syscall_init(); /* This sets MSR_*STAR and related */
33815 #endif
33816 load_TR_desc(); /* This does ltr */
33817diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33818index a44f457..9140171 100644
33819--- a/arch/x86/realmode/init.c
33820+++ b/arch/x86/realmode/init.c
33821@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33822 __va(real_mode_header->trampoline_header);
33823
33824 #ifdef CONFIG_X86_32
33825- trampoline_header->start = __pa_symbol(startup_32_smp);
33826+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33827+
33828+#ifdef CONFIG_PAX_KERNEXEC
33829+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33830+#endif
33831+
33832+ trampoline_header->boot_cs = __BOOT_CS;
33833 trampoline_header->gdt_limit = __BOOT_DS + 7;
33834 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33835 #else
33836@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33837 *trampoline_cr4_features = read_cr4();
33838
33839 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33840- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33841+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33842 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33843 #endif
33844 }
33845diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33846index 8869287..d577672 100644
33847--- a/arch/x86/realmode/rm/Makefile
33848+++ b/arch/x86/realmode/rm/Makefile
33849@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33850 $(call cc-option, -fno-unit-at-a-time)) \
33851 $(call cc-option, -fno-stack-protector) \
33852 $(call cc-option, -mpreferred-stack-boundary=2)
33853+ifdef CONSTIFY_PLUGIN
33854+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33855+endif
33856 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33857 GCOV_PROFILE := n
33858diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33859index a28221d..93c40f1 100644
33860--- a/arch/x86/realmode/rm/header.S
33861+++ b/arch/x86/realmode/rm/header.S
33862@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33863 #endif
33864 /* APM/BIOS reboot */
33865 .long pa_machine_real_restart_asm
33866-#ifdef CONFIG_X86_64
33867+#ifdef CONFIG_X86_32
33868+ .long __KERNEL_CS
33869+#else
33870 .long __KERNEL32_CS
33871 #endif
33872 END(real_mode_header)
33873diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33874index c1b2791..f9e31c7 100644
33875--- a/arch/x86/realmode/rm/trampoline_32.S
33876+++ b/arch/x86/realmode/rm/trampoline_32.S
33877@@ -25,6 +25,12 @@
33878 #include <asm/page_types.h>
33879 #include "realmode.h"
33880
33881+#ifdef CONFIG_PAX_KERNEXEC
33882+#define ta(X) (X)
33883+#else
33884+#define ta(X) (pa_ ## X)
33885+#endif
33886+
33887 .text
33888 .code16
33889
33890@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33891
33892 cli # We should be safe anyway
33893
33894- movl tr_start, %eax # where we need to go
33895-
33896 movl $0xA5A5A5A5, trampoline_status
33897 # write marker for master knows we're running
33898
33899@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33900 movw $1, %dx # protected mode (PE) bit
33901 lmsw %dx # into protected mode
33902
33903- ljmpl $__BOOT_CS, $pa_startup_32
33904+ ljmpl *(trampoline_header)
33905
33906 .section ".text32","ax"
33907 .code32
33908@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33909 .balign 8
33910 GLOBAL(trampoline_header)
33911 tr_start: .space 4
33912- tr_gdt_pad: .space 2
33913+ tr_boot_cs: .space 2
33914 tr_gdt: .space 6
33915 END(trampoline_header)
33916
33917diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33918index bb360dc..d0fd8f8 100644
33919--- a/arch/x86/realmode/rm/trampoline_64.S
33920+++ b/arch/x86/realmode/rm/trampoline_64.S
33921@@ -94,6 +94,7 @@ ENTRY(startup_32)
33922 movl %edx, %gs
33923
33924 movl pa_tr_cr4, %eax
33925+ andl $~X86_CR4_PCIDE, %eax
33926 movl %eax, %cr4 # Enable PAE mode
33927
33928 # Setup trampoline 4 level pagetables
33929@@ -107,7 +108,7 @@ ENTRY(startup_32)
33930 wrmsr
33931
33932 # Enable paging and in turn activate Long Mode
33933- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33934+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33935 movl %eax, %cr0
33936
33937 /*
33938diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33939index e812034..c747134 100644
33940--- a/arch/x86/tools/Makefile
33941+++ b/arch/x86/tools/Makefile
33942@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33943
33944 $(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
33945
33946-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33947+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33948 hostprogs-y += relocs
33949 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33950 relocs: $(obj)/relocs
33951diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33952index f7bab68..b6d9886 100644
33953--- a/arch/x86/tools/relocs.c
33954+++ b/arch/x86/tools/relocs.c
33955@@ -1,5 +1,7 @@
33956 /* This is included from relocs_32/64.c */
33957
33958+#include "../../../include/generated/autoconf.h"
33959+
33960 #define ElfW(type) _ElfW(ELF_BITS, type)
33961 #define _ElfW(bits, type) __ElfW(bits, type)
33962 #define __ElfW(bits, type) Elf##bits##_##type
33963@@ -11,6 +13,7 @@
33964 #define Elf_Sym ElfW(Sym)
33965
33966 static Elf_Ehdr ehdr;
33967+static Elf_Phdr *phdr;
33968
33969 struct relocs {
33970 uint32_t *offset;
33971@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33972 }
33973 }
33974
33975+static void read_phdrs(FILE *fp)
33976+{
33977+ unsigned int i;
33978+
33979+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33980+ if (!phdr) {
33981+ die("Unable to allocate %d program headers\n",
33982+ ehdr.e_phnum);
33983+ }
33984+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33985+ die("Seek to %d failed: %s\n",
33986+ ehdr.e_phoff, strerror(errno));
33987+ }
33988+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33989+ die("Cannot read ELF program headers: %s\n",
33990+ strerror(errno));
33991+ }
33992+ for(i = 0; i < ehdr.e_phnum; i++) {
33993+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33994+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33995+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33996+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33997+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33998+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33999+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34000+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34001+ }
34002+
34003+}
34004+
34005 static void read_shdrs(FILE *fp)
34006 {
34007- int i;
34008+ unsigned int i;
34009 Elf_Shdr shdr;
34010
34011 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34012@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34013
34014 static void read_strtabs(FILE *fp)
34015 {
34016- int i;
34017+ unsigned int i;
34018 for (i = 0; i < ehdr.e_shnum; i++) {
34019 struct section *sec = &secs[i];
34020 if (sec->shdr.sh_type != SHT_STRTAB) {
34021@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34022
34023 static void read_symtabs(FILE *fp)
34024 {
34025- int i,j;
34026+ unsigned int i,j;
34027 for (i = 0; i < ehdr.e_shnum; i++) {
34028 struct section *sec = &secs[i];
34029 if (sec->shdr.sh_type != SHT_SYMTAB) {
34030@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34031 }
34032
34033
34034-static void read_relocs(FILE *fp)
34035+static void read_relocs(FILE *fp, int use_real_mode)
34036 {
34037- int i,j;
34038+ unsigned int i,j;
34039+ uint32_t base;
34040+
34041 for (i = 0; i < ehdr.e_shnum; i++) {
34042 struct section *sec = &secs[i];
34043 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34044@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34045 die("Cannot read symbol table: %s\n",
34046 strerror(errno));
34047 }
34048+ base = 0;
34049+
34050+#ifdef CONFIG_X86_32
34051+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34052+ if (phdr[j].p_type != PT_LOAD )
34053+ continue;
34054+ 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)
34055+ continue;
34056+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34057+ break;
34058+ }
34059+#endif
34060+
34061 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34062 Elf_Rel *rel = &sec->reltab[j];
34063- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34064+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34065 rel->r_info = elf_xword_to_cpu(rel->r_info);
34066 #if (SHT_REL_TYPE == SHT_RELA)
34067 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
34068@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
34069
34070 static void print_absolute_symbols(void)
34071 {
34072- int i;
34073+ unsigned int i;
34074 const char *format;
34075
34076 if (ELF_BITS == 64)
34077@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
34078 for (i = 0; i < ehdr.e_shnum; i++) {
34079 struct section *sec = &secs[i];
34080 char *sym_strtab;
34081- int j;
34082+ unsigned int j;
34083
34084 if (sec->shdr.sh_type != SHT_SYMTAB) {
34085 continue;
34086@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
34087
34088 static void print_absolute_relocs(void)
34089 {
34090- int i, printed = 0;
34091+ unsigned int i, printed = 0;
34092 const char *format;
34093
34094 if (ELF_BITS == 64)
34095@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
34096 struct section *sec_applies, *sec_symtab;
34097 char *sym_strtab;
34098 Elf_Sym *sh_symtab;
34099- int j;
34100+ unsigned int j;
34101 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34102 continue;
34103 }
34104@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
34105 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
34106 Elf_Sym *sym, const char *symname))
34107 {
34108- int i;
34109+ unsigned int i;
34110 /* Walk through the relocations */
34111 for (i = 0; i < ehdr.e_shnum; i++) {
34112 char *sym_strtab;
34113 Elf_Sym *sh_symtab;
34114 struct section *sec_applies, *sec_symtab;
34115- int j;
34116+ unsigned int j;
34117 struct section *sec = &secs[i];
34118
34119 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34120@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34121 {
34122 unsigned r_type = ELF32_R_TYPE(rel->r_info);
34123 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
34124+ char *sym_strtab = sec->link->link->strtab;
34125+
34126+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
34127+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
34128+ return 0;
34129+
34130+#ifdef CONFIG_PAX_KERNEXEC
34131+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
34132+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
34133+ return 0;
34134+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
34135+ return 0;
34136+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
34137+ return 0;
34138+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
34139+ return 0;
34140+#endif
34141
34142 switch (r_type) {
34143 case R_386_NONE:
34144@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
34145
34146 static void emit_relocs(int as_text, int use_real_mode)
34147 {
34148- int i;
34149+ unsigned int i;
34150 int (*write_reloc)(uint32_t, FILE *) = write32;
34151 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34152 const char *symname);
34153@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
34154 {
34155 regex_init(use_real_mode);
34156 read_ehdr(fp);
34157+ read_phdrs(fp);
34158 read_shdrs(fp);
34159 read_strtabs(fp);
34160 read_symtabs(fp);
34161- read_relocs(fp);
34162+ read_relocs(fp, use_real_mode);
34163 if (ELF_BITS == 64)
34164 percpu_init();
34165 if (show_absolute_syms) {
34166diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
34167index 80ffa5b..a33bd15 100644
34168--- a/arch/x86/um/tls_32.c
34169+++ b/arch/x86/um/tls_32.c
34170@@ -260,7 +260,7 @@ out:
34171 if (unlikely(task == current &&
34172 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
34173 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
34174- "without flushed TLS.", current->pid);
34175+ "without flushed TLS.", task_pid_nr(current));
34176 }
34177
34178 return 0;
34179diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
34180index fd14be1..e3c79c0 100644
34181--- a/arch/x86/vdso/Makefile
34182+++ b/arch/x86/vdso/Makefile
34183@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
34184 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
34185 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
34186
34187-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34188+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34189 GCOV_PROFILE := n
34190
34191 #
34192diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
34193index 0faad64..39ef157 100644
34194--- a/arch/x86/vdso/vdso32-setup.c
34195+++ b/arch/x86/vdso/vdso32-setup.c
34196@@ -25,6 +25,7 @@
34197 #include <asm/tlbflush.h>
34198 #include <asm/vdso.h>
34199 #include <asm/proto.h>
34200+#include <asm/mman.h>
34201
34202 enum {
34203 VDSO_DISABLED = 0,
34204@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
34205 void enable_sep_cpu(void)
34206 {
34207 int cpu = get_cpu();
34208- struct tss_struct *tss = &per_cpu(init_tss, cpu);
34209+ struct tss_struct *tss = init_tss + cpu;
34210
34211 if (!boot_cpu_has(X86_FEATURE_SEP)) {
34212 put_cpu();
34213@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
34214 gate_vma.vm_start = FIXADDR_USER_START;
34215 gate_vma.vm_end = FIXADDR_USER_END;
34216 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
34217- gate_vma.vm_page_prot = __P101;
34218+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
34219
34220 return 0;
34221 }
34222@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34223 if (compat)
34224 addr = VDSO_HIGH_BASE;
34225 else {
34226- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
34227+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
34228 if (IS_ERR_VALUE(addr)) {
34229 ret = addr;
34230 goto up_fail;
34231 }
34232 }
34233
34234- current->mm->context.vdso = (void *)addr;
34235+ current->mm->context.vdso = addr;
34236
34237 if (compat_uses_vma || !compat) {
34238 /*
34239@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34240 }
34241
34242 current_thread_info()->sysenter_return =
34243- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34244+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34245
34246 up_fail:
34247 if (ret)
34248- current->mm->context.vdso = NULL;
34249+ current->mm->context.vdso = 0;
34250
34251 up_write(&mm->mmap_sem);
34252
34253@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
34254
34255 const char *arch_vma_name(struct vm_area_struct *vma)
34256 {
34257- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
34258+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
34259 return "[vdso]";
34260+
34261+#ifdef CONFIG_PAX_SEGMEXEC
34262+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
34263+ return "[vdso]";
34264+#endif
34265+
34266 return NULL;
34267 }
34268
34269@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
34270 * Check to see if the corresponding task was created in compat vdso
34271 * mode.
34272 */
34273- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
34274+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
34275 return &gate_vma;
34276 return NULL;
34277 }
34278diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
34279index 431e875..cbb23f3 100644
34280--- a/arch/x86/vdso/vma.c
34281+++ b/arch/x86/vdso/vma.c
34282@@ -16,8 +16,6 @@
34283 #include <asm/vdso.h>
34284 #include <asm/page.h>
34285
34286-unsigned int __read_mostly vdso_enabled = 1;
34287-
34288 extern char vdso_start[], vdso_end[];
34289 extern unsigned short vdso_sync_cpuid;
34290
34291@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
34292 * unaligned here as a result of stack start randomization.
34293 */
34294 addr = PAGE_ALIGN(addr);
34295- addr = align_vdso_addr(addr);
34296
34297 return addr;
34298 }
34299@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
34300 unsigned size)
34301 {
34302 struct mm_struct *mm = current->mm;
34303- unsigned long addr;
34304+ unsigned long addr = 0;
34305 int ret;
34306
34307- if (!vdso_enabled)
34308- return 0;
34309-
34310 down_write(&mm->mmap_sem);
34311+
34312+#ifdef CONFIG_PAX_RANDMMAP
34313+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34314+#endif
34315+
34316 addr = vdso_addr(mm->start_stack, size);
34317+ addr = align_vdso_addr(addr);
34318 addr = get_unmapped_area(NULL, addr, size, 0, 0);
34319 if (IS_ERR_VALUE(addr)) {
34320 ret = addr;
34321 goto up_fail;
34322 }
34323
34324- current->mm->context.vdso = (void *)addr;
34325+ mm->context.vdso = addr;
34326
34327 ret = install_special_mapping(mm, addr, size,
34328 VM_READ|VM_EXEC|
34329 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
34330 pages);
34331- if (ret) {
34332- current->mm->context.vdso = NULL;
34333- goto up_fail;
34334- }
34335+ if (ret)
34336+ mm->context.vdso = 0;
34337
34338 up_fail:
34339 up_write(&mm->mmap_sem);
34340@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34341 vdsox32_size);
34342 }
34343 #endif
34344-
34345-static __init int vdso_setup(char *s)
34346-{
34347- vdso_enabled = simple_strtoul(s, NULL, 0);
34348- return 0;
34349-}
34350-__setup("vdso=", vdso_setup);
34351diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
34352index a492be2..08678da 100644
34353--- a/arch/x86/xen/enlighten.c
34354+++ b/arch/x86/xen/enlighten.c
34355@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
34356
34357 struct shared_info xen_dummy_shared_info;
34358
34359-void *xen_initial_gdt;
34360-
34361 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
34362 __read_mostly int xen_have_vector_callback;
34363 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
34364@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
34365 {
34366 unsigned long va = dtr->address;
34367 unsigned int size = dtr->size + 1;
34368- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34369- unsigned long frames[pages];
34370+ unsigned long frames[65536 / PAGE_SIZE];
34371 int f;
34372
34373 /*
34374@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34375 {
34376 unsigned long va = dtr->address;
34377 unsigned int size = dtr->size + 1;
34378- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34379- unsigned long frames[pages];
34380+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
34381 int f;
34382
34383 /*
34384@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34385 * 8-byte entries, or 16 4k pages..
34386 */
34387
34388- BUG_ON(size > 65536);
34389+ BUG_ON(size > GDT_SIZE);
34390 BUG_ON(va & ~PAGE_MASK);
34391
34392 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34393@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34394 return 0;
34395 }
34396
34397-static void set_xen_basic_apic_ops(void)
34398+static void __init set_xen_basic_apic_ops(void)
34399 {
34400 apic->read = xen_apic_read;
34401 apic->write = xen_apic_write;
34402@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34403 #endif
34404 };
34405
34406-static void xen_reboot(int reason)
34407+static __noreturn void xen_reboot(int reason)
34408 {
34409 struct sched_shutdown r = { .reason = reason };
34410
34411- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34412- BUG();
34413+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34414+ BUG();
34415 }
34416
34417-static void xen_restart(char *msg)
34418+static __noreturn void xen_restart(char *msg)
34419 {
34420 xen_reboot(SHUTDOWN_reboot);
34421 }
34422
34423-static void xen_emergency_restart(void)
34424+static __noreturn void xen_emergency_restart(void)
34425 {
34426 xen_reboot(SHUTDOWN_reboot);
34427 }
34428
34429-static void xen_machine_halt(void)
34430+static __noreturn void xen_machine_halt(void)
34431 {
34432 xen_reboot(SHUTDOWN_poweroff);
34433 }
34434
34435-static void xen_machine_power_off(void)
34436+static __noreturn void xen_machine_power_off(void)
34437 {
34438 if (pm_power_off)
34439 pm_power_off();
34440@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
34441 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34442
34443 /* Work out if we support NX */
34444- x86_configure_nx();
34445+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34446+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34447+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34448+ unsigned l, h;
34449+
34450+ __supported_pte_mask |= _PAGE_NX;
34451+ rdmsr(MSR_EFER, l, h);
34452+ l |= EFER_NX;
34453+ wrmsr(MSR_EFER, l, h);
34454+ }
34455+#endif
34456
34457 xen_setup_features();
34458
34459@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
34460
34461 machine_ops = xen_machine_ops;
34462
34463- /*
34464- * The only reliable way to retain the initial address of the
34465- * percpu gdt_page is to remember it here, so we can go and
34466- * mark it RW later, when the initial percpu area is freed.
34467- */
34468- xen_initial_gdt = &per_cpu(gdt_page, 0);
34469-
34470 xen_smp_init();
34471
34472 #ifdef CONFIG_ACPI_NUMA
34473@@ -1700,7 +1699,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
34474 return NOTIFY_OK;
34475 }
34476
34477-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
34478+static struct notifier_block xen_hvm_cpu_notifier = {
34479 .notifier_call = xen_hvm_cpu_notify,
34480 };
34481
34482diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34483index fdc3ba2..3daee39 100644
34484--- a/arch/x86/xen/mmu.c
34485+++ b/arch/x86/xen/mmu.c
34486@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34487 /* L3_k[510] -> level2_kernel_pgt
34488 * L3_i[511] -> level2_fixmap_pgt */
34489 convert_pfn_mfn(level3_kernel_pgt);
34490+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34491+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34492+ convert_pfn_mfn(level3_vmemmap_pgt);
34493
34494 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34495 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34496@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34497 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34498 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34499 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34500+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34501+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34502+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34503 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34504 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34505+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34506 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34507 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34508
34509@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34510 pv_mmu_ops.set_pud = xen_set_pud;
34511 #if PAGETABLE_LEVELS == 4
34512 pv_mmu_ops.set_pgd = xen_set_pgd;
34513+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34514 #endif
34515
34516 /* This will work as long as patching hasn't happened yet
34517@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34518 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34519 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34520 .set_pgd = xen_set_pgd_hyper,
34521+ .set_pgd_batched = xen_set_pgd_hyper,
34522
34523 .alloc_pud = xen_alloc_pmd_init,
34524 .release_pud = xen_release_pmd_init,
34525diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34526index a1e58e1..9392ad8 100644
34527--- a/arch/x86/xen/smp.c
34528+++ b/arch/x86/xen/smp.c
34529@@ -240,11 +240,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
34530 {
34531 BUG_ON(smp_processor_id() != 0);
34532 native_smp_prepare_boot_cpu();
34533-
34534- /* We've switched to the "real" per-cpu gdt, so make sure the
34535- old memory can be recycled */
34536- make_lowmem_page_readwrite(xen_initial_gdt);
34537-
34538 xen_filter_cpu_maps();
34539 xen_setup_vcpu_info_placement();
34540 }
34541@@ -314,7 +309,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34542 ctxt->user_regs.ss = __KERNEL_DS;
34543 #ifdef CONFIG_X86_32
34544 ctxt->user_regs.fs = __KERNEL_PERCPU;
34545- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34546+ savesegment(gs, ctxt->user_regs.gs);
34547 #else
34548 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34549 #endif
34550@@ -324,8 +319,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34551
34552 {
34553 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34554- ctxt->user_regs.ds = __USER_DS;
34555- ctxt->user_regs.es = __USER_DS;
34556+ ctxt->user_regs.ds = __KERNEL_DS;
34557+ ctxt->user_regs.es = __KERNEL_DS;
34558
34559 xen_copy_trap_info(ctxt->trap_ctxt);
34560
34561@@ -370,13 +365,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34562 int rc;
34563
34564 per_cpu(current_task, cpu) = idle;
34565+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34566 #ifdef CONFIG_X86_32
34567 irq_ctx_init(cpu);
34568 #else
34569 clear_tsk_thread_flag(idle, TIF_FORK);
34570- per_cpu(kernel_stack, cpu) =
34571- (unsigned long)task_stack_page(idle) -
34572- KERNEL_STACK_OFFSET + THREAD_SIZE;
34573+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34574 #endif
34575 xen_setup_runstate_info(cpu);
34576 xen_setup_timer(cpu);
34577@@ -651,7 +645,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34578
34579 void __init xen_smp_init(void)
34580 {
34581- smp_ops = xen_smp_ops;
34582+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34583 xen_fill_possible_map();
34584 xen_init_spinlocks();
34585 }
34586diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34587index 33ca6e4..0ded929 100644
34588--- a/arch/x86/xen/xen-asm_32.S
34589+++ b/arch/x86/xen/xen-asm_32.S
34590@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34591 ESP_OFFSET=4 # bytes pushed onto stack
34592
34593 /*
34594- * Store vcpu_info pointer for easy access. Do it this way to
34595- * avoid having to reload %fs
34596+ * Store vcpu_info pointer for easy access.
34597 */
34598 #ifdef CONFIG_SMP
34599- GET_THREAD_INFO(%eax)
34600- movl %ss:TI_cpu(%eax), %eax
34601- movl %ss:__per_cpu_offset(,%eax,4), %eax
34602- mov %ss:xen_vcpu(%eax), %eax
34603+ push %fs
34604+ mov $(__KERNEL_PERCPU), %eax
34605+ mov %eax, %fs
34606+ mov PER_CPU_VAR(xen_vcpu), %eax
34607+ pop %fs
34608 #else
34609 movl %ss:xen_vcpu, %eax
34610 #endif
34611diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34612index 7faed58..ba4427c 100644
34613--- a/arch/x86/xen/xen-head.S
34614+++ b/arch/x86/xen/xen-head.S
34615@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34616 #ifdef CONFIG_X86_32
34617 mov %esi,xen_start_info
34618 mov $init_thread_union+THREAD_SIZE,%esp
34619+#ifdef CONFIG_SMP
34620+ movl $cpu_gdt_table,%edi
34621+ movl $__per_cpu_load,%eax
34622+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34623+ rorl $16,%eax
34624+ movb %al,__KERNEL_PERCPU + 4(%edi)
34625+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34626+ movl $__per_cpu_end - 1,%eax
34627+ subl $__per_cpu_start,%eax
34628+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34629+#endif
34630 #else
34631 mov %rsi,xen_start_info
34632 mov $init_thread_union+THREAD_SIZE,%rsp
34633diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34634index a95b417..b6dbd0b 100644
34635--- a/arch/x86/xen/xen-ops.h
34636+++ b/arch/x86/xen/xen-ops.h
34637@@ -10,8 +10,6 @@
34638 extern const char xen_hypervisor_callback[];
34639 extern const char xen_failsafe_callback[];
34640
34641-extern void *xen_initial_gdt;
34642-
34643 struct trap_info;
34644 void xen_copy_trap_info(struct trap_info *traps);
34645
34646diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34647index 525bd3d..ef888b1 100644
34648--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34649+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34650@@ -119,9 +119,9 @@
34651 ----------------------------------------------------------------------*/
34652
34653 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34654-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34655 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34656 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34657+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34658
34659 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34660 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34661diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34662index 2f33760..835e50a 100644
34663--- a/arch/xtensa/variants/fsf/include/variant/core.h
34664+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34665@@ -11,6 +11,7 @@
34666 #ifndef _XTENSA_CORE_H
34667 #define _XTENSA_CORE_H
34668
34669+#include <linux/const.h>
34670
34671 /****************************************************************************
34672 Parameters Useful for Any Code, USER or PRIVILEGED
34673@@ -112,9 +113,9 @@
34674 ----------------------------------------------------------------------*/
34675
34676 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34677-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34678 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34679 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34680+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34681
34682 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34683 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34684diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34685index af00795..2bb8105 100644
34686--- a/arch/xtensa/variants/s6000/include/variant/core.h
34687+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34688@@ -11,6 +11,7 @@
34689 #ifndef _XTENSA_CORE_CONFIGURATION_H
34690 #define _XTENSA_CORE_CONFIGURATION_H
34691
34692+#include <linux/const.h>
34693
34694 /****************************************************************************
34695 Parameters Useful for Any Code, USER or PRIVILEGED
34696@@ -118,9 +119,9 @@
34697 ----------------------------------------------------------------------*/
34698
34699 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34700-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34701 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34702 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34703+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34704
34705 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34706 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34707diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34708index e8918ff..b3ffc51 100644
34709--- a/block/blk-cgroup.c
34710+++ b/block/blk-cgroup.c
34711@@ -825,7 +825,7 @@ static void blkcg_css_free(struct cgroup *cgroup)
34712
34713 static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34714 {
34715- static atomic64_t id_seq = ATOMIC64_INIT(0);
34716+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34717 struct blkcg *blkcg;
34718 struct cgroup *parent = cgroup->parent;
34719
34720@@ -840,7 +840,7 @@ static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34721
34722 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34723 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34724- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34725+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34726 done:
34727 spin_lock_init(&blkcg->lock);
34728 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34729diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34730index 58916af..eb9dbcf6 100644
34731--- a/block/blk-iopoll.c
34732+++ b/block/blk-iopoll.c
34733@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34734 }
34735 EXPORT_SYMBOL(blk_iopoll_complete);
34736
34737-static void blk_iopoll_softirq(struct softirq_action *h)
34738+static void blk_iopoll_softirq(void)
34739 {
34740 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34741 int rearm = 0, budget = blk_iopoll_budget;
34742@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
34743 return NOTIFY_OK;
34744 }
34745
34746-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
34747+static struct notifier_block blk_iopoll_cpu_notifier = {
34748 .notifier_call = blk_iopoll_cpu_notify,
34749 };
34750
34751diff --git a/block/blk-map.c b/block/blk-map.c
34752index 623e1cd..ca1e109 100644
34753--- a/block/blk-map.c
34754+++ b/block/blk-map.c
34755@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34756 if (!len || !kbuf)
34757 return -EINVAL;
34758
34759- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34760+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34761 if (do_copy)
34762 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34763 else
34764diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34765index 467c8de..f3628c5 100644
34766--- a/block/blk-softirq.c
34767+++ b/block/blk-softirq.c
34768@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34769 * Softirq action handler - move entries to local list and loop over them
34770 * while passing them to the queue registered handler.
34771 */
34772-static void blk_done_softirq(struct softirq_action *h)
34773+static void blk_done_softirq(void)
34774 {
34775 struct list_head *cpu_list, local_list;
34776
34777@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
34778 return NOTIFY_OK;
34779 }
34780
34781-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
34782+static struct notifier_block blk_cpu_notifier = {
34783 .notifier_call = blk_cpu_notify,
34784 };
34785
34786diff --git a/block/bsg.c b/block/bsg.c
34787index 420a5a9..23834aa 100644
34788--- a/block/bsg.c
34789+++ b/block/bsg.c
34790@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34791 struct sg_io_v4 *hdr, struct bsg_device *bd,
34792 fmode_t has_write_perm)
34793 {
34794+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34795+ unsigned char *cmdptr;
34796+
34797 if (hdr->request_len > BLK_MAX_CDB) {
34798 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34799 if (!rq->cmd)
34800 return -ENOMEM;
34801- }
34802+ cmdptr = rq->cmd;
34803+ } else
34804+ cmdptr = tmpcmd;
34805
34806- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34807+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34808 hdr->request_len))
34809 return -EFAULT;
34810
34811+ if (cmdptr != rq->cmd)
34812+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34813+
34814 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34815 if (blk_verify_command(rq->cmd, has_write_perm))
34816 return -EPERM;
34817diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34818index 7c668c8..db3521c 100644
34819--- a/block/compat_ioctl.c
34820+++ b/block/compat_ioctl.c
34821@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34822 err |= __get_user(f->spec1, &uf->spec1);
34823 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34824 err |= __get_user(name, &uf->name);
34825- f->name = compat_ptr(name);
34826+ f->name = (void __force_kernel *)compat_ptr(name);
34827 if (err) {
34828 err = -EFAULT;
34829 goto out;
34830diff --git a/block/genhd.c b/block/genhd.c
34831index cdeb527..10aa34db 100644
34832--- a/block/genhd.c
34833+++ b/block/genhd.c
34834@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34835
34836 /*
34837 * Register device numbers dev..(dev+range-1)
34838- * range must be nonzero
34839+ * Noop if @range is zero.
34840 * The hash chain is sorted on range, so that subranges can override.
34841 */
34842 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34843 struct kobject *(*probe)(dev_t, int *, void *),
34844 int (*lock)(dev_t, void *), void *data)
34845 {
34846- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34847+ if (range)
34848+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34849 }
34850
34851 EXPORT_SYMBOL(blk_register_region);
34852
34853+/* undo blk_register_region(), noop if @range is zero */
34854 void blk_unregister_region(dev_t devt, unsigned long range)
34855 {
34856- kobj_unmap(bdev_map, devt, range);
34857+ if (range)
34858+ kobj_unmap(bdev_map, devt, range);
34859 }
34860
34861 EXPORT_SYMBOL(blk_unregister_region);
34862diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34863index c85fc89..51e690b 100644
34864--- a/block/partitions/efi.c
34865+++ b/block/partitions/efi.c
34866@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34867 if (!gpt)
34868 return NULL;
34869
34870+ if (!le32_to_cpu(gpt->num_partition_entries))
34871+ return NULL;
34872+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34873+ if (!pte)
34874+ return NULL;
34875+
34876 count = le32_to_cpu(gpt->num_partition_entries) *
34877 le32_to_cpu(gpt->sizeof_partition_entry);
34878- if (!count)
34879- return NULL;
34880- pte = kmalloc(count, GFP_KERNEL);
34881- if (!pte)
34882- return NULL;
34883-
34884 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34885 (u8 *) pte,
34886 count) < count) {
34887diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34888index a5ffcc9..3cedc9c 100644
34889--- a/block/scsi_ioctl.c
34890+++ b/block/scsi_ioctl.c
34891@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34892 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34893 struct sg_io_hdr *hdr, fmode_t mode)
34894 {
34895- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34896+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34897+ unsigned char *cmdptr;
34898+
34899+ if (rq->cmd != rq->__cmd)
34900+ cmdptr = rq->cmd;
34901+ else
34902+ cmdptr = tmpcmd;
34903+
34904+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34905 return -EFAULT;
34906+
34907+ if (cmdptr != rq->cmd)
34908+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34909+
34910 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34911 return -EPERM;
34912
34913@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34914 int err;
34915 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34916 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34917+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34918+ unsigned char *cmdptr;
34919
34920 if (!sic)
34921 return -EINVAL;
34922@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34923 */
34924 err = -EFAULT;
34925 rq->cmd_len = cmdlen;
34926- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34927+
34928+ if (rq->cmd != rq->__cmd)
34929+ cmdptr = rq->cmd;
34930+ else
34931+ cmdptr = tmpcmd;
34932+
34933+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34934 goto error;
34935
34936+ if (rq->cmd != cmdptr)
34937+ memcpy(rq->cmd, cmdptr, cmdlen);
34938+
34939 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34940 goto error;
34941
34942diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34943index 7bdd61b..afec999 100644
34944--- a/crypto/cryptd.c
34945+++ b/crypto/cryptd.c
34946@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34947
34948 struct cryptd_blkcipher_request_ctx {
34949 crypto_completion_t complete;
34950-};
34951+} __no_const;
34952
34953 struct cryptd_hash_ctx {
34954 struct crypto_shash *child;
34955@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34956
34957 struct cryptd_aead_request_ctx {
34958 crypto_completion_t complete;
34959-};
34960+} __no_const;
34961
34962 static void cryptd_queue_worker(struct work_struct *work);
34963
34964diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34965index b2c99dc..476c9fb 100644
34966--- a/crypto/pcrypt.c
34967+++ b/crypto/pcrypt.c
34968@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34969 int ret;
34970
34971 pinst->kobj.kset = pcrypt_kset;
34972- ret = kobject_add(&pinst->kobj, NULL, name);
34973+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34974 if (!ret)
34975 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34976
34977@@ -455,8 +455,8 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
34978
34979 get_online_cpus();
34980
34981- pcrypt->wq = alloc_workqueue(name,
34982- WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
34983+ pcrypt->wq = alloc_workqueue("%s",
34984+ WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1, name);
34985 if (!pcrypt->wq)
34986 goto err;
34987
34988diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34989index f220d64..d359ad6 100644
34990--- a/drivers/acpi/apei/apei-internal.h
34991+++ b/drivers/acpi/apei/apei-internal.h
34992@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34993 struct apei_exec_ins_type {
34994 u32 flags;
34995 apei_exec_ins_func_t run;
34996-};
34997+} __do_const;
34998
34999 struct apei_exec_context {
35000 u32 ip;
35001diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
35002index 33dc6a0..4b24b47 100644
35003--- a/drivers/acpi/apei/cper.c
35004+++ b/drivers/acpi/apei/cper.c
35005@@ -39,12 +39,12 @@
35006 */
35007 u64 cper_next_record_id(void)
35008 {
35009- static atomic64_t seq;
35010+ static atomic64_unchecked_t seq;
35011
35012- if (!atomic64_read(&seq))
35013- atomic64_set(&seq, ((u64)get_seconds()) << 32);
35014+ if (!atomic64_read_unchecked(&seq))
35015+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
35016
35017- return atomic64_inc_return(&seq);
35018+ return atomic64_inc_return_unchecked(&seq);
35019 }
35020 EXPORT_SYMBOL_GPL(cper_next_record_id);
35021
35022diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35023index fcd7d91..6b2f1a3 100644
35024--- a/drivers/acpi/apei/ghes.c
35025+++ b/drivers/acpi/apei/ghes.c
35026@@ -468,7 +468,7 @@ static void __ghes_print_estatus(const char *pfx,
35027 const struct acpi_hest_generic *generic,
35028 const struct acpi_hest_generic_status *estatus)
35029 {
35030- static atomic_t seqno;
35031+ static atomic_unchecked_t seqno;
35032 unsigned int curr_seqno;
35033 char pfx_seq[64];
35034
35035@@ -479,7 +479,7 @@ static void __ghes_print_estatus(const char *pfx,
35036 else
35037 pfx = KERN_ERR;
35038 }
35039- curr_seqno = atomic_inc_return(&seqno);
35040+ curr_seqno = atomic_inc_return_unchecked(&seqno);
35041 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35042 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35043 pfx_seq, generic->header.source_id);
35044diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35045index be60399..778b33e8 100644
35046--- a/drivers/acpi/bgrt.c
35047+++ b/drivers/acpi/bgrt.c
35048@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
35049 return -ENODEV;
35050
35051 sysfs_bin_attr_init(&image_attr);
35052- image_attr.private = bgrt_image;
35053- image_attr.size = bgrt_image_size;
35054+ pax_open_kernel();
35055+ *(void **)&image_attr.private = bgrt_image;
35056+ *(size_t *)&image_attr.size = bgrt_image_size;
35057+ pax_close_kernel();
35058
35059 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
35060 if (!bgrt_kobj)
35061diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
35062index cb96296..b81293b 100644
35063--- a/drivers/acpi/blacklist.c
35064+++ b/drivers/acpi/blacklist.c
35065@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
35066 u32 is_critical_error;
35067 };
35068
35069-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
35070+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
35071
35072 /*
35073 * POLICY: If *anything* doesn't work, put it on the blacklist.
35074@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
35075 return 0;
35076 }
35077
35078-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
35079+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
35080 {
35081 .callback = dmi_disable_osi_vista,
35082 .ident = "Fujitsu Siemens",
35083diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
35084index 7586544..636a2f0 100644
35085--- a/drivers/acpi/ec_sys.c
35086+++ b/drivers/acpi/ec_sys.c
35087@@ -12,6 +12,7 @@
35088 #include <linux/acpi.h>
35089 #include <linux/debugfs.h>
35090 #include <linux/module.h>
35091+#include <linux/uaccess.h>
35092 #include "internal.h"
35093
35094 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
35095@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
35096 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
35097 */
35098 unsigned int size = EC_SPACE_SIZE;
35099- u8 *data = (u8 *) buf;
35100+ u8 data;
35101 loff_t init_off = *off;
35102 int err = 0;
35103
35104@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
35105 size = count;
35106
35107 while (size) {
35108- err = ec_read(*off, &data[*off - init_off]);
35109+ err = ec_read(*off, &data);
35110 if (err)
35111 return err;
35112+ if (put_user(data, &buf[*off - init_off]))
35113+ return -EFAULT;
35114 *off += 1;
35115 size--;
35116 }
35117@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
35118
35119 unsigned int size = count;
35120 loff_t init_off = *off;
35121- u8 *data = (u8 *) buf;
35122 int err = 0;
35123
35124 if (*off >= EC_SPACE_SIZE)
35125@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
35126 }
35127
35128 while (size) {
35129- u8 byte_write = data[*off - init_off];
35130+ u8 byte_write;
35131+ if (get_user(byte_write, &buf[*off - init_off]))
35132+ return -EFAULT;
35133 err = ec_write(*off, byte_write);
35134 if (err)
35135 return err;
35136diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
35137index eb133c7..f571552 100644
35138--- a/drivers/acpi/processor_idle.c
35139+++ b/drivers/acpi/processor_idle.c
35140@@ -994,7 +994,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
35141 {
35142 int i, count = CPUIDLE_DRIVER_STATE_START;
35143 struct acpi_processor_cx *cx;
35144- struct cpuidle_state *state;
35145+ cpuidle_state_no_const *state;
35146 struct cpuidle_driver *drv = &acpi_idle_driver;
35147
35148 if (!pr->flags.power_setup_done)
35149diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
35150index fcae5fa..e9f71ea 100644
35151--- a/drivers/acpi/sysfs.c
35152+++ b/drivers/acpi/sysfs.c
35153@@ -423,11 +423,11 @@ static u32 num_counters;
35154 static struct attribute **all_attrs;
35155 static u32 acpi_gpe_count;
35156
35157-static struct attribute_group interrupt_stats_attr_group = {
35158+static attribute_group_no_const interrupt_stats_attr_group = {
35159 .name = "interrupts",
35160 };
35161
35162-static struct kobj_attribute *counter_attrs;
35163+static kobj_attribute_no_const *counter_attrs;
35164
35165 static void delete_gpe_attr_array(void)
35166 {
35167diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
35168index 7b9bdd8..37638ca 100644
35169--- a/drivers/ata/libahci.c
35170+++ b/drivers/ata/libahci.c
35171@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
35172 }
35173 EXPORT_SYMBOL_GPL(ahci_kick_engine);
35174
35175-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35176+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35177 struct ata_taskfile *tf, int is_cmd, u16 flags,
35178 unsigned long timeout_msec)
35179 {
35180diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
35181index adf002a..06c46a7 100644
35182--- a/drivers/ata/libata-core.c
35183+++ b/drivers/ata/libata-core.c
35184@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
35185 static void ata_dev_xfermask(struct ata_device *dev);
35186 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
35187
35188-atomic_t ata_print_id = ATOMIC_INIT(0);
35189+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
35190
35191 struct ata_force_param {
35192 const char *name;
35193@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
35194 struct ata_port *ap;
35195 unsigned int tag;
35196
35197- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35198+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35199 ap = qc->ap;
35200
35201 qc->flags = 0;
35202@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
35203 struct ata_port *ap;
35204 struct ata_link *link;
35205
35206- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35207+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35208 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
35209 ap = qc->ap;
35210 link = qc->dev->link;
35211@@ -5926,6 +5926,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35212 return;
35213
35214 spin_lock(&lock);
35215+ pax_open_kernel();
35216
35217 for (cur = ops->inherits; cur; cur = cur->inherits) {
35218 void **inherit = (void **)cur;
35219@@ -5939,8 +5940,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35220 if (IS_ERR(*pp))
35221 *pp = NULL;
35222
35223- ops->inherits = NULL;
35224+ *(struct ata_port_operations **)&ops->inherits = NULL;
35225
35226+ pax_close_kernel();
35227 spin_unlock(&lock);
35228 }
35229
35230@@ -6133,7 +6135,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
35231
35232 /* give ports names and add SCSI hosts */
35233 for (i = 0; i < host->n_ports; i++)
35234- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
35235+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
35236
35237
35238 /* Create associated sysfs transport objects */
35239diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
35240index 0101af5..c70c325 100644
35241--- a/drivers/ata/libata-scsi.c
35242+++ b/drivers/ata/libata-scsi.c
35243@@ -4105,7 +4105,7 @@ int ata_sas_port_init(struct ata_port *ap)
35244
35245 if (rc)
35246 return rc;
35247- ap->print_id = atomic_inc_return(&ata_print_id);
35248+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
35249 return 0;
35250 }
35251 EXPORT_SYMBOL_GPL(ata_sas_port_init);
35252diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
35253index 577d902b..cb4781e 100644
35254--- a/drivers/ata/libata.h
35255+++ b/drivers/ata/libata.h
35256@@ -53,7 +53,7 @@ enum {
35257 ATA_DNXFER_QUIET = (1 << 31),
35258 };
35259
35260-extern atomic_t ata_print_id;
35261+extern atomic_unchecked_t ata_print_id;
35262 extern int atapi_passthru16;
35263 extern int libata_fua;
35264 extern int libata_noacpi;
35265diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
35266index 7638121..357a965 100644
35267--- a/drivers/ata/pata_arasan_cf.c
35268+++ b/drivers/ata/pata_arasan_cf.c
35269@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
35270 /* Handle platform specific quirks */
35271 if (quirk) {
35272 if (quirk & CF_BROKEN_PIO) {
35273- ap->ops->set_piomode = NULL;
35274+ pax_open_kernel();
35275+ *(void **)&ap->ops->set_piomode = NULL;
35276+ pax_close_kernel();
35277 ap->pio_mask = 0;
35278 }
35279 if (quirk & CF_BROKEN_MWDMA)
35280diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
35281index f9b983a..887b9d8 100644
35282--- a/drivers/atm/adummy.c
35283+++ b/drivers/atm/adummy.c
35284@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
35285 vcc->pop(vcc, skb);
35286 else
35287 dev_kfree_skb_any(skb);
35288- atomic_inc(&vcc->stats->tx);
35289+ atomic_inc_unchecked(&vcc->stats->tx);
35290
35291 return 0;
35292 }
35293diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
35294index 77a7480d..05cde58 100644
35295--- a/drivers/atm/ambassador.c
35296+++ b/drivers/atm/ambassador.c
35297@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
35298 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
35299
35300 // VC layer stats
35301- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35302+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35303
35304 // free the descriptor
35305 kfree (tx_descr);
35306@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35307 dump_skb ("<<<", vc, skb);
35308
35309 // VC layer stats
35310- atomic_inc(&atm_vcc->stats->rx);
35311+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35312 __net_timestamp(skb);
35313 // end of our responsibility
35314 atm_vcc->push (atm_vcc, skb);
35315@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35316 } else {
35317 PRINTK (KERN_INFO, "dropped over-size frame");
35318 // should we count this?
35319- atomic_inc(&atm_vcc->stats->rx_drop);
35320+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35321 }
35322
35323 } else {
35324@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
35325 }
35326
35327 if (check_area (skb->data, skb->len)) {
35328- atomic_inc(&atm_vcc->stats->tx_err);
35329+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
35330 return -ENOMEM; // ?
35331 }
35332
35333diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
35334index 0e3f8f9..765a7a5 100644
35335--- a/drivers/atm/atmtcp.c
35336+++ b/drivers/atm/atmtcp.c
35337@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35338 if (vcc->pop) vcc->pop(vcc,skb);
35339 else dev_kfree_skb(skb);
35340 if (dev_data) return 0;
35341- atomic_inc(&vcc->stats->tx_err);
35342+ atomic_inc_unchecked(&vcc->stats->tx_err);
35343 return -ENOLINK;
35344 }
35345 size = skb->len+sizeof(struct atmtcp_hdr);
35346@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35347 if (!new_skb) {
35348 if (vcc->pop) vcc->pop(vcc,skb);
35349 else dev_kfree_skb(skb);
35350- atomic_inc(&vcc->stats->tx_err);
35351+ atomic_inc_unchecked(&vcc->stats->tx_err);
35352 return -ENOBUFS;
35353 }
35354 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
35355@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35356 if (vcc->pop) vcc->pop(vcc,skb);
35357 else dev_kfree_skb(skb);
35358 out_vcc->push(out_vcc,new_skb);
35359- atomic_inc(&vcc->stats->tx);
35360- atomic_inc(&out_vcc->stats->rx);
35361+ atomic_inc_unchecked(&vcc->stats->tx);
35362+ atomic_inc_unchecked(&out_vcc->stats->rx);
35363 return 0;
35364 }
35365
35366@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35367 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
35368 read_unlock(&vcc_sklist_lock);
35369 if (!out_vcc) {
35370- atomic_inc(&vcc->stats->tx_err);
35371+ atomic_inc_unchecked(&vcc->stats->tx_err);
35372 goto done;
35373 }
35374 skb_pull(skb,sizeof(struct atmtcp_hdr));
35375@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35376 __net_timestamp(new_skb);
35377 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
35378 out_vcc->push(out_vcc,new_skb);
35379- atomic_inc(&vcc->stats->tx);
35380- atomic_inc(&out_vcc->stats->rx);
35381+ atomic_inc_unchecked(&vcc->stats->tx);
35382+ atomic_inc_unchecked(&out_vcc->stats->rx);
35383 done:
35384 if (vcc->pop) vcc->pop(vcc,skb);
35385 else dev_kfree_skb(skb);
35386diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
35387index b1955ba..b179940 100644
35388--- a/drivers/atm/eni.c
35389+++ b/drivers/atm/eni.c
35390@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
35391 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
35392 vcc->dev->number);
35393 length = 0;
35394- atomic_inc(&vcc->stats->rx_err);
35395+ atomic_inc_unchecked(&vcc->stats->rx_err);
35396 }
35397 else {
35398 length = ATM_CELL_SIZE-1; /* no HEC */
35399@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35400 size);
35401 }
35402 eff = length = 0;
35403- atomic_inc(&vcc->stats->rx_err);
35404+ atomic_inc_unchecked(&vcc->stats->rx_err);
35405 }
35406 else {
35407 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
35408@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35409 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
35410 vcc->dev->number,vcc->vci,length,size << 2,descr);
35411 length = eff = 0;
35412- atomic_inc(&vcc->stats->rx_err);
35413+ atomic_inc_unchecked(&vcc->stats->rx_err);
35414 }
35415 }
35416 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
35417@@ -767,7 +767,7 @@ rx_dequeued++;
35418 vcc->push(vcc,skb);
35419 pushed++;
35420 }
35421- atomic_inc(&vcc->stats->rx);
35422+ atomic_inc_unchecked(&vcc->stats->rx);
35423 }
35424 wake_up(&eni_dev->rx_wait);
35425 }
35426@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
35427 PCI_DMA_TODEVICE);
35428 if (vcc->pop) vcc->pop(vcc,skb);
35429 else dev_kfree_skb_irq(skb);
35430- atomic_inc(&vcc->stats->tx);
35431+ atomic_inc_unchecked(&vcc->stats->tx);
35432 wake_up(&eni_dev->tx_wait);
35433 dma_complete++;
35434 }
35435diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
35436index b41c948..a002b17 100644
35437--- a/drivers/atm/firestream.c
35438+++ b/drivers/atm/firestream.c
35439@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
35440 }
35441 }
35442
35443- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35444+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35445
35446 fs_dprintk (FS_DEBUG_TXMEM, "i");
35447 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
35448@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35449 #endif
35450 skb_put (skb, qe->p1 & 0xffff);
35451 ATM_SKB(skb)->vcc = atm_vcc;
35452- atomic_inc(&atm_vcc->stats->rx);
35453+ atomic_inc_unchecked(&atm_vcc->stats->rx);
35454 __net_timestamp(skb);
35455 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
35456 atm_vcc->push (atm_vcc, skb);
35457@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35458 kfree (pe);
35459 }
35460 if (atm_vcc)
35461- atomic_inc(&atm_vcc->stats->rx_drop);
35462+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35463 break;
35464 case 0x1f: /* Reassembly abort: no buffers. */
35465 /* Silently increment error counter. */
35466 if (atm_vcc)
35467- atomic_inc(&atm_vcc->stats->rx_drop);
35468+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35469 break;
35470 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35471 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35472diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35473index 204814e..cede831 100644
35474--- a/drivers/atm/fore200e.c
35475+++ b/drivers/atm/fore200e.c
35476@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35477 #endif
35478 /* check error condition */
35479 if (*entry->status & STATUS_ERROR)
35480- atomic_inc(&vcc->stats->tx_err);
35481+ atomic_inc_unchecked(&vcc->stats->tx_err);
35482 else
35483- atomic_inc(&vcc->stats->tx);
35484+ atomic_inc_unchecked(&vcc->stats->tx);
35485 }
35486 }
35487
35488@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35489 if (skb == NULL) {
35490 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35491
35492- atomic_inc(&vcc->stats->rx_drop);
35493+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35494 return -ENOMEM;
35495 }
35496
35497@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35498
35499 dev_kfree_skb_any(skb);
35500
35501- atomic_inc(&vcc->stats->rx_drop);
35502+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35503 return -ENOMEM;
35504 }
35505
35506 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35507
35508 vcc->push(vcc, skb);
35509- atomic_inc(&vcc->stats->rx);
35510+ atomic_inc_unchecked(&vcc->stats->rx);
35511
35512 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35513
35514@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35515 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35516 fore200e->atm_dev->number,
35517 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35518- atomic_inc(&vcc->stats->rx_err);
35519+ atomic_inc_unchecked(&vcc->stats->rx_err);
35520 }
35521 }
35522
35523@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35524 goto retry_here;
35525 }
35526
35527- atomic_inc(&vcc->stats->tx_err);
35528+ atomic_inc_unchecked(&vcc->stats->tx_err);
35529
35530 fore200e->tx_sat++;
35531 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35532diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35533index 507362a..a845e57 100644
35534--- a/drivers/atm/he.c
35535+++ b/drivers/atm/he.c
35536@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35537
35538 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35539 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35540- atomic_inc(&vcc->stats->rx_drop);
35541+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35542 goto return_host_buffers;
35543 }
35544
35545@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35546 RBRQ_LEN_ERR(he_dev->rbrq_head)
35547 ? "LEN_ERR" : "",
35548 vcc->vpi, vcc->vci);
35549- atomic_inc(&vcc->stats->rx_err);
35550+ atomic_inc_unchecked(&vcc->stats->rx_err);
35551 goto return_host_buffers;
35552 }
35553
35554@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35555 vcc->push(vcc, skb);
35556 spin_lock(&he_dev->global_lock);
35557
35558- atomic_inc(&vcc->stats->rx);
35559+ atomic_inc_unchecked(&vcc->stats->rx);
35560
35561 return_host_buffers:
35562 ++pdus_assembled;
35563@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35564 tpd->vcc->pop(tpd->vcc, tpd->skb);
35565 else
35566 dev_kfree_skb_any(tpd->skb);
35567- atomic_inc(&tpd->vcc->stats->tx_err);
35568+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35569 }
35570 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35571 return;
35572@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35573 vcc->pop(vcc, skb);
35574 else
35575 dev_kfree_skb_any(skb);
35576- atomic_inc(&vcc->stats->tx_err);
35577+ atomic_inc_unchecked(&vcc->stats->tx_err);
35578 return -EINVAL;
35579 }
35580
35581@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35582 vcc->pop(vcc, skb);
35583 else
35584 dev_kfree_skb_any(skb);
35585- atomic_inc(&vcc->stats->tx_err);
35586+ atomic_inc_unchecked(&vcc->stats->tx_err);
35587 return -EINVAL;
35588 }
35589 #endif
35590@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35591 vcc->pop(vcc, skb);
35592 else
35593 dev_kfree_skb_any(skb);
35594- atomic_inc(&vcc->stats->tx_err);
35595+ atomic_inc_unchecked(&vcc->stats->tx_err);
35596 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35597 return -ENOMEM;
35598 }
35599@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35600 vcc->pop(vcc, skb);
35601 else
35602 dev_kfree_skb_any(skb);
35603- atomic_inc(&vcc->stats->tx_err);
35604+ atomic_inc_unchecked(&vcc->stats->tx_err);
35605 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35606 return -ENOMEM;
35607 }
35608@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35609 __enqueue_tpd(he_dev, tpd, cid);
35610 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35611
35612- atomic_inc(&vcc->stats->tx);
35613+ atomic_inc_unchecked(&vcc->stats->tx);
35614
35615 return 0;
35616 }
35617diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35618index 1dc0519..1aadaf7 100644
35619--- a/drivers/atm/horizon.c
35620+++ b/drivers/atm/horizon.c
35621@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35622 {
35623 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35624 // VC layer stats
35625- atomic_inc(&vcc->stats->rx);
35626+ atomic_inc_unchecked(&vcc->stats->rx);
35627 __net_timestamp(skb);
35628 // end of our responsibility
35629 vcc->push (vcc, skb);
35630@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35631 dev->tx_iovec = NULL;
35632
35633 // VC layer stats
35634- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35635+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35636
35637 // free the skb
35638 hrz_kfree_skb (skb);
35639diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35640index 272f009..a18ba55 100644
35641--- a/drivers/atm/idt77252.c
35642+++ b/drivers/atm/idt77252.c
35643@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35644 else
35645 dev_kfree_skb(skb);
35646
35647- atomic_inc(&vcc->stats->tx);
35648+ atomic_inc_unchecked(&vcc->stats->tx);
35649 }
35650
35651 atomic_dec(&scq->used);
35652@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35653 if ((sb = dev_alloc_skb(64)) == NULL) {
35654 printk("%s: Can't allocate buffers for aal0.\n",
35655 card->name);
35656- atomic_add(i, &vcc->stats->rx_drop);
35657+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35658 break;
35659 }
35660 if (!atm_charge(vcc, sb->truesize)) {
35661 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35662 card->name);
35663- atomic_add(i - 1, &vcc->stats->rx_drop);
35664+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35665 dev_kfree_skb(sb);
35666 break;
35667 }
35668@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35669 ATM_SKB(sb)->vcc = vcc;
35670 __net_timestamp(sb);
35671 vcc->push(vcc, sb);
35672- atomic_inc(&vcc->stats->rx);
35673+ atomic_inc_unchecked(&vcc->stats->rx);
35674
35675 cell += ATM_CELL_PAYLOAD;
35676 }
35677@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35678 "(CDC: %08x)\n",
35679 card->name, len, rpp->len, readl(SAR_REG_CDC));
35680 recycle_rx_pool_skb(card, rpp);
35681- atomic_inc(&vcc->stats->rx_err);
35682+ atomic_inc_unchecked(&vcc->stats->rx_err);
35683 return;
35684 }
35685 if (stat & SAR_RSQE_CRC) {
35686 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35687 recycle_rx_pool_skb(card, rpp);
35688- atomic_inc(&vcc->stats->rx_err);
35689+ atomic_inc_unchecked(&vcc->stats->rx_err);
35690 return;
35691 }
35692 if (skb_queue_len(&rpp->queue) > 1) {
35693@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35694 RXPRINTK("%s: Can't alloc RX skb.\n",
35695 card->name);
35696 recycle_rx_pool_skb(card, rpp);
35697- atomic_inc(&vcc->stats->rx_err);
35698+ atomic_inc_unchecked(&vcc->stats->rx_err);
35699 return;
35700 }
35701 if (!atm_charge(vcc, skb->truesize)) {
35702@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35703 __net_timestamp(skb);
35704
35705 vcc->push(vcc, skb);
35706- atomic_inc(&vcc->stats->rx);
35707+ atomic_inc_unchecked(&vcc->stats->rx);
35708
35709 return;
35710 }
35711@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35712 __net_timestamp(skb);
35713
35714 vcc->push(vcc, skb);
35715- atomic_inc(&vcc->stats->rx);
35716+ atomic_inc_unchecked(&vcc->stats->rx);
35717
35718 if (skb->truesize > SAR_FB_SIZE_3)
35719 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35720@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35721 if (vcc->qos.aal != ATM_AAL0) {
35722 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35723 card->name, vpi, vci);
35724- atomic_inc(&vcc->stats->rx_drop);
35725+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35726 goto drop;
35727 }
35728
35729 if ((sb = dev_alloc_skb(64)) == NULL) {
35730 printk("%s: Can't allocate buffers for AAL0.\n",
35731 card->name);
35732- atomic_inc(&vcc->stats->rx_err);
35733+ atomic_inc_unchecked(&vcc->stats->rx_err);
35734 goto drop;
35735 }
35736
35737@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35738 ATM_SKB(sb)->vcc = vcc;
35739 __net_timestamp(sb);
35740 vcc->push(vcc, sb);
35741- atomic_inc(&vcc->stats->rx);
35742+ atomic_inc_unchecked(&vcc->stats->rx);
35743
35744 drop:
35745 skb_pull(queue, 64);
35746@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35747
35748 if (vc == NULL) {
35749 printk("%s: NULL connection in send().\n", card->name);
35750- atomic_inc(&vcc->stats->tx_err);
35751+ atomic_inc_unchecked(&vcc->stats->tx_err);
35752 dev_kfree_skb(skb);
35753 return -EINVAL;
35754 }
35755 if (!test_bit(VCF_TX, &vc->flags)) {
35756 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35757- atomic_inc(&vcc->stats->tx_err);
35758+ atomic_inc_unchecked(&vcc->stats->tx_err);
35759 dev_kfree_skb(skb);
35760 return -EINVAL;
35761 }
35762@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35763 break;
35764 default:
35765 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35766- atomic_inc(&vcc->stats->tx_err);
35767+ atomic_inc_unchecked(&vcc->stats->tx_err);
35768 dev_kfree_skb(skb);
35769 return -EINVAL;
35770 }
35771
35772 if (skb_shinfo(skb)->nr_frags != 0) {
35773 printk("%s: No scatter-gather yet.\n", card->name);
35774- atomic_inc(&vcc->stats->tx_err);
35775+ atomic_inc_unchecked(&vcc->stats->tx_err);
35776 dev_kfree_skb(skb);
35777 return -EINVAL;
35778 }
35779@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35780
35781 err = queue_skb(card, vc, skb, oam);
35782 if (err) {
35783- atomic_inc(&vcc->stats->tx_err);
35784+ atomic_inc_unchecked(&vcc->stats->tx_err);
35785 dev_kfree_skb(skb);
35786 return err;
35787 }
35788@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35789 skb = dev_alloc_skb(64);
35790 if (!skb) {
35791 printk("%s: Out of memory in send_oam().\n", card->name);
35792- atomic_inc(&vcc->stats->tx_err);
35793+ atomic_inc_unchecked(&vcc->stats->tx_err);
35794 return -ENOMEM;
35795 }
35796 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35797diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35798index 4217f29..88f547a 100644
35799--- a/drivers/atm/iphase.c
35800+++ b/drivers/atm/iphase.c
35801@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35802 status = (u_short) (buf_desc_ptr->desc_mode);
35803 if (status & (RX_CER | RX_PTE | RX_OFL))
35804 {
35805- atomic_inc(&vcc->stats->rx_err);
35806+ atomic_inc_unchecked(&vcc->stats->rx_err);
35807 IF_ERR(printk("IA: bad packet, dropping it");)
35808 if (status & RX_CER) {
35809 IF_ERR(printk(" cause: packet CRC error\n");)
35810@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35811 len = dma_addr - buf_addr;
35812 if (len > iadev->rx_buf_sz) {
35813 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35814- atomic_inc(&vcc->stats->rx_err);
35815+ atomic_inc_unchecked(&vcc->stats->rx_err);
35816 goto out_free_desc;
35817 }
35818
35819@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35820 ia_vcc = INPH_IA_VCC(vcc);
35821 if (ia_vcc == NULL)
35822 {
35823- atomic_inc(&vcc->stats->rx_err);
35824+ atomic_inc_unchecked(&vcc->stats->rx_err);
35825 atm_return(vcc, skb->truesize);
35826 dev_kfree_skb_any(skb);
35827 goto INCR_DLE;
35828@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35829 if ((length > iadev->rx_buf_sz) || (length >
35830 (skb->len - sizeof(struct cpcs_trailer))))
35831 {
35832- atomic_inc(&vcc->stats->rx_err);
35833+ atomic_inc_unchecked(&vcc->stats->rx_err);
35834 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35835 length, skb->len);)
35836 atm_return(vcc, skb->truesize);
35837@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35838
35839 IF_RX(printk("rx_dle_intr: skb push");)
35840 vcc->push(vcc,skb);
35841- atomic_inc(&vcc->stats->rx);
35842+ atomic_inc_unchecked(&vcc->stats->rx);
35843 iadev->rx_pkt_cnt++;
35844 }
35845 INCR_DLE:
35846@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35847 {
35848 struct k_sonet_stats *stats;
35849 stats = &PRIV(_ia_dev[board])->sonet_stats;
35850- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35851- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35852- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35853- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35854- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35855- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35856- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35857- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35858- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35859+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35860+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35861+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35862+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35863+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35864+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35865+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35866+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35867+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35868 }
35869 ia_cmds.status = 0;
35870 break;
35871@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35872 if ((desc == 0) || (desc > iadev->num_tx_desc))
35873 {
35874 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35875- atomic_inc(&vcc->stats->tx);
35876+ atomic_inc_unchecked(&vcc->stats->tx);
35877 if (vcc->pop)
35878 vcc->pop(vcc, skb);
35879 else
35880@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35881 ATM_DESC(skb) = vcc->vci;
35882 skb_queue_tail(&iadev->tx_dma_q, skb);
35883
35884- atomic_inc(&vcc->stats->tx);
35885+ atomic_inc_unchecked(&vcc->stats->tx);
35886 iadev->tx_pkt_cnt++;
35887 /* Increment transaction counter */
35888 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35889
35890 #if 0
35891 /* add flow control logic */
35892- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35893+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35894 if (iavcc->vc_desc_cnt > 10) {
35895 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35896 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35897diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35898index fa7d701..1e404c7 100644
35899--- a/drivers/atm/lanai.c
35900+++ b/drivers/atm/lanai.c
35901@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35902 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35903 lanai_endtx(lanai, lvcc);
35904 lanai_free_skb(lvcc->tx.atmvcc, skb);
35905- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35906+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35907 }
35908
35909 /* Try to fill the buffer - don't call unless there is backlog */
35910@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35911 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35912 __net_timestamp(skb);
35913 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35914- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35915+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35916 out:
35917 lvcc->rx.buf.ptr = end;
35918 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35919@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35920 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35921 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35922 lanai->stats.service_rxnotaal5++;
35923- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35924+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35925 return 0;
35926 }
35927 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35928@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35929 int bytes;
35930 read_unlock(&vcc_sklist_lock);
35931 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35932- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35933+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35934 lvcc->stats.x.aal5.service_trash++;
35935 bytes = (SERVICE_GET_END(s) * 16) -
35936 (((unsigned long) lvcc->rx.buf.ptr) -
35937@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35938 }
35939 if (s & SERVICE_STREAM) {
35940 read_unlock(&vcc_sklist_lock);
35941- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35942+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35943 lvcc->stats.x.aal5.service_stream++;
35944 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35945 "PDU on VCI %d!\n", lanai->number, vci);
35946@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35947 return 0;
35948 }
35949 DPRINTK("got rx crc error on vci %d\n", vci);
35950- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35951+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35952 lvcc->stats.x.aal5.service_rxcrc++;
35953 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35954 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35955diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35956index 6587dc2..149833d 100644
35957--- a/drivers/atm/nicstar.c
35958+++ b/drivers/atm/nicstar.c
35959@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35960 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35961 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35962 card->index);
35963- atomic_inc(&vcc->stats->tx_err);
35964+ atomic_inc_unchecked(&vcc->stats->tx_err);
35965 dev_kfree_skb_any(skb);
35966 return -EINVAL;
35967 }
35968@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35969 if (!vc->tx) {
35970 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35971 card->index);
35972- atomic_inc(&vcc->stats->tx_err);
35973+ atomic_inc_unchecked(&vcc->stats->tx_err);
35974 dev_kfree_skb_any(skb);
35975 return -EINVAL;
35976 }
35977@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35978 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35979 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35980 card->index);
35981- atomic_inc(&vcc->stats->tx_err);
35982+ atomic_inc_unchecked(&vcc->stats->tx_err);
35983 dev_kfree_skb_any(skb);
35984 return -EINVAL;
35985 }
35986
35987 if (skb_shinfo(skb)->nr_frags != 0) {
35988 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35989- atomic_inc(&vcc->stats->tx_err);
35990+ atomic_inc_unchecked(&vcc->stats->tx_err);
35991 dev_kfree_skb_any(skb);
35992 return -EINVAL;
35993 }
35994@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35995 }
35996
35997 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35998- atomic_inc(&vcc->stats->tx_err);
35999+ atomic_inc_unchecked(&vcc->stats->tx_err);
36000 dev_kfree_skb_any(skb);
36001 return -EIO;
36002 }
36003- atomic_inc(&vcc->stats->tx);
36004+ atomic_inc_unchecked(&vcc->stats->tx);
36005
36006 return 0;
36007 }
36008@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36009 printk
36010 ("nicstar%d: Can't allocate buffers for aal0.\n",
36011 card->index);
36012- atomic_add(i, &vcc->stats->rx_drop);
36013+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36014 break;
36015 }
36016 if (!atm_charge(vcc, sb->truesize)) {
36017 RXPRINTK
36018 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36019 card->index);
36020- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36021+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36022 dev_kfree_skb_any(sb);
36023 break;
36024 }
36025@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36026 ATM_SKB(sb)->vcc = vcc;
36027 __net_timestamp(sb);
36028 vcc->push(vcc, sb);
36029- atomic_inc(&vcc->stats->rx);
36030+ atomic_inc_unchecked(&vcc->stats->rx);
36031 cell += ATM_CELL_PAYLOAD;
36032 }
36033
36034@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36035 if (iovb == NULL) {
36036 printk("nicstar%d: Out of iovec buffers.\n",
36037 card->index);
36038- atomic_inc(&vcc->stats->rx_drop);
36039+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36040 recycle_rx_buf(card, skb);
36041 return;
36042 }
36043@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36044 small or large buffer itself. */
36045 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36046 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36047- atomic_inc(&vcc->stats->rx_err);
36048+ atomic_inc_unchecked(&vcc->stats->rx_err);
36049 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36050 NS_MAX_IOVECS);
36051 NS_PRV_IOVCNT(iovb) = 0;
36052@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36053 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36054 card->index);
36055 which_list(card, skb);
36056- atomic_inc(&vcc->stats->rx_err);
36057+ atomic_inc_unchecked(&vcc->stats->rx_err);
36058 recycle_rx_buf(card, skb);
36059 vc->rx_iov = NULL;
36060 recycle_iov_buf(card, iovb);
36061@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36062 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36063 card->index);
36064 which_list(card, skb);
36065- atomic_inc(&vcc->stats->rx_err);
36066+ atomic_inc_unchecked(&vcc->stats->rx_err);
36067 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36068 NS_PRV_IOVCNT(iovb));
36069 vc->rx_iov = NULL;
36070@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36071 printk(" - PDU size mismatch.\n");
36072 else
36073 printk(".\n");
36074- atomic_inc(&vcc->stats->rx_err);
36075+ atomic_inc_unchecked(&vcc->stats->rx_err);
36076 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36077 NS_PRV_IOVCNT(iovb));
36078 vc->rx_iov = NULL;
36079@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36080 /* skb points to a small buffer */
36081 if (!atm_charge(vcc, skb->truesize)) {
36082 push_rxbufs(card, skb);
36083- atomic_inc(&vcc->stats->rx_drop);
36084+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36085 } else {
36086 skb_put(skb, len);
36087 dequeue_sm_buf(card, skb);
36088@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36089 ATM_SKB(skb)->vcc = vcc;
36090 __net_timestamp(skb);
36091 vcc->push(vcc, skb);
36092- atomic_inc(&vcc->stats->rx);
36093+ atomic_inc_unchecked(&vcc->stats->rx);
36094 }
36095 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
36096 struct sk_buff *sb;
36097@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36098 if (len <= NS_SMBUFSIZE) {
36099 if (!atm_charge(vcc, sb->truesize)) {
36100 push_rxbufs(card, sb);
36101- atomic_inc(&vcc->stats->rx_drop);
36102+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36103 } else {
36104 skb_put(sb, len);
36105 dequeue_sm_buf(card, sb);
36106@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36107 ATM_SKB(sb)->vcc = vcc;
36108 __net_timestamp(sb);
36109 vcc->push(vcc, sb);
36110- atomic_inc(&vcc->stats->rx);
36111+ atomic_inc_unchecked(&vcc->stats->rx);
36112 }
36113
36114 push_rxbufs(card, skb);
36115@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36116
36117 if (!atm_charge(vcc, skb->truesize)) {
36118 push_rxbufs(card, skb);
36119- atomic_inc(&vcc->stats->rx_drop);
36120+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36121 } else {
36122 dequeue_lg_buf(card, skb);
36123 #ifdef NS_USE_DESTRUCTORS
36124@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36125 ATM_SKB(skb)->vcc = vcc;
36126 __net_timestamp(skb);
36127 vcc->push(vcc, skb);
36128- atomic_inc(&vcc->stats->rx);
36129+ atomic_inc_unchecked(&vcc->stats->rx);
36130 }
36131
36132 push_rxbufs(card, sb);
36133@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36134 printk
36135 ("nicstar%d: Out of huge buffers.\n",
36136 card->index);
36137- atomic_inc(&vcc->stats->rx_drop);
36138+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36139 recycle_iovec_rx_bufs(card,
36140 (struct iovec *)
36141 iovb->data,
36142@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36143 card->hbpool.count++;
36144 } else
36145 dev_kfree_skb_any(hb);
36146- atomic_inc(&vcc->stats->rx_drop);
36147+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36148 } else {
36149 /* Copy the small buffer to the huge buffer */
36150 sb = (struct sk_buff *)iov->iov_base;
36151@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36152 #endif /* NS_USE_DESTRUCTORS */
36153 __net_timestamp(hb);
36154 vcc->push(vcc, hb);
36155- atomic_inc(&vcc->stats->rx);
36156+ atomic_inc_unchecked(&vcc->stats->rx);
36157 }
36158 }
36159
36160diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
36161index 32784d1..4a8434a 100644
36162--- a/drivers/atm/solos-pci.c
36163+++ b/drivers/atm/solos-pci.c
36164@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
36165 }
36166 atm_charge(vcc, skb->truesize);
36167 vcc->push(vcc, skb);
36168- atomic_inc(&vcc->stats->rx);
36169+ atomic_inc_unchecked(&vcc->stats->rx);
36170 break;
36171
36172 case PKT_STATUS:
36173@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
36174 vcc = SKB_CB(oldskb)->vcc;
36175
36176 if (vcc) {
36177- atomic_inc(&vcc->stats->tx);
36178+ atomic_inc_unchecked(&vcc->stats->tx);
36179 solos_pop(vcc, oldskb);
36180 } else {
36181 dev_kfree_skb_irq(oldskb);
36182diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
36183index 0215934..ce9f5b1 100644
36184--- a/drivers/atm/suni.c
36185+++ b/drivers/atm/suni.c
36186@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
36187
36188
36189 #define ADD_LIMITED(s,v) \
36190- atomic_add((v),&stats->s); \
36191- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
36192+ atomic_add_unchecked((v),&stats->s); \
36193+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
36194
36195
36196 static void suni_hz(unsigned long from_timer)
36197diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
36198index 5120a96..e2572bd 100644
36199--- a/drivers/atm/uPD98402.c
36200+++ b/drivers/atm/uPD98402.c
36201@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
36202 struct sonet_stats tmp;
36203 int error = 0;
36204
36205- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36206+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36207 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
36208 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
36209 if (zero && !error) {
36210@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
36211
36212
36213 #define ADD_LIMITED(s,v) \
36214- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
36215- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
36216- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36217+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
36218+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
36219+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36220
36221
36222 static void stat_event(struct atm_dev *dev)
36223@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
36224 if (reason & uPD98402_INT_PFM) stat_event(dev);
36225 if (reason & uPD98402_INT_PCO) {
36226 (void) GET(PCOCR); /* clear interrupt cause */
36227- atomic_add(GET(HECCT),
36228+ atomic_add_unchecked(GET(HECCT),
36229 &PRIV(dev)->sonet_stats.uncorr_hcs);
36230 }
36231 if ((reason & uPD98402_INT_RFO) &&
36232@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
36233 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
36234 uPD98402_INT_LOS),PIMR); /* enable them */
36235 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
36236- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36237- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
36238- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
36239+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36240+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
36241+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
36242 return 0;
36243 }
36244
36245diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
36246index 969c3c2..9b72956 100644
36247--- a/drivers/atm/zatm.c
36248+++ b/drivers/atm/zatm.c
36249@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36250 }
36251 if (!size) {
36252 dev_kfree_skb_irq(skb);
36253- if (vcc) atomic_inc(&vcc->stats->rx_err);
36254+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
36255 continue;
36256 }
36257 if (!atm_charge(vcc,skb->truesize)) {
36258@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36259 skb->len = size;
36260 ATM_SKB(skb)->vcc = vcc;
36261 vcc->push(vcc,skb);
36262- atomic_inc(&vcc->stats->rx);
36263+ atomic_inc_unchecked(&vcc->stats->rx);
36264 }
36265 zout(pos & 0xffff,MTA(mbx));
36266 #if 0 /* probably a stupid idea */
36267@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
36268 skb_queue_head(&zatm_vcc->backlog,skb);
36269 break;
36270 }
36271- atomic_inc(&vcc->stats->tx);
36272+ atomic_inc_unchecked(&vcc->stats->tx);
36273 wake_up(&zatm_vcc->tx_wait);
36274 }
36275
36276diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
36277index d78b204..ecc1929 100644
36278--- a/drivers/base/attribute_container.c
36279+++ b/drivers/base/attribute_container.c
36280@@ -167,7 +167,7 @@ attribute_container_add_device(struct device *dev,
36281 ic->classdev.parent = get_device(dev);
36282 ic->classdev.class = cont->class;
36283 cont->class->dev_release = attribute_container_release;
36284- dev_set_name(&ic->classdev, dev_name(dev));
36285+ dev_set_name(&ic->classdev, "%s", dev_name(dev));
36286 if (fn)
36287 fn(cont, dev, &ic->classdev);
36288 else
36289diff --git a/drivers/base/bus.c b/drivers/base/bus.c
36290index d414331..b4dd4ba 100644
36291--- a/drivers/base/bus.c
36292+++ b/drivers/base/bus.c
36293@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
36294 return -EINVAL;
36295
36296 mutex_lock(&subsys->p->mutex);
36297- list_add_tail(&sif->node, &subsys->p->interfaces);
36298+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
36299 if (sif->add_dev) {
36300 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36301 while ((dev = subsys_dev_iter_next(&iter)))
36302@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
36303 subsys = sif->subsys;
36304
36305 mutex_lock(&subsys->p->mutex);
36306- list_del_init(&sif->node);
36307+ pax_list_del_init((struct list_head *)&sif->node);
36308 if (sif->remove_dev) {
36309 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36310 while ((dev = subsys_dev_iter_next(&iter)))
36311diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
36312index 7413d06..79155fa 100644
36313--- a/drivers/base/devtmpfs.c
36314+++ b/drivers/base/devtmpfs.c
36315@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
36316 if (!thread)
36317 return 0;
36318
36319- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
36320+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
36321 if (err)
36322 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
36323 else
36324@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
36325 *err = sys_unshare(CLONE_NEWNS);
36326 if (*err)
36327 goto out;
36328- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
36329+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
36330 if (*err)
36331 goto out;
36332- sys_chdir("/.."); /* will traverse into overmounted root */
36333- sys_chroot(".");
36334+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
36335+ sys_chroot((char __force_user *)".");
36336 complete(&setup_done);
36337 while (1) {
36338 spin_lock(&req_lock);
36339diff --git a/drivers/base/node.c b/drivers/base/node.c
36340index 7616a77c..8f57f51 100644
36341--- a/drivers/base/node.c
36342+++ b/drivers/base/node.c
36343@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
36344 struct node_attr {
36345 struct device_attribute attr;
36346 enum node_states state;
36347-};
36348+} __do_const;
36349
36350 static ssize_t show_node_state(struct device *dev,
36351 struct device_attribute *attr, char *buf)
36352diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
36353index 7072404..76dcebd 100644
36354--- a/drivers/base/power/domain.c
36355+++ b/drivers/base/power/domain.c
36356@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
36357 {
36358 struct cpuidle_driver *cpuidle_drv;
36359 struct gpd_cpu_data *cpu_data;
36360- struct cpuidle_state *idle_state;
36361+ cpuidle_state_no_const *idle_state;
36362 int ret = 0;
36363
36364 if (IS_ERR_OR_NULL(genpd) || state < 0)
36365@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
36366 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
36367 {
36368 struct gpd_cpu_data *cpu_data;
36369- struct cpuidle_state *idle_state;
36370+ cpuidle_state_no_const *idle_state;
36371 int ret = 0;
36372
36373 if (IS_ERR_OR_NULL(genpd))
36374diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
36375index a53ebd2..8f73eeb 100644
36376--- a/drivers/base/power/sysfs.c
36377+++ b/drivers/base/power/sysfs.c
36378@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
36379 return -EIO;
36380 }
36381 }
36382- return sprintf(buf, p);
36383+ return sprintf(buf, "%s", p);
36384 }
36385
36386 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
36387diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
36388index 79715e7..df06b3b 100644
36389--- a/drivers/base/power/wakeup.c
36390+++ b/drivers/base/power/wakeup.c
36391@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
36392 * They need to be modified together atomically, so it's better to use one
36393 * atomic variable to hold them both.
36394 */
36395-static atomic_t combined_event_count = ATOMIC_INIT(0);
36396+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
36397
36398 #define IN_PROGRESS_BITS (sizeof(int) * 4)
36399 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
36400
36401 static void split_counters(unsigned int *cnt, unsigned int *inpr)
36402 {
36403- unsigned int comb = atomic_read(&combined_event_count);
36404+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
36405
36406 *cnt = (comb >> IN_PROGRESS_BITS);
36407 *inpr = comb & MAX_IN_PROGRESS;
36408@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
36409 ws->start_prevent_time = ws->last_time;
36410
36411 /* Increment the counter of events in progress. */
36412- cec = atomic_inc_return(&combined_event_count);
36413+ cec = atomic_inc_return_unchecked(&combined_event_count);
36414
36415 trace_wakeup_source_activate(ws->name, cec);
36416 }
36417@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
36418 * Increment the counter of registered wakeup events and decrement the
36419 * couter of wakeup events in progress simultaneously.
36420 */
36421- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
36422+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
36423 trace_wakeup_source_deactivate(ws->name, cec);
36424
36425 split_counters(&cnt, &inpr);
36426diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
36427index e8d11b6..7b1b36f 100644
36428--- a/drivers/base/syscore.c
36429+++ b/drivers/base/syscore.c
36430@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
36431 void register_syscore_ops(struct syscore_ops *ops)
36432 {
36433 mutex_lock(&syscore_ops_lock);
36434- list_add_tail(&ops->node, &syscore_ops_list);
36435+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
36436 mutex_unlock(&syscore_ops_lock);
36437 }
36438 EXPORT_SYMBOL_GPL(register_syscore_ops);
36439@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
36440 void unregister_syscore_ops(struct syscore_ops *ops)
36441 {
36442 mutex_lock(&syscore_ops_lock);
36443- list_del(&ops->node);
36444+ pax_list_del((struct list_head *)&ops->node);
36445 mutex_unlock(&syscore_ops_lock);
36446 }
36447 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
36448diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
36449index 62b6c2c..4a11354 100644
36450--- a/drivers/block/cciss.c
36451+++ b/drivers/block/cciss.c
36452@@ -1189,6 +1189,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
36453 int err;
36454 u32 cp;
36455
36456+ memset(&arg64, 0, sizeof(arg64));
36457+
36458 err = 0;
36459 err |=
36460 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
36461@@ -3010,7 +3012,7 @@ static void start_io(ctlr_info_t *h)
36462 while (!list_empty(&h->reqQ)) {
36463 c = list_entry(h->reqQ.next, CommandList_struct, list);
36464 /* can't do anything if fifo is full */
36465- if ((h->access.fifo_full(h))) {
36466+ if ((h->access->fifo_full(h))) {
36467 dev_warn(&h->pdev->dev, "fifo full\n");
36468 break;
36469 }
36470@@ -3020,7 +3022,7 @@ static void start_io(ctlr_info_t *h)
36471 h->Qdepth--;
36472
36473 /* Tell the controller execute command */
36474- h->access.submit_command(h, c);
36475+ h->access->submit_command(h, c);
36476
36477 /* Put job onto the completed Q */
36478 addQ(&h->cmpQ, c);
36479@@ -3446,17 +3448,17 @@ startio:
36480
36481 static inline unsigned long get_next_completion(ctlr_info_t *h)
36482 {
36483- return h->access.command_completed(h);
36484+ return h->access->command_completed(h);
36485 }
36486
36487 static inline int interrupt_pending(ctlr_info_t *h)
36488 {
36489- return h->access.intr_pending(h);
36490+ return h->access->intr_pending(h);
36491 }
36492
36493 static inline long interrupt_not_for_us(ctlr_info_t *h)
36494 {
36495- return ((h->access.intr_pending(h) == 0) ||
36496+ return ((h->access->intr_pending(h) == 0) ||
36497 (h->interrupts_enabled == 0));
36498 }
36499
36500@@ -3489,7 +3491,7 @@ static inline u32 next_command(ctlr_info_t *h)
36501 u32 a;
36502
36503 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36504- return h->access.command_completed(h);
36505+ return h->access->command_completed(h);
36506
36507 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36508 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36509@@ -4046,7 +4048,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36510 trans_support & CFGTBL_Trans_use_short_tags);
36511
36512 /* Change the access methods to the performant access methods */
36513- h->access = SA5_performant_access;
36514+ h->access = &SA5_performant_access;
36515 h->transMethod = CFGTBL_Trans_Performant;
36516
36517 return;
36518@@ -4319,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36519 if (prod_index < 0)
36520 return -ENODEV;
36521 h->product_name = products[prod_index].product_name;
36522- h->access = *(products[prod_index].access);
36523+ h->access = products[prod_index].access;
36524
36525 if (cciss_board_disabled(h)) {
36526 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36527@@ -5051,7 +5053,7 @@ reinit_after_soft_reset:
36528 }
36529
36530 /* make sure the board interrupts are off */
36531- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36532+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36533 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36534 if (rc)
36535 goto clean2;
36536@@ -5101,7 +5103,7 @@ reinit_after_soft_reset:
36537 * fake ones to scoop up any residual completions.
36538 */
36539 spin_lock_irqsave(&h->lock, flags);
36540- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36541+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36542 spin_unlock_irqrestore(&h->lock, flags);
36543 free_irq(h->intr[h->intr_mode], h);
36544 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36545@@ -5121,9 +5123,9 @@ reinit_after_soft_reset:
36546 dev_info(&h->pdev->dev, "Board READY.\n");
36547 dev_info(&h->pdev->dev,
36548 "Waiting for stale completions to drain.\n");
36549- h->access.set_intr_mask(h, CCISS_INTR_ON);
36550+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36551 msleep(10000);
36552- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36553+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36554
36555 rc = controller_reset_failed(h->cfgtable);
36556 if (rc)
36557@@ -5146,7 +5148,7 @@ reinit_after_soft_reset:
36558 cciss_scsi_setup(h);
36559
36560 /* Turn the interrupts on so we can service requests */
36561- h->access.set_intr_mask(h, CCISS_INTR_ON);
36562+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36563
36564 /* Get the firmware version */
36565 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36566@@ -5218,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36567 kfree(flush_buf);
36568 if (return_code != IO_OK)
36569 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36570- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36571+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36572 free_irq(h->intr[h->intr_mode], h);
36573 }
36574
36575diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36576index 7fda30e..eb5dfe0 100644
36577--- a/drivers/block/cciss.h
36578+++ b/drivers/block/cciss.h
36579@@ -101,7 +101,7 @@ struct ctlr_info
36580 /* information about each logical volume */
36581 drive_info_struct *drv[CISS_MAX_LUN];
36582
36583- struct access_method access;
36584+ struct access_method *access;
36585
36586 /* queue and queue Info */
36587 struct list_head reqQ;
36588diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36589index 639d26b..fd6ad1f 100644
36590--- a/drivers/block/cpqarray.c
36591+++ b/drivers/block/cpqarray.c
36592@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36593 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36594 goto Enomem4;
36595 }
36596- hba[i]->access.set_intr_mask(hba[i], 0);
36597+ hba[i]->access->set_intr_mask(hba[i], 0);
36598 if (request_irq(hba[i]->intr, do_ida_intr,
36599 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36600 {
36601@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36602 add_timer(&hba[i]->timer);
36603
36604 /* Enable IRQ now that spinlock and rate limit timer are set up */
36605- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36606+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36607
36608 for(j=0; j<NWD; j++) {
36609 struct gendisk *disk = ida_gendisk[i][j];
36610@@ -694,7 +694,7 @@ DBGINFO(
36611 for(i=0; i<NR_PRODUCTS; i++) {
36612 if (board_id == products[i].board_id) {
36613 c->product_name = products[i].product_name;
36614- c->access = *(products[i].access);
36615+ c->access = products[i].access;
36616 break;
36617 }
36618 }
36619@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36620 hba[ctlr]->intr = intr;
36621 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36622 hba[ctlr]->product_name = products[j].product_name;
36623- hba[ctlr]->access = *(products[j].access);
36624+ hba[ctlr]->access = products[j].access;
36625 hba[ctlr]->ctlr = ctlr;
36626 hba[ctlr]->board_id = board_id;
36627 hba[ctlr]->pci_dev = NULL; /* not PCI */
36628@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36629
36630 while((c = h->reqQ) != NULL) {
36631 /* Can't do anything if we're busy */
36632- if (h->access.fifo_full(h) == 0)
36633+ if (h->access->fifo_full(h) == 0)
36634 return;
36635
36636 /* Get the first entry from the request Q */
36637@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36638 h->Qdepth--;
36639
36640 /* Tell the controller to do our bidding */
36641- h->access.submit_command(h, c);
36642+ h->access->submit_command(h, c);
36643
36644 /* Get onto the completion Q */
36645 addQ(&h->cmpQ, c);
36646@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36647 unsigned long flags;
36648 __u32 a,a1;
36649
36650- istat = h->access.intr_pending(h);
36651+ istat = h->access->intr_pending(h);
36652 /* Is this interrupt for us? */
36653 if (istat == 0)
36654 return IRQ_NONE;
36655@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36656 */
36657 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36658 if (istat & FIFO_NOT_EMPTY) {
36659- while((a = h->access.command_completed(h))) {
36660+ while((a = h->access->command_completed(h))) {
36661 a1 = a; a &= ~3;
36662 if ((c = h->cmpQ) == NULL)
36663 {
36664@@ -1193,6 +1193,7 @@ out_passthru:
36665 ida_pci_info_struct pciinfo;
36666
36667 if (!arg) return -EINVAL;
36668+ memset(&pciinfo, 0, sizeof(pciinfo));
36669 pciinfo.bus = host->pci_dev->bus->number;
36670 pciinfo.dev_fn = host->pci_dev->devfn;
36671 pciinfo.board_id = host->board_id;
36672@@ -1447,11 +1448,11 @@ static int sendcmd(
36673 /*
36674 * Disable interrupt
36675 */
36676- info_p->access.set_intr_mask(info_p, 0);
36677+ info_p->access->set_intr_mask(info_p, 0);
36678 /* Make sure there is room in the command FIFO */
36679 /* Actually it should be completely empty at this time. */
36680 for (i = 200000; i > 0; i--) {
36681- temp = info_p->access.fifo_full(info_p);
36682+ temp = info_p->access->fifo_full(info_p);
36683 if (temp != 0) {
36684 break;
36685 }
36686@@ -1464,7 +1465,7 @@ DBG(
36687 /*
36688 * Send the cmd
36689 */
36690- info_p->access.submit_command(info_p, c);
36691+ info_p->access->submit_command(info_p, c);
36692 complete = pollcomplete(ctlr);
36693
36694 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36695@@ -1547,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36696 * we check the new geometry. Then turn interrupts back on when
36697 * we're done.
36698 */
36699- host->access.set_intr_mask(host, 0);
36700+ host->access->set_intr_mask(host, 0);
36701 getgeometry(ctlr);
36702- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36703+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36704
36705 for(i=0; i<NWD; i++) {
36706 struct gendisk *disk = ida_gendisk[ctlr][i];
36707@@ -1589,7 +1590,7 @@ static int pollcomplete(int ctlr)
36708 /* Wait (up to 2 seconds) for a command to complete */
36709
36710 for (i = 200000; i > 0; i--) {
36711- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36712+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36713 if (done == 0) {
36714 udelay(10); /* a short fixed delay */
36715 } else
36716diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36717index be73e9d..7fbf140 100644
36718--- a/drivers/block/cpqarray.h
36719+++ b/drivers/block/cpqarray.h
36720@@ -99,7 +99,7 @@ struct ctlr_info {
36721 drv_info_t drv[NWD];
36722 struct proc_dir_entry *proc;
36723
36724- struct access_method access;
36725+ struct access_method *access;
36726
36727 cmdlist_t *reqQ;
36728 cmdlist_t *cmpQ;
36729diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36730index f943aac..99bfd19 100644
36731--- a/drivers/block/drbd/drbd_int.h
36732+++ b/drivers/block/drbd/drbd_int.h
36733@@ -582,7 +582,7 @@ struct drbd_epoch {
36734 struct drbd_tconn *tconn;
36735 struct list_head list;
36736 unsigned int barrier_nr;
36737- atomic_t epoch_size; /* increased on every request added. */
36738+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36739 atomic_t active; /* increased on every req. added, and dec on every finished. */
36740 unsigned long flags;
36741 };
36742@@ -1021,7 +1021,7 @@ struct drbd_conf {
36743 unsigned int al_tr_number;
36744 int al_tr_cycle;
36745 wait_queue_head_t seq_wait;
36746- atomic_t packet_seq;
36747+ atomic_unchecked_t packet_seq;
36748 unsigned int peer_seq;
36749 spinlock_t peer_seq_lock;
36750 unsigned int minor;
36751@@ -1562,7 +1562,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36752 char __user *uoptval;
36753 int err;
36754
36755- uoptval = (char __user __force *)optval;
36756+ uoptval = (char __force_user *)optval;
36757
36758 set_fs(KERNEL_DS);
36759 if (level == SOL_SOCKET)
36760diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36761index a5dca6a..bb27967 100644
36762--- a/drivers/block/drbd/drbd_main.c
36763+++ b/drivers/block/drbd/drbd_main.c
36764@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36765 p->sector = sector;
36766 p->block_id = block_id;
36767 p->blksize = blksize;
36768- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36769+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36770 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36771 }
36772
36773@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36774 return -EIO;
36775 p->sector = cpu_to_be64(req->i.sector);
36776 p->block_id = (unsigned long)req;
36777- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36778+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36779 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36780 if (mdev->state.conn >= C_SYNC_SOURCE &&
36781 mdev->state.conn <= C_PAUSED_SYNC_T)
36782@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36783 {
36784 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36785
36786- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36787- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36788+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36789+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36790 kfree(tconn->current_epoch);
36791
36792 idr_destroy(&tconn->volumes);
36793diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36794index 9e3f441..4044d47 100644
36795--- a/drivers/block/drbd/drbd_nl.c
36796+++ b/drivers/block/drbd/drbd_nl.c
36797@@ -3339,7 +3339,7 @@ out:
36798
36799 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36800 {
36801- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36802+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36803 struct sk_buff *msg;
36804 struct drbd_genlmsghdr *d_out;
36805 unsigned seq;
36806@@ -3352,7 +3352,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36807 return;
36808 }
36809
36810- seq = atomic_inc_return(&drbd_genl_seq);
36811+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36812 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36813 if (!msg)
36814 goto failed;
36815diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36816index 4222aff..1f79506 100644
36817--- a/drivers/block/drbd/drbd_receiver.c
36818+++ b/drivers/block/drbd/drbd_receiver.c
36819@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36820 {
36821 int err;
36822
36823- atomic_set(&mdev->packet_seq, 0);
36824+ atomic_set_unchecked(&mdev->packet_seq, 0);
36825 mdev->peer_seq = 0;
36826
36827 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36828@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36829 do {
36830 next_epoch = NULL;
36831
36832- epoch_size = atomic_read(&epoch->epoch_size);
36833+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36834
36835 switch (ev & ~EV_CLEANUP) {
36836 case EV_PUT:
36837@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36838 rv = FE_DESTROYED;
36839 } else {
36840 epoch->flags = 0;
36841- atomic_set(&epoch->epoch_size, 0);
36842+ atomic_set_unchecked(&epoch->epoch_size, 0);
36843 /* atomic_set(&epoch->active, 0); is already zero */
36844 if (rv == FE_STILL_LIVE)
36845 rv = FE_RECYCLED;
36846@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36847 conn_wait_active_ee_empty(tconn);
36848 drbd_flush(tconn);
36849
36850- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36851+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36852 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36853 if (epoch)
36854 break;
36855@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36856 }
36857
36858 epoch->flags = 0;
36859- atomic_set(&epoch->epoch_size, 0);
36860+ atomic_set_unchecked(&epoch->epoch_size, 0);
36861 atomic_set(&epoch->active, 0);
36862
36863 spin_lock(&tconn->epoch_lock);
36864- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36865+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36866 list_add(&epoch->list, &tconn->current_epoch->list);
36867 tconn->current_epoch = epoch;
36868 tconn->epochs++;
36869@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36870
36871 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36872 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36873- atomic_inc(&tconn->current_epoch->epoch_size);
36874+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36875 err2 = drbd_drain_block(mdev, pi->size);
36876 if (!err)
36877 err = err2;
36878@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36879
36880 spin_lock(&tconn->epoch_lock);
36881 peer_req->epoch = tconn->current_epoch;
36882- atomic_inc(&peer_req->epoch->epoch_size);
36883+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36884 atomic_inc(&peer_req->epoch->active);
36885 spin_unlock(&tconn->epoch_lock);
36886
36887@@ -4347,7 +4347,7 @@ struct data_cmd {
36888 int expect_payload;
36889 size_t pkt_size;
36890 int (*fn)(struct drbd_tconn *, struct packet_info *);
36891-};
36892+} __do_const;
36893
36894 static struct data_cmd drbd_cmd_handler[] = {
36895 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36896@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36897 if (!list_empty(&tconn->current_epoch->list))
36898 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36899 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36900- atomic_set(&tconn->current_epoch->epoch_size, 0);
36901+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36902 tconn->send.seen_any_write_yet = false;
36903
36904 conn_info(tconn, "Connection closed\n");
36905@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36906 struct asender_cmd {
36907 size_t pkt_size;
36908 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36909-};
36910+} __do_const;
36911
36912 static struct asender_cmd asender_tbl[] = {
36913 [P_PING] = { 0, got_Ping },
36914diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36915index d92d50f..a7e9d97 100644
36916--- a/drivers/block/loop.c
36917+++ b/drivers/block/loop.c
36918@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36919
36920 file_start_write(file);
36921 set_fs(get_ds());
36922- bw = file->f_op->write(file, buf, len, &pos);
36923+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36924 set_fs(old_fs);
36925 file_end_write(file);
36926 if (likely(bw == len))
36927diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36928index f5d0ea1..c62380a 100644
36929--- a/drivers/block/pktcdvd.c
36930+++ b/drivers/block/pktcdvd.c
36931@@ -84,7 +84,7 @@
36932 #define MAX_SPEED 0xffff
36933
36934 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
36935- ~(sector_t)((pd)->settings.size - 1))
36936+ ~(sector_t)((pd)->settings.size - 1UL))
36937
36938 static DEFINE_MUTEX(pktcdvd_mutex);
36939 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
36940diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36941index 8a3aff7..d7538c2 100644
36942--- a/drivers/cdrom/cdrom.c
36943+++ b/drivers/cdrom/cdrom.c
36944@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36945 ENSURE(reset, CDC_RESET);
36946 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36947 cdi->mc_flags = 0;
36948- cdo->n_minors = 0;
36949 cdi->options = CDO_USE_FFLAGS;
36950
36951 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36952@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36953 else
36954 cdi->cdda_method = CDDA_OLD;
36955
36956- if (!cdo->generic_packet)
36957- cdo->generic_packet = cdrom_dummy_generic_packet;
36958+ if (!cdo->generic_packet) {
36959+ pax_open_kernel();
36960+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36961+ pax_close_kernel();
36962+ }
36963
36964 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36965 mutex_lock(&cdrom_mutex);
36966@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36967 if (cdi->exit)
36968 cdi->exit(cdi);
36969
36970- cdi->ops->n_minors--;
36971 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36972 }
36973
36974@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36975 */
36976 nr = nframes;
36977 do {
36978- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36979+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36980 if (cgc.buffer)
36981 break;
36982
36983@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36984 struct cdrom_device_info *cdi;
36985 int ret;
36986
36987- ret = scnprintf(info + *pos, max_size - *pos, header);
36988+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36989 if (!ret)
36990 return 1;
36991
36992diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36993index 4afcb65..a68a32d 100644
36994--- a/drivers/cdrom/gdrom.c
36995+++ b/drivers/cdrom/gdrom.c
36996@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36997 .audio_ioctl = gdrom_audio_ioctl,
36998 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36999 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
37000- .n_minors = 1,
37001 };
37002
37003 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
37004diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
37005index 3bb6fa3..34013fb 100644
37006--- a/drivers/char/Kconfig
37007+++ b/drivers/char/Kconfig
37008@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
37009
37010 config DEVKMEM
37011 bool "/dev/kmem virtual device support"
37012- default y
37013+ default n
37014+ depends on !GRKERNSEC_KMEM
37015 help
37016 Say Y here if you want to support the /dev/kmem device. The
37017 /dev/kmem device is rarely used, but can be used for certain
37018@@ -582,6 +583,7 @@ config DEVPORT
37019 bool
37020 depends on !M68K
37021 depends on ISA || PCI
37022+ depends on !GRKERNSEC_KMEM
37023 default y
37024
37025 source "drivers/s390/char/Kconfig"
37026diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
37027index a48e05b..6bac831 100644
37028--- a/drivers/char/agp/compat_ioctl.c
37029+++ b/drivers/char/agp/compat_ioctl.c
37030@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
37031 return -ENOMEM;
37032 }
37033
37034- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
37035+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
37036 sizeof(*usegment) * ureserve.seg_count)) {
37037 kfree(usegment);
37038 kfree(ksegment);
37039diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
37040index 2e04433..771f2cc 100644
37041--- a/drivers/char/agp/frontend.c
37042+++ b/drivers/char/agp/frontend.c
37043@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37044 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
37045 return -EFAULT;
37046
37047- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
37048+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
37049 return -EFAULT;
37050
37051 client = agp_find_client_by_pid(reserve.pid);
37052@@ -847,7 +847,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37053 if (segment == NULL)
37054 return -ENOMEM;
37055
37056- if (copy_from_user(segment, (void __user *) reserve.seg_list,
37057+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
37058 sizeof(struct agp_segment) * reserve.seg_count)) {
37059 kfree(segment);
37060 return -EFAULT;
37061diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
37062index 4f94375..413694e 100644
37063--- a/drivers/char/genrtc.c
37064+++ b/drivers/char/genrtc.c
37065@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
37066 switch (cmd) {
37067
37068 case RTC_PLL_GET:
37069+ memset(&pll, 0, sizeof(pll));
37070 if (get_rtc_pll(&pll))
37071 return -EINVAL;
37072 else
37073diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
37074index d784650..e8bfd69 100644
37075--- a/drivers/char/hpet.c
37076+++ b/drivers/char/hpet.c
37077@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
37078 }
37079
37080 static int
37081-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
37082+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
37083 struct hpet_info *info)
37084 {
37085 struct hpet_timer __iomem *timer;
37086diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
37087index 86fe45c..c0ea948 100644
37088--- a/drivers/char/hw_random/intel-rng.c
37089+++ b/drivers/char/hw_random/intel-rng.c
37090@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
37091
37092 if (no_fwh_detect)
37093 return -ENODEV;
37094- printk(warning);
37095+ printk("%s", warning);
37096 return -EBUSY;
37097 }
37098
37099diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
37100index 4445fa1..7c6de37 100644
37101--- a/drivers/char/ipmi/ipmi_msghandler.c
37102+++ b/drivers/char/ipmi/ipmi_msghandler.c
37103@@ -420,7 +420,7 @@ struct ipmi_smi {
37104 struct proc_dir_entry *proc_dir;
37105 char proc_dir_name[10];
37106
37107- atomic_t stats[IPMI_NUM_STATS];
37108+ atomic_unchecked_t stats[IPMI_NUM_STATS];
37109
37110 /*
37111 * run_to_completion duplicate of smb_info, smi_info
37112@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
37113
37114
37115 #define ipmi_inc_stat(intf, stat) \
37116- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
37117+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
37118 #define ipmi_get_stat(intf, stat) \
37119- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
37120+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
37121
37122 static int is_lan_addr(struct ipmi_addr *addr)
37123 {
37124@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
37125 INIT_LIST_HEAD(&intf->cmd_rcvrs);
37126 init_waitqueue_head(&intf->waitq);
37127 for (i = 0; i < IPMI_NUM_STATS; i++)
37128- atomic_set(&intf->stats[i], 0);
37129+ atomic_set_unchecked(&intf->stats[i], 0);
37130
37131 intf->proc_dir = NULL;
37132
37133diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
37134index af4b23f..79806fc 100644
37135--- a/drivers/char/ipmi/ipmi_si_intf.c
37136+++ b/drivers/char/ipmi/ipmi_si_intf.c
37137@@ -275,7 +275,7 @@ struct smi_info {
37138 unsigned char slave_addr;
37139
37140 /* Counters and things for the proc filesystem. */
37141- atomic_t stats[SI_NUM_STATS];
37142+ atomic_unchecked_t stats[SI_NUM_STATS];
37143
37144 struct task_struct *thread;
37145
37146@@ -284,9 +284,9 @@ struct smi_info {
37147 };
37148
37149 #define smi_inc_stat(smi, stat) \
37150- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
37151+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
37152 #define smi_get_stat(smi, stat) \
37153- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
37154+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
37155
37156 #define SI_MAX_PARMS 4
37157
37158@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
37159 atomic_set(&new_smi->req_events, 0);
37160 new_smi->run_to_completion = 0;
37161 for (i = 0; i < SI_NUM_STATS; i++)
37162- atomic_set(&new_smi->stats[i], 0);
37163+ atomic_set_unchecked(&new_smi->stats[i], 0);
37164
37165 new_smi->interrupt_disabled = 1;
37166 atomic_set(&new_smi->stop_operation, 0);
37167diff --git a/drivers/char/mem.c b/drivers/char/mem.c
37168index 1ccbe94..6ad651a 100644
37169--- a/drivers/char/mem.c
37170+++ b/drivers/char/mem.c
37171@@ -18,6 +18,7 @@
37172 #include <linux/raw.h>
37173 #include <linux/tty.h>
37174 #include <linux/capability.h>
37175+#include <linux/security.h>
37176 #include <linux/ptrace.h>
37177 #include <linux/device.h>
37178 #include <linux/highmem.h>
37179@@ -38,6 +39,10 @@
37180
37181 #define DEVPORT_MINOR 4
37182
37183+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37184+extern const struct file_operations grsec_fops;
37185+#endif
37186+
37187 static inline unsigned long size_inside_page(unsigned long start,
37188 unsigned long size)
37189 {
37190@@ -69,9 +74,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37191
37192 while (cursor < to) {
37193 if (!devmem_is_allowed(pfn)) {
37194+#ifdef CONFIG_GRKERNSEC_KMEM
37195+ gr_handle_mem_readwrite(from, to);
37196+#else
37197 printk(KERN_INFO
37198 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
37199 current->comm, from, to);
37200+#endif
37201 return 0;
37202 }
37203 cursor += PAGE_SIZE;
37204@@ -79,6 +88,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37205 }
37206 return 1;
37207 }
37208+#elif defined(CONFIG_GRKERNSEC_KMEM)
37209+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37210+{
37211+ return 0;
37212+}
37213 #else
37214 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37215 {
37216@@ -121,6 +135,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37217
37218 while (count > 0) {
37219 unsigned long remaining;
37220+ char *temp;
37221
37222 sz = size_inside_page(p, count);
37223
37224@@ -136,7 +151,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37225 if (!ptr)
37226 return -EFAULT;
37227
37228- remaining = copy_to_user(buf, ptr, sz);
37229+#ifdef CONFIG_PAX_USERCOPY
37230+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37231+ if (!temp) {
37232+ unxlate_dev_mem_ptr(p, ptr);
37233+ return -ENOMEM;
37234+ }
37235+ memcpy(temp, ptr, sz);
37236+#else
37237+ temp = ptr;
37238+#endif
37239+
37240+ remaining = copy_to_user(buf, temp, sz);
37241+
37242+#ifdef CONFIG_PAX_USERCOPY
37243+ kfree(temp);
37244+#endif
37245+
37246 unxlate_dev_mem_ptr(p, ptr);
37247 if (remaining)
37248 return -EFAULT;
37249@@ -379,7 +410,7 @@ static ssize_t read_oldmem(struct file *file, char __user *buf,
37250 else
37251 csize = count;
37252
37253- rc = copy_oldmem_page(pfn, buf, csize, offset, 1);
37254+ rc = copy_oldmem_page(pfn, (char __force_kernel *)buf, csize, offset, 1);
37255 if (rc < 0)
37256 return rc;
37257 buf += csize;
37258@@ -399,9 +430,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37259 size_t count, loff_t *ppos)
37260 {
37261 unsigned long p = *ppos;
37262- ssize_t low_count, read, sz;
37263+ ssize_t low_count, read, sz, err = 0;
37264 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
37265- int err = 0;
37266
37267 read = 0;
37268 if (p < (unsigned long) high_memory) {
37269@@ -423,6 +453,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37270 }
37271 #endif
37272 while (low_count > 0) {
37273+ char *temp;
37274+
37275 sz = size_inside_page(p, low_count);
37276
37277 /*
37278@@ -432,7 +464,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37279 */
37280 kbuf = xlate_dev_kmem_ptr((char *)p);
37281
37282- if (copy_to_user(buf, kbuf, sz))
37283+#ifdef CONFIG_PAX_USERCOPY
37284+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37285+ if (!temp)
37286+ return -ENOMEM;
37287+ memcpy(temp, kbuf, sz);
37288+#else
37289+ temp = kbuf;
37290+#endif
37291+
37292+ err = copy_to_user(buf, temp, sz);
37293+
37294+#ifdef CONFIG_PAX_USERCOPY
37295+ kfree(temp);
37296+#endif
37297+
37298+ if (err)
37299 return -EFAULT;
37300 buf += sz;
37301 p += sz;
37302@@ -869,6 +916,9 @@ static const struct memdev {
37303 #ifdef CONFIG_CRASH_DUMP
37304 [12] = { "oldmem", 0, &oldmem_fops, NULL },
37305 #endif
37306+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37307+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
37308+#endif
37309 };
37310
37311 static int memory_open(struct inode *inode, struct file *filp)
37312@@ -940,7 +990,7 @@ static int __init chr_dev_init(void)
37313 continue;
37314
37315 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
37316- NULL, devlist[minor].name);
37317+ NULL, "%s", devlist[minor].name);
37318 }
37319
37320 return tty_init();
37321diff --git a/drivers/char/mwave/tp3780i.c b/drivers/char/mwave/tp3780i.c
37322index c689697..04e6d6a2 100644
37323--- a/drivers/char/mwave/tp3780i.c
37324+++ b/drivers/char/mwave/tp3780i.c
37325@@ -479,6 +479,7 @@ int tp3780I_QueryAbilities(THINKPAD_BD_DATA * pBDData, MW_ABILITIES * pAbilities
37326 PRINTK_2(TRACE_TP3780I,
37327 "tp3780i::tp3780I_QueryAbilities entry pBDData %p\n", pBDData);
37328
37329+ memset(pAbilities, 0, sizeof(*pAbilities));
37330 /* fill out standard constant fields */
37331 pAbilities->instr_per_sec = pBDData->rDspSettings.uIps;
37332 pAbilities->data_size = pBDData->rDspSettings.uDStoreSize;
37333diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
37334index 9df78e2..01ba9ae 100644
37335--- a/drivers/char/nvram.c
37336+++ b/drivers/char/nvram.c
37337@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
37338
37339 spin_unlock_irq(&rtc_lock);
37340
37341- if (copy_to_user(buf, contents, tmp - contents))
37342+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
37343 return -EFAULT;
37344
37345 *ppos = i;
37346diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
37347index 5c5cc00..ac9edb7 100644
37348--- a/drivers/char/pcmcia/synclink_cs.c
37349+++ b/drivers/char/pcmcia/synclink_cs.c
37350@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37351
37352 if (debug_level >= DEBUG_LEVEL_INFO)
37353 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
37354- __FILE__, __LINE__, info->device_name, port->count);
37355+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
37356
37357- WARN_ON(!port->count);
37358+ WARN_ON(!atomic_read(&port->count));
37359
37360 if (tty_port_close_start(port, tty, filp) == 0)
37361 goto cleanup;
37362@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37363 cleanup:
37364 if (debug_level >= DEBUG_LEVEL_INFO)
37365 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
37366- tty->driver->name, port->count);
37367+ tty->driver->name, atomic_read(&port->count));
37368 }
37369
37370 /* Wait until the transmitter is empty.
37371@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37372
37373 if (debug_level >= DEBUG_LEVEL_INFO)
37374 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
37375- __FILE__, __LINE__, tty->driver->name, port->count);
37376+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
37377
37378 /* If port is closing, signal caller to try again */
37379 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
37380@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37381 goto cleanup;
37382 }
37383 spin_lock(&port->lock);
37384- port->count++;
37385+ atomic_inc(&port->count);
37386 spin_unlock(&port->lock);
37387 spin_unlock_irqrestore(&info->netlock, flags);
37388
37389- if (port->count == 1) {
37390+ if (atomic_read(&port->count) == 1) {
37391 /* 1st open on this device, init hardware */
37392 retval = startup(info, tty);
37393 if (retval < 0)
37394@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
37395 unsigned short new_crctype;
37396
37397 /* return error if TTY interface open */
37398- if (info->port.count)
37399+ if (atomic_read(&info->port.count))
37400 return -EBUSY;
37401
37402 switch (encoding)
37403@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
37404
37405 /* arbitrate between network and tty opens */
37406 spin_lock_irqsave(&info->netlock, flags);
37407- if (info->port.count != 0 || info->netcount != 0) {
37408+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
37409 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
37410 spin_unlock_irqrestore(&info->netlock, flags);
37411 return -EBUSY;
37412@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37413 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
37414
37415 /* return error if TTY interface open */
37416- if (info->port.count)
37417+ if (atomic_read(&info->port.count))
37418 return -EBUSY;
37419
37420 if (cmd != SIOCWANDEV)
37421diff --git a/drivers/char/random.c b/drivers/char/random.c
37422index 35487e8..dac8bd1 100644
37423--- a/drivers/char/random.c
37424+++ b/drivers/char/random.c
37425@@ -272,8 +272,13 @@
37426 /*
37427 * Configuration information
37428 */
37429+#ifdef CONFIG_GRKERNSEC_RANDNET
37430+#define INPUT_POOL_WORDS 512
37431+#define OUTPUT_POOL_WORDS 128
37432+#else
37433 #define INPUT_POOL_WORDS 128
37434 #define OUTPUT_POOL_WORDS 32
37435+#endif
37436 #define SEC_XFER_SIZE 512
37437 #define EXTRACT_SIZE 10
37438
37439@@ -313,10 +318,17 @@ static struct poolinfo {
37440 int poolwords;
37441 int tap1, tap2, tap3, tap4, tap5;
37442 } poolinfo_table[] = {
37443+#ifdef CONFIG_GRKERNSEC_RANDNET
37444+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
37445+ { 512, 411, 308, 208, 104, 1 },
37446+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
37447+ { 128, 103, 76, 51, 25, 1 },
37448+#else
37449 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
37450 { 128, 103, 76, 51, 25, 1 },
37451 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
37452 { 32, 26, 20, 14, 7, 1 },
37453+#endif
37454 #if 0
37455 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
37456 { 2048, 1638, 1231, 819, 411, 1 },
37457@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
37458 input_rotate += i ? 7 : 14;
37459 }
37460
37461- ACCESS_ONCE(r->input_rotate) = input_rotate;
37462- ACCESS_ONCE(r->add_ptr) = i;
37463+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
37464+ ACCESS_ONCE_RW(r->add_ptr) = i;
37465 smp_wmb();
37466
37467 if (out)
37468@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
37469
37470 extract_buf(r, tmp);
37471 i = min_t(int, nbytes, EXTRACT_SIZE);
37472- if (copy_to_user(buf, tmp, i)) {
37473+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
37474 ret = -EFAULT;
37475 break;
37476 }
37477@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
37478 #include <linux/sysctl.h>
37479
37480 static int min_read_thresh = 8, min_write_thresh;
37481-static int max_read_thresh = INPUT_POOL_WORDS * 32;
37482+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
37483 static int max_write_thresh = INPUT_POOL_WORDS * 32;
37484 static char sysctl_bootid[16];
37485
37486@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
37487 static int proc_do_uuid(ctl_table *table, int write,
37488 void __user *buffer, size_t *lenp, loff_t *ppos)
37489 {
37490- ctl_table fake_table;
37491+ ctl_table_no_const fake_table;
37492 unsigned char buf[64], tmp_uuid[16], *uuid;
37493
37494 uuid = table->data;
37495diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
37496index bf2349db..5456d53 100644
37497--- a/drivers/char/sonypi.c
37498+++ b/drivers/char/sonypi.c
37499@@ -54,6 +54,7 @@
37500
37501 #include <asm/uaccess.h>
37502 #include <asm/io.h>
37503+#include <asm/local.h>
37504
37505 #include <linux/sonypi.h>
37506
37507@@ -490,7 +491,7 @@ static struct sonypi_device {
37508 spinlock_t fifo_lock;
37509 wait_queue_head_t fifo_proc_list;
37510 struct fasync_struct *fifo_async;
37511- int open_count;
37512+ local_t open_count;
37513 int model;
37514 struct input_dev *input_jog_dev;
37515 struct input_dev *input_key_dev;
37516@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
37517 static int sonypi_misc_release(struct inode *inode, struct file *file)
37518 {
37519 mutex_lock(&sonypi_device.lock);
37520- sonypi_device.open_count--;
37521+ local_dec(&sonypi_device.open_count);
37522 mutex_unlock(&sonypi_device.lock);
37523 return 0;
37524 }
37525@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
37526 {
37527 mutex_lock(&sonypi_device.lock);
37528 /* Flush input queue on first open */
37529- if (!sonypi_device.open_count)
37530+ if (!local_read(&sonypi_device.open_count))
37531 kfifo_reset(&sonypi_device.fifo);
37532- sonypi_device.open_count++;
37533+ local_inc(&sonypi_device.open_count);
37534 mutex_unlock(&sonypi_device.lock);
37535
37536 return 0;
37537diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
37538index 64420b3..5c40b56 100644
37539--- a/drivers/char/tpm/tpm_acpi.c
37540+++ b/drivers/char/tpm/tpm_acpi.c
37541@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37542 virt = acpi_os_map_memory(start, len);
37543 if (!virt) {
37544 kfree(log->bios_event_log);
37545+ log->bios_event_log = NULL;
37546 printk("%s: ERROR - Unable to map memory\n", __func__);
37547 return -EIO;
37548 }
37549
37550- memcpy_fromio(log->bios_event_log, virt, len);
37551+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37552
37553 acpi_os_unmap_memory(virt, len);
37554 return 0;
37555diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37556index 84ddc55..1d32f1e 100644
37557--- a/drivers/char/tpm/tpm_eventlog.c
37558+++ b/drivers/char/tpm/tpm_eventlog.c
37559@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37560 event = addr;
37561
37562 if ((event->event_type == 0 && event->event_size == 0) ||
37563- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37564+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37565 return NULL;
37566
37567 return addr;
37568@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37569 return NULL;
37570
37571 if ((event->event_type == 0 && event->event_size == 0) ||
37572- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37573+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37574 return NULL;
37575
37576 (*pos)++;
37577@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37578 int i;
37579
37580 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37581- seq_putc(m, data[i]);
37582+ if (!seq_putc(m, data[i]))
37583+ return -EFAULT;
37584
37585 return 0;
37586 }
37587diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37588index fc45567..fa2a590 100644
37589--- a/drivers/char/virtio_console.c
37590+++ b/drivers/char/virtio_console.c
37591@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37592 if (to_user) {
37593 ssize_t ret;
37594
37595- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37596+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37597 if (ret)
37598 return -EFAULT;
37599 } else {
37600@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37601 if (!port_has_data(port) && !port->host_connected)
37602 return 0;
37603
37604- return fill_readbuf(port, ubuf, count, true);
37605+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37606 }
37607
37608 static int wait_port_writable(struct port *port, bool nonblock)
37609diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37610index a33f46f..a720eed 100644
37611--- a/drivers/clk/clk-composite.c
37612+++ b/drivers/clk/clk-composite.c
37613@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37614 struct clk *clk;
37615 struct clk_init_data init;
37616 struct clk_composite *composite;
37617- struct clk_ops *clk_composite_ops;
37618+ clk_ops_no_const *clk_composite_ops;
37619
37620 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37621 if (!composite) {
37622diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37623index bd11315..7f87098 100644
37624--- a/drivers/clk/socfpga/clk.c
37625+++ b/drivers/clk/socfpga/clk.c
37626@@ -22,6 +22,7 @@
37627 #include <linux/clk-provider.h>
37628 #include <linux/io.h>
37629 #include <linux/of.h>
37630+#include <asm/pgtable.h>
37631
37632 /* Clock Manager offsets */
37633 #define CLKMGR_CTRL 0x0
37634@@ -135,8 +136,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37635 if (strcmp(clk_name, "main_pll") || strcmp(clk_name, "periph_pll") ||
37636 strcmp(clk_name, "sdram_pll")) {
37637 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37638- clk_pll_ops.enable = clk_gate_ops.enable;
37639- clk_pll_ops.disable = clk_gate_ops.disable;
37640+ pax_open_kernel();
37641+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37642+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37643+ pax_close_kernel();
37644 }
37645
37646 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37647diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
37648index a2b2541..bc1e7ff 100644
37649--- a/drivers/clocksource/arm_arch_timer.c
37650+++ b/drivers/clocksource/arm_arch_timer.c
37651@@ -264,7 +264,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
37652 return NOTIFY_OK;
37653 }
37654
37655-static struct notifier_block arch_timer_cpu_nb __cpuinitdata = {
37656+static struct notifier_block arch_timer_cpu_nb = {
37657 .notifier_call = arch_timer_cpu_notify,
37658 };
37659
37660diff --git a/drivers/clocksource/bcm_kona_timer.c b/drivers/clocksource/bcm_kona_timer.c
37661index 350f493..489479e 100644
37662--- a/drivers/clocksource/bcm_kona_timer.c
37663+++ b/drivers/clocksource/bcm_kona_timer.c
37664@@ -199,7 +199,7 @@ static struct irqaction kona_timer_irq = {
37665 .handler = kona_timer_interrupt,
37666 };
37667
37668-static void __init kona_timer_init(void)
37669+static void __init kona_timer_init(struct device_node *np)
37670 {
37671 kona_timers_init();
37672 kona_timer_clockevents_init();
37673diff --git a/drivers/clocksource/metag_generic.c b/drivers/clocksource/metag_generic.c
37674index ade7513..069445f 100644
37675--- a/drivers/clocksource/metag_generic.c
37676+++ b/drivers/clocksource/metag_generic.c
37677@@ -169,7 +169,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
37678 return NOTIFY_OK;
37679 }
37680
37681-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
37682+static struct notifier_block arch_timer_cpu_nb = {
37683 .notifier_call = arch_timer_cpu_notify,
37684 };
37685
37686diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37687index edc089e..bc7c0bc 100644
37688--- a/drivers/cpufreq/acpi-cpufreq.c
37689+++ b/drivers/cpufreq/acpi-cpufreq.c
37690@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37691 return sprintf(buf, "%u\n", boost_enabled);
37692 }
37693
37694-static struct global_attr global_boost = __ATTR(boost, 0644,
37695+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37696 show_global_boost,
37697 store_global_boost);
37698
37699@@ -705,8 +705,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37700 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37701 per_cpu(acfreq_data, cpu) = data;
37702
37703- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37704- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37705+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37706+ pax_open_kernel();
37707+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37708+ pax_close_kernel();
37709+ }
37710
37711 result = acpi_processor_register_performance(data->acpi_data, cpu);
37712 if (result)
37713@@ -832,7 +835,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37714 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37715 break;
37716 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37717- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37718+ pax_open_kernel();
37719+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37720+ pax_close_kernel();
37721 policy->cur = get_cur_freq_on_cpu(cpu);
37722 break;
37723 default:
37724@@ -843,8 +848,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37725 acpi_processor_notify_smm(THIS_MODULE);
37726
37727 /* Check for APERF/MPERF support in hardware */
37728- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
37729- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37730+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
37731+ pax_open_kernel();
37732+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37733+ pax_close_kernel();
37734+ }
37735
37736 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
37737 for (i = 0; i < perf->state_count; i++)
37738diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37739index 6485547..477033e 100644
37740--- a/drivers/cpufreq/cpufreq.c
37741+++ b/drivers/cpufreq/cpufreq.c
37742@@ -1854,7 +1854,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
37743 return NOTIFY_OK;
37744 }
37745
37746-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37747+static struct notifier_block cpufreq_cpu_notifier = {
37748 .notifier_call = cpufreq_cpu_callback,
37749 };
37750
37751@@ -1886,8 +1886,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37752
37753 pr_debug("trying to register driver %s\n", driver_data->name);
37754
37755- if (driver_data->setpolicy)
37756- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37757+ if (driver_data->setpolicy) {
37758+ pax_open_kernel();
37759+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37760+ pax_close_kernel();
37761+ }
37762
37763 write_lock_irqsave(&cpufreq_driver_lock, flags);
37764 if (cpufreq_driver) {
37765diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37766index a86ff72..aad2b03 100644
37767--- a/drivers/cpufreq/cpufreq_governor.c
37768+++ b/drivers/cpufreq/cpufreq_governor.c
37769@@ -235,7 +235,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37770 struct dbs_data *dbs_data;
37771 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37772 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37773- struct od_ops *od_ops = NULL;
37774+ const struct od_ops *od_ops = NULL;
37775 struct od_dbs_tuners *od_tuners = NULL;
37776 struct cs_dbs_tuners *cs_tuners = NULL;
37777 struct cpu_dbs_common_info *cpu_cdbs;
37778@@ -298,7 +298,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37779
37780 if ((cdata->governor == GOV_CONSERVATIVE) &&
37781 (!policy->governor->initialized)) {
37782- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37783+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37784
37785 cpufreq_register_notifier(cs_ops->notifier_block,
37786 CPUFREQ_TRANSITION_NOTIFIER);
37787@@ -315,7 +315,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37788
37789 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37790 (policy->governor->initialized == 1)) {
37791- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37792+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37793
37794 cpufreq_unregister_notifier(cs_ops->notifier_block,
37795 CPUFREQ_TRANSITION_NOTIFIER);
37796diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37797index 0d9e6be..461fd3b 100644
37798--- a/drivers/cpufreq/cpufreq_governor.h
37799+++ b/drivers/cpufreq/cpufreq_governor.h
37800@@ -204,7 +204,7 @@ struct common_dbs_data {
37801 void (*exit)(struct dbs_data *dbs_data);
37802
37803 /* Governor specific ops, see below */
37804- void *gov_ops;
37805+ const void *gov_ops;
37806 };
37807
37808 /* Governer Per policy data */
37809diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37810index c087347..dad6268 100644
37811--- a/drivers/cpufreq/cpufreq_ondemand.c
37812+++ b/drivers/cpufreq/cpufreq_ondemand.c
37813@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37814 (struct cpufreq_policy *, unsigned int, unsigned int),
37815 unsigned int powersave_bias)
37816 {
37817- od_ops.powersave_bias_target = f;
37818+ pax_open_kernel();
37819+ *(void **)&od_ops.powersave_bias_target = f;
37820+ pax_close_kernel();
37821 od_set_powersave_bias(powersave_bias);
37822 }
37823 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37824
37825 void od_unregister_powersave_bias_handler(void)
37826 {
37827- od_ops.powersave_bias_target = generic_powersave_bias_target;
37828+ pax_open_kernel();
37829+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37830+ pax_close_kernel();
37831 od_set_powersave_bias(0);
37832 }
37833 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37834diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37835index bfd6273..e39dd63 100644
37836--- a/drivers/cpufreq/cpufreq_stats.c
37837+++ b/drivers/cpufreq/cpufreq_stats.c
37838@@ -365,7 +365,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37839 }
37840
37841 /* priority=1 so this will get called before cpufreq_remove_dev */
37842-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37843+static struct notifier_block cpufreq_stat_cpu_notifier = {
37844 .notifier_call = cpufreq_stat_cpu_callback,
37845 .priority = 1,
37846 };
37847diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37848index 421ef37..e708530c 100644
37849--- a/drivers/cpufreq/p4-clockmod.c
37850+++ b/drivers/cpufreq/p4-clockmod.c
37851@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37852 case 0x0F: /* Core Duo */
37853 case 0x16: /* Celeron Core */
37854 case 0x1C: /* Atom */
37855- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37856+ pax_open_kernel();
37857+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37858+ pax_close_kernel();
37859 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37860 case 0x0D: /* Pentium M (Dothan) */
37861- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37862+ pax_open_kernel();
37863+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37864+ pax_close_kernel();
37865 /* fall through */
37866 case 0x09: /* Pentium M (Banias) */
37867 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37868@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37869
37870 /* on P-4s, the TSC runs with constant frequency independent whether
37871 * throttling is active or not. */
37872- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37873+ pax_open_kernel();
37874+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37875+ pax_close_kernel();
37876
37877 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37878 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37879diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37880index c71ee14..7c2e183 100644
37881--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37882+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37883@@ -18,14 +18,12 @@
37884 #include <asm/head.h>
37885 #include <asm/timer.h>
37886
37887-static struct cpufreq_driver *cpufreq_us3_driver;
37888-
37889 struct us3_freq_percpu_info {
37890 struct cpufreq_frequency_table table[4];
37891 };
37892
37893 /* Indexed by cpu number. */
37894-static struct us3_freq_percpu_info *us3_freq_table;
37895+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37896
37897 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37898 * in the Safari config register.
37899@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37900
37901 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37902 {
37903- if (cpufreq_us3_driver)
37904- us3_set_cpu_divider_index(policy, 0);
37905+ us3_set_cpu_divider_index(policy->cpu, 0);
37906
37907 return 0;
37908 }
37909
37910+static int __init us3_freq_init(void);
37911+static void __exit us3_freq_exit(void);
37912+
37913+static struct cpufreq_driver cpufreq_us3_driver = {
37914+ .init = us3_freq_cpu_init,
37915+ .verify = us3_freq_verify,
37916+ .target = us3_freq_target,
37917+ .get = us3_freq_get,
37918+ .exit = us3_freq_cpu_exit,
37919+ .owner = THIS_MODULE,
37920+ .name = "UltraSPARC-III",
37921+
37922+};
37923+
37924 static int __init us3_freq_init(void)
37925 {
37926 unsigned long manuf, impl, ver;
37927@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
37928 (impl == CHEETAH_IMPL ||
37929 impl == CHEETAH_PLUS_IMPL ||
37930 impl == JAGUAR_IMPL ||
37931- impl == PANTHER_IMPL)) {
37932- struct cpufreq_driver *driver;
37933-
37934- ret = -ENOMEM;
37935- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
37936- if (!driver)
37937- goto err_out;
37938-
37939- us3_freq_table = kzalloc(
37940- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
37941- GFP_KERNEL);
37942- if (!us3_freq_table)
37943- goto err_out;
37944-
37945- driver->init = us3_freq_cpu_init;
37946- driver->verify = us3_freq_verify;
37947- driver->target = us3_freq_target;
37948- driver->get = us3_freq_get;
37949- driver->exit = us3_freq_cpu_exit;
37950- driver->owner = THIS_MODULE,
37951- strcpy(driver->name, "UltraSPARC-III");
37952-
37953- cpufreq_us3_driver = driver;
37954- ret = cpufreq_register_driver(driver);
37955- if (ret)
37956- goto err_out;
37957-
37958- return 0;
37959-
37960-err_out:
37961- if (driver) {
37962- kfree(driver);
37963- cpufreq_us3_driver = NULL;
37964- }
37965- kfree(us3_freq_table);
37966- us3_freq_table = NULL;
37967- return ret;
37968- }
37969+ impl == PANTHER_IMPL))
37970+ return cpufreq_register_driver(&cpufreq_us3_driver);
37971
37972 return -ENODEV;
37973 }
37974
37975 static void __exit us3_freq_exit(void)
37976 {
37977- if (cpufreq_us3_driver) {
37978- cpufreq_unregister_driver(cpufreq_us3_driver);
37979- kfree(cpufreq_us3_driver);
37980- cpufreq_us3_driver = NULL;
37981- kfree(us3_freq_table);
37982- us3_freq_table = NULL;
37983- }
37984+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37985 }
37986
37987 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37988diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37989index 618e6f4..e89d915 100644
37990--- a/drivers/cpufreq/speedstep-centrino.c
37991+++ b/drivers/cpufreq/speedstep-centrino.c
37992@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37993 !cpu_has(cpu, X86_FEATURE_EST))
37994 return -ENODEV;
37995
37996- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37997- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37998+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37999+ pax_open_kernel();
38000+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38001+ pax_close_kernel();
38002+ }
38003
38004 if (policy->cpu != 0)
38005 return -ENODEV;
38006diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
38007index c3a93fe..e808f24 100644
38008--- a/drivers/cpuidle/cpuidle.c
38009+++ b/drivers/cpuidle/cpuidle.c
38010@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
38011
38012 static void poll_idle_init(struct cpuidle_driver *drv)
38013 {
38014- struct cpuidle_state *state = &drv->states[0];
38015+ cpuidle_state_no_const *state = &drv->states[0];
38016
38017 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
38018 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
38019diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
38020index ea2f8e7..70ac501 100644
38021--- a/drivers/cpuidle/governor.c
38022+++ b/drivers/cpuidle/governor.c
38023@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
38024 mutex_lock(&cpuidle_lock);
38025 if (__cpuidle_find_governor(gov->name) == NULL) {
38026 ret = 0;
38027- list_add_tail(&gov->governor_list, &cpuidle_governors);
38028+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
38029 if (!cpuidle_curr_governor ||
38030 cpuidle_curr_governor->rating < gov->rating)
38031 cpuidle_switch_governor(gov);
38032@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
38033 new_gov = cpuidle_replace_governor(gov->rating);
38034 cpuidle_switch_governor(new_gov);
38035 }
38036- list_del(&gov->governor_list);
38037+ pax_list_del((struct list_head *)&gov->governor_list);
38038 mutex_unlock(&cpuidle_lock);
38039 }
38040
38041diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
38042index 428754a..8bdf9cc 100644
38043--- a/drivers/cpuidle/sysfs.c
38044+++ b/drivers/cpuidle/sysfs.c
38045@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
38046 NULL
38047 };
38048
38049-static struct attribute_group cpuidle_attr_group = {
38050+static attribute_group_no_const cpuidle_attr_group = {
38051 .attrs = cpuidle_default_attrs,
38052 .name = "cpuidle",
38053 };
38054diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
38055index ebf130e..e32d8a9 100644
38056--- a/drivers/crypto/hifn_795x.c
38057+++ b/drivers/crypto/hifn_795x.c
38058@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
38059 MODULE_PARM_DESC(hifn_pll_ref,
38060 "PLL reference clock (pci[freq] or ext[freq], default ext)");
38061
38062-static atomic_t hifn_dev_number;
38063+static atomic_unchecked_t hifn_dev_number;
38064
38065 #define ACRYPTO_OP_DECRYPT 0
38066 #define ACRYPTO_OP_ENCRYPT 1
38067@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
38068 goto err_out_disable_pci_device;
38069
38070 snprintf(name, sizeof(name), "hifn%d",
38071- atomic_inc_return(&hifn_dev_number)-1);
38072+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
38073
38074 err = pci_request_regions(pdev, name);
38075 if (err)
38076diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
38077index 3b36797..db0b0c0 100644
38078--- a/drivers/devfreq/devfreq.c
38079+++ b/drivers/devfreq/devfreq.c
38080@@ -477,7 +477,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
38081 GFP_KERNEL);
38082 devfreq->last_stat_updated = jiffies;
38083
38084- dev_set_name(&devfreq->dev, dev_name(dev));
38085+ dev_set_name(&devfreq->dev, "%s", dev_name(dev));
38086 err = device_register(&devfreq->dev);
38087 if (err) {
38088 put_device(&devfreq->dev);
38089@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
38090 goto err_out;
38091 }
38092
38093- list_add(&governor->node, &devfreq_governor_list);
38094+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
38095
38096 list_for_each_entry(devfreq, &devfreq_list, node) {
38097 int ret = 0;
38098@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
38099 }
38100 }
38101
38102- list_del(&governor->node);
38103+ pax_list_del((struct list_head *)&governor->node);
38104 err_out:
38105 mutex_unlock(&devfreq_list_lock);
38106
38107diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
38108index b70709b..1d8d02a 100644
38109--- a/drivers/dma/sh/shdma.c
38110+++ b/drivers/dma/sh/shdma.c
38111@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
38112 return ret;
38113 }
38114
38115-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
38116+static struct notifier_block sh_dmae_nmi_notifier = {
38117 .notifier_call = sh_dmae_nmi_handler,
38118
38119 /* Run before NMI debug handler and KGDB */
38120diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
38121index 211021d..201d47f 100644
38122--- a/drivers/edac/edac_device.c
38123+++ b/drivers/edac/edac_device.c
38124@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
38125 */
38126 int edac_device_alloc_index(void)
38127 {
38128- static atomic_t device_indexes = ATOMIC_INIT(0);
38129+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
38130
38131- return atomic_inc_return(&device_indexes) - 1;
38132+ return atomic_inc_return_unchecked(&device_indexes) - 1;
38133 }
38134 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
38135
38136diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
38137index c4d700a..0b57abd 100644
38138--- a/drivers/edac/edac_mc_sysfs.c
38139+++ b/drivers/edac/edac_mc_sysfs.c
38140@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
38141 struct dev_ch_attribute {
38142 struct device_attribute attr;
38143 int channel;
38144-};
38145+} __do_const;
38146
38147 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
38148 struct dev_ch_attribute dev_attr_legacy_##_name = \
38149@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
38150 }
38151
38152 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
38153+ pax_open_kernel();
38154 if (mci->get_sdram_scrub_rate) {
38155- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38156- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38157+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38158+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38159 }
38160 if (mci->set_sdram_scrub_rate) {
38161- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38162- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38163+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38164+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38165 }
38166+ pax_close_kernel();
38167 err = device_create_file(&mci->dev,
38168 &dev_attr_sdram_scrub_rate);
38169 if (err) {
38170diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
38171index dd370f9..0281629 100644
38172--- a/drivers/edac/edac_pci.c
38173+++ b/drivers/edac/edac_pci.c
38174@@ -29,7 +29,7 @@
38175
38176 static DEFINE_MUTEX(edac_pci_ctls_mutex);
38177 static LIST_HEAD(edac_pci_list);
38178-static atomic_t pci_indexes = ATOMIC_INIT(0);
38179+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
38180
38181 /*
38182 * edac_pci_alloc_ctl_info
38183@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
38184 */
38185 int edac_pci_alloc_index(void)
38186 {
38187- return atomic_inc_return(&pci_indexes) - 1;
38188+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
38189 }
38190 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
38191
38192diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
38193index e8658e4..22746d6 100644
38194--- a/drivers/edac/edac_pci_sysfs.c
38195+++ b/drivers/edac/edac_pci_sysfs.c
38196@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
38197 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
38198 static int edac_pci_poll_msec = 1000; /* one second workq period */
38199
38200-static atomic_t pci_parity_count = ATOMIC_INIT(0);
38201-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
38202+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
38203+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
38204
38205 static struct kobject *edac_pci_top_main_kobj;
38206 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
38207@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
38208 void *value;
38209 ssize_t(*show) (void *, char *);
38210 ssize_t(*store) (void *, const char *, size_t);
38211-};
38212+} __do_const;
38213
38214 /* Set of show/store abstract level functions for PCI Parity object */
38215 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
38216@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38217 edac_printk(KERN_CRIT, EDAC_PCI,
38218 "Signaled System Error on %s\n",
38219 pci_name(dev));
38220- atomic_inc(&pci_nonparity_count);
38221+ atomic_inc_unchecked(&pci_nonparity_count);
38222 }
38223
38224 if (status & (PCI_STATUS_PARITY)) {
38225@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38226 "Master Data Parity Error on %s\n",
38227 pci_name(dev));
38228
38229- atomic_inc(&pci_parity_count);
38230+ atomic_inc_unchecked(&pci_parity_count);
38231 }
38232
38233 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38234@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38235 "Detected Parity Error on %s\n",
38236 pci_name(dev));
38237
38238- atomic_inc(&pci_parity_count);
38239+ atomic_inc_unchecked(&pci_parity_count);
38240 }
38241 }
38242
38243@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38244 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
38245 "Signaled System Error on %s\n",
38246 pci_name(dev));
38247- atomic_inc(&pci_nonparity_count);
38248+ atomic_inc_unchecked(&pci_nonparity_count);
38249 }
38250
38251 if (status & (PCI_STATUS_PARITY)) {
38252@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38253 "Master Data Parity Error on "
38254 "%s\n", pci_name(dev));
38255
38256- atomic_inc(&pci_parity_count);
38257+ atomic_inc_unchecked(&pci_parity_count);
38258 }
38259
38260 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38261@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38262 "Detected Parity Error on %s\n",
38263 pci_name(dev));
38264
38265- atomic_inc(&pci_parity_count);
38266+ atomic_inc_unchecked(&pci_parity_count);
38267 }
38268 }
38269 }
38270@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
38271 if (!check_pci_errors)
38272 return;
38273
38274- before_count = atomic_read(&pci_parity_count);
38275+ before_count = atomic_read_unchecked(&pci_parity_count);
38276
38277 /* scan all PCI devices looking for a Parity Error on devices and
38278 * bridges.
38279@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
38280 /* Only if operator has selected panic on PCI Error */
38281 if (edac_pci_get_panic_on_pe()) {
38282 /* If the count is different 'after' from 'before' */
38283- if (before_count != atomic_read(&pci_parity_count))
38284+ if (before_count != atomic_read_unchecked(&pci_parity_count))
38285 panic("EDAC: PCI Parity Error");
38286 }
38287 }
38288diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
38289index 51b7e3a..aa8a3e8 100644
38290--- a/drivers/edac/mce_amd.h
38291+++ b/drivers/edac/mce_amd.h
38292@@ -77,7 +77,7 @@ struct amd_decoder_ops {
38293 bool (*mc0_mce)(u16, u8);
38294 bool (*mc1_mce)(u16, u8);
38295 bool (*mc2_mce)(u16, u8);
38296-};
38297+} __no_const;
38298
38299 void amd_report_gart_errors(bool);
38300 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
38301diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
38302index 57ea7f4..af06b76 100644
38303--- a/drivers/firewire/core-card.c
38304+++ b/drivers/firewire/core-card.c
38305@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
38306 const struct fw_card_driver *driver,
38307 struct device *device)
38308 {
38309- static atomic_t index = ATOMIC_INIT(-1);
38310+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
38311
38312- card->index = atomic_inc_return(&index);
38313+ card->index = atomic_inc_return_unchecked(&index);
38314 card->driver = driver;
38315 card->device = device;
38316 card->current_tlabel = 0;
38317@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
38318
38319 void fw_core_remove_card(struct fw_card *card)
38320 {
38321- struct fw_card_driver dummy_driver = dummy_driver_template;
38322+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
38323
38324 card->driver->update_phy_reg(card, 4,
38325 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
38326diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
38327index 664a6ff..af13580 100644
38328--- a/drivers/firewire/core-device.c
38329+++ b/drivers/firewire/core-device.c
38330@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
38331 struct config_rom_attribute {
38332 struct device_attribute attr;
38333 u32 key;
38334-};
38335+} __do_const;
38336
38337 static ssize_t show_immediate(struct device *dev,
38338 struct device_attribute *dattr, char *buf)
38339diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
38340index 28a94c7..58da63a 100644
38341--- a/drivers/firewire/core-transaction.c
38342+++ b/drivers/firewire/core-transaction.c
38343@@ -38,6 +38,7 @@
38344 #include <linux/timer.h>
38345 #include <linux/types.h>
38346 #include <linux/workqueue.h>
38347+#include <linux/sched.h>
38348
38349 #include <asm/byteorder.h>
38350
38351diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
38352index 515a42c..5ecf3ba 100644
38353--- a/drivers/firewire/core.h
38354+++ b/drivers/firewire/core.h
38355@@ -111,6 +111,7 @@ struct fw_card_driver {
38356
38357 int (*stop_iso)(struct fw_iso_context *ctx);
38358 };
38359+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
38360
38361 void fw_card_initialize(struct fw_card *card,
38362 const struct fw_card_driver *driver, struct device *device);
38363diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
38364index 94a58a0..f5eba42 100644
38365--- a/drivers/firmware/dmi-id.c
38366+++ b/drivers/firmware/dmi-id.c
38367@@ -16,7 +16,7 @@
38368 struct dmi_device_attribute{
38369 struct device_attribute dev_attr;
38370 int field;
38371-};
38372+} __do_const;
38373 #define to_dmi_dev_attr(_dev_attr) \
38374 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
38375
38376diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
38377index b95159b..841ae55 100644
38378--- a/drivers/firmware/dmi_scan.c
38379+++ b/drivers/firmware/dmi_scan.c
38380@@ -497,11 +497,6 @@ void __init dmi_scan_machine(void)
38381 }
38382 }
38383 else {
38384- /*
38385- * no iounmap() for that ioremap(); it would be a no-op, but
38386- * it's so early in setup that sucker gets confused into doing
38387- * what it shouldn't if we actually call it.
38388- */
38389 p = dmi_ioremap(0xF0000, 0x10000);
38390 if (p == NULL)
38391 goto error;
38392@@ -786,7 +781,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
38393 if (buf == NULL)
38394 return -1;
38395
38396- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
38397+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
38398
38399 iounmap(buf);
38400 return 0;
38401diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
38402index 5145fa3..0d3babd 100644
38403--- a/drivers/firmware/efi/efi.c
38404+++ b/drivers/firmware/efi/efi.c
38405@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
38406 };
38407
38408 static struct efivars generic_efivars;
38409-static struct efivar_operations generic_ops;
38410+static efivar_operations_no_const generic_ops __read_only;
38411
38412 static int generic_ops_register(void)
38413 {
38414- generic_ops.get_variable = efi.get_variable;
38415- generic_ops.set_variable = efi.set_variable;
38416- generic_ops.get_next_variable = efi.get_next_variable;
38417- generic_ops.query_variable_store = efi_query_variable_store;
38418+ pax_open_kernel();
38419+ *(void **)&generic_ops.get_variable = efi.get_variable;
38420+ *(void **)&generic_ops.set_variable = efi.set_variable;
38421+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
38422+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
38423+ pax_close_kernel();
38424
38425 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
38426 }
38427diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
38428index 8bd1bb6..c48b0c6 100644
38429--- a/drivers/firmware/efi/efivars.c
38430+++ b/drivers/firmware/efi/efivars.c
38431@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
38432 static int
38433 create_efivars_bin_attributes(void)
38434 {
38435- struct bin_attribute *attr;
38436+ bin_attribute_no_const *attr;
38437 int error;
38438
38439 /* new_var */
38440diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
38441index 2a90ba6..07f3733 100644
38442--- a/drivers/firmware/google/memconsole.c
38443+++ b/drivers/firmware/google/memconsole.c
38444@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
38445 if (!found_memconsole())
38446 return -ENODEV;
38447
38448- memconsole_bin_attr.size = memconsole_length;
38449+ pax_open_kernel();
38450+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
38451+ pax_close_kernel();
38452
38453 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
38454
38455diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
38456index e16d932..f0206ef 100644
38457--- a/drivers/gpio/gpio-ich.c
38458+++ b/drivers/gpio/gpio-ich.c
38459@@ -69,7 +69,7 @@ struct ichx_desc {
38460 /* Some chipsets have quirks, let these use their own request/get */
38461 int (*request)(struct gpio_chip *chip, unsigned offset);
38462 int (*get)(struct gpio_chip *chip, unsigned offset);
38463-};
38464+} __do_const;
38465
38466 static struct {
38467 spinlock_t lock;
38468diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
38469index 9902732..64b62dd 100644
38470--- a/drivers/gpio/gpio-vr41xx.c
38471+++ b/drivers/gpio/gpio-vr41xx.c
38472@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
38473 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
38474 maskl, pendl, maskh, pendh);
38475
38476- atomic_inc(&irq_err_count);
38477+ atomic_inc_unchecked(&irq_err_count);
38478
38479 return -EINVAL;
38480 }
38481diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
38482index ed1334e..ee0dd42 100644
38483--- a/drivers/gpu/drm/drm_crtc_helper.c
38484+++ b/drivers/gpu/drm/drm_crtc_helper.c
38485@@ -321,7 +321,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
38486 struct drm_crtc *tmp;
38487 int crtc_mask = 1;
38488
38489- WARN(!crtc, "checking null crtc?\n");
38490+ BUG_ON(!crtc);
38491
38492 dev = crtc->dev;
38493
38494diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
38495index 9cc247f..36aa285 100644
38496--- a/drivers/gpu/drm/drm_drv.c
38497+++ b/drivers/gpu/drm/drm_drv.c
38498@@ -306,7 +306,7 @@ module_exit(drm_core_exit);
38499 /**
38500 * Copy and IOCTL return string to user space
38501 */
38502-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
38503+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
38504 {
38505 int len;
38506
38507@@ -376,7 +376,7 @@ long drm_ioctl(struct file *filp,
38508 struct drm_file *file_priv = filp->private_data;
38509 struct drm_device *dev;
38510 const struct drm_ioctl_desc *ioctl = NULL;
38511- drm_ioctl_t *func;
38512+ drm_ioctl_no_const_t func;
38513 unsigned int nr = DRM_IOCTL_NR(cmd);
38514 int retcode = -EINVAL;
38515 char stack_kdata[128];
38516@@ -389,7 +389,7 @@ long drm_ioctl(struct file *filp,
38517 return -ENODEV;
38518
38519 atomic_inc(&dev->ioctl_count);
38520- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
38521+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
38522 ++file_priv->ioctl_count;
38523
38524 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
38525diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
38526index 429e07d..e681a2c 100644
38527--- a/drivers/gpu/drm/drm_fops.c
38528+++ b/drivers/gpu/drm/drm_fops.c
38529@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
38530 }
38531
38532 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
38533- atomic_set(&dev->counts[i], 0);
38534+ atomic_set_unchecked(&dev->counts[i], 0);
38535
38536 dev->sigdata.lock = NULL;
38537
38538@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
38539 if (drm_device_is_unplugged(dev))
38540 return -ENODEV;
38541
38542- if (!dev->open_count++)
38543+ if (local_inc_return(&dev->open_count) == 1)
38544 need_setup = 1;
38545 mutex_lock(&dev->struct_mutex);
38546 old_imapping = inode->i_mapping;
38547@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
38548 retcode = drm_open_helper(inode, filp, dev);
38549 if (retcode)
38550 goto err_undo;
38551- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
38552+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
38553 if (need_setup) {
38554 retcode = drm_setup(dev);
38555 if (retcode)
38556@@ -166,7 +166,7 @@ err_undo:
38557 iput(container_of(dev->dev_mapping, struct inode, i_data));
38558 dev->dev_mapping = old_mapping;
38559 mutex_unlock(&dev->struct_mutex);
38560- dev->open_count--;
38561+ local_dec(&dev->open_count);
38562 return retcode;
38563 }
38564 EXPORT_SYMBOL(drm_open);
38565@@ -441,7 +441,7 @@ int drm_release(struct inode *inode, struct file *filp)
38566
38567 mutex_lock(&drm_global_mutex);
38568
38569- DRM_DEBUG("open_count = %d\n", dev->open_count);
38570+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38571
38572 if (dev->driver->preclose)
38573 dev->driver->preclose(dev, file_priv);
38574@@ -450,10 +450,10 @@ int drm_release(struct inode *inode, struct file *filp)
38575 * Begin inline drm_release
38576 */
38577
38578- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38579+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38580 task_pid_nr(current),
38581 (long)old_encode_dev(file_priv->minor->device),
38582- dev->open_count);
38583+ local_read(&dev->open_count));
38584
38585 /* Release any auth tokens that might point to this file_priv,
38586 (do that under the drm_global_mutex) */
38587@@ -550,8 +550,8 @@ int drm_release(struct inode *inode, struct file *filp)
38588 * End inline drm_release
38589 */
38590
38591- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38592- if (!--dev->open_count) {
38593+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38594+ if (local_dec_and_test(&dev->open_count)) {
38595 if (atomic_read(&dev->ioctl_count)) {
38596 DRM_ERROR("Device busy: %d\n",
38597 atomic_read(&dev->ioctl_count));
38598diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38599index f731116..629842c 100644
38600--- a/drivers/gpu/drm/drm_global.c
38601+++ b/drivers/gpu/drm/drm_global.c
38602@@ -36,7 +36,7 @@
38603 struct drm_global_item {
38604 struct mutex mutex;
38605 void *object;
38606- int refcount;
38607+ atomic_t refcount;
38608 };
38609
38610 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38611@@ -49,7 +49,7 @@ void drm_global_init(void)
38612 struct drm_global_item *item = &glob[i];
38613 mutex_init(&item->mutex);
38614 item->object = NULL;
38615- item->refcount = 0;
38616+ atomic_set(&item->refcount, 0);
38617 }
38618 }
38619
38620@@ -59,7 +59,7 @@ void drm_global_release(void)
38621 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38622 struct drm_global_item *item = &glob[i];
38623 BUG_ON(item->object != NULL);
38624- BUG_ON(item->refcount != 0);
38625+ BUG_ON(atomic_read(&item->refcount) != 0);
38626 }
38627 }
38628
38629@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38630 void *object;
38631
38632 mutex_lock(&item->mutex);
38633- if (item->refcount == 0) {
38634+ if (atomic_read(&item->refcount) == 0) {
38635 item->object = kzalloc(ref->size, GFP_KERNEL);
38636 if (unlikely(item->object == NULL)) {
38637 ret = -ENOMEM;
38638@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38639 goto out_err;
38640
38641 }
38642- ++item->refcount;
38643+ atomic_inc(&item->refcount);
38644 ref->object = item->object;
38645 object = item->object;
38646 mutex_unlock(&item->mutex);
38647@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38648 struct drm_global_item *item = &glob[ref->global_type];
38649
38650 mutex_lock(&item->mutex);
38651- BUG_ON(item->refcount == 0);
38652+ BUG_ON(atomic_read(&item->refcount) == 0);
38653 BUG_ON(ref->object != item->object);
38654- if (--item->refcount == 0) {
38655+ if (atomic_dec_and_test(&item->refcount)) {
38656 ref->release(ref);
38657 item->object = NULL;
38658 }
38659diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38660index d4b20ce..77a8d41 100644
38661--- a/drivers/gpu/drm/drm_info.c
38662+++ b/drivers/gpu/drm/drm_info.c
38663@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38664 struct drm_local_map *map;
38665 struct drm_map_list *r_list;
38666
38667- /* Hardcoded from _DRM_FRAME_BUFFER,
38668- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38669- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38670- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38671+ static const char * const types[] = {
38672+ [_DRM_FRAME_BUFFER] = "FB",
38673+ [_DRM_REGISTERS] = "REG",
38674+ [_DRM_SHM] = "SHM",
38675+ [_DRM_AGP] = "AGP",
38676+ [_DRM_SCATTER_GATHER] = "SG",
38677+ [_DRM_CONSISTENT] = "PCI",
38678+ [_DRM_GEM] = "GEM" };
38679 const char *type;
38680 int i;
38681
38682@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38683 map = r_list->map;
38684 if (!map)
38685 continue;
38686- if (map->type < 0 || map->type > 5)
38687+ if (map->type >= ARRAY_SIZE(types))
38688 type = "??";
38689 else
38690 type = types[map->type];
38691@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38692 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38693 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38694 vma->vm_flags & VM_IO ? 'i' : '-',
38695+#ifdef CONFIG_GRKERNSEC_HIDESYM
38696+ 0);
38697+#else
38698 vma->vm_pgoff);
38699+#endif
38700
38701 #if defined(__i386__)
38702 pgprot = pgprot_val(vma->vm_page_prot);
38703diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38704index 2f4c434..dd12cd2 100644
38705--- a/drivers/gpu/drm/drm_ioc32.c
38706+++ b/drivers/gpu/drm/drm_ioc32.c
38707@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38708 request = compat_alloc_user_space(nbytes);
38709 if (!access_ok(VERIFY_WRITE, request, nbytes))
38710 return -EFAULT;
38711- list = (struct drm_buf_desc *) (request + 1);
38712+ list = (struct drm_buf_desc __user *) (request + 1);
38713
38714 if (__put_user(count, &request->count)
38715 || __put_user(list, &request->list))
38716@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38717 request = compat_alloc_user_space(nbytes);
38718 if (!access_ok(VERIFY_WRITE, request, nbytes))
38719 return -EFAULT;
38720- list = (struct drm_buf_pub *) (request + 1);
38721+ list = (struct drm_buf_pub __user *) (request + 1);
38722
38723 if (__put_user(count, &request->count)
38724 || __put_user(list, &request->list))
38725@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38726 return 0;
38727 }
38728
38729-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38730+drm_ioctl_compat_t drm_compat_ioctls[] = {
38731 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38732 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38733 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38734@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38735 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38736 {
38737 unsigned int nr = DRM_IOCTL_NR(cmd);
38738- drm_ioctl_compat_t *fn;
38739 int ret;
38740
38741 /* Assume that ioctls without an explicit compat routine will just
38742@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38743 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38744 return drm_ioctl(filp, cmd, arg);
38745
38746- fn = drm_compat_ioctls[nr];
38747-
38748- if (fn != NULL)
38749- ret = (*fn) (filp, cmd, arg);
38750+ if (drm_compat_ioctls[nr] != NULL)
38751+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38752 else
38753 ret = drm_ioctl(filp, cmd, arg);
38754
38755diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
38756index e77bd8b..1571b85 100644
38757--- a/drivers/gpu/drm/drm_ioctl.c
38758+++ b/drivers/gpu/drm/drm_ioctl.c
38759@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
38760 stats->data[i].value =
38761 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
38762 else
38763- stats->data[i].value = atomic_read(&dev->counts[i]);
38764+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
38765 stats->data[i].type = dev->types[i];
38766 }
38767
38768diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38769index d752c96..fe08455 100644
38770--- a/drivers/gpu/drm/drm_lock.c
38771+++ b/drivers/gpu/drm/drm_lock.c
38772@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38773 if (drm_lock_take(&master->lock, lock->context)) {
38774 master->lock.file_priv = file_priv;
38775 master->lock.lock_time = jiffies;
38776- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38777+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38778 break; /* Got lock */
38779 }
38780
38781@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38782 return -EINVAL;
38783 }
38784
38785- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38786+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38787
38788 if (drm_lock_free(&master->lock, lock->context)) {
38789 /* FIXME: Should really bail out here. */
38790diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38791index 16f3ec5..b28f9ca 100644
38792--- a/drivers/gpu/drm/drm_stub.c
38793+++ b/drivers/gpu/drm/drm_stub.c
38794@@ -501,7 +501,7 @@ void drm_unplug_dev(struct drm_device *dev)
38795
38796 drm_device_set_unplugged(dev);
38797
38798- if (dev->open_count == 0) {
38799+ if (local_read(&dev->open_count) == 0) {
38800 drm_put_dev(dev);
38801 }
38802 mutex_unlock(&drm_global_mutex);
38803diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38804index 0229665..f61329c 100644
38805--- a/drivers/gpu/drm/drm_sysfs.c
38806+++ b/drivers/gpu/drm/drm_sysfs.c
38807@@ -499,7 +499,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38808 int drm_sysfs_device_add(struct drm_minor *minor)
38809 {
38810 int err;
38811- char *minor_str;
38812+ const char *minor_str;
38813
38814 minor->kdev.parent = minor->dev->dev;
38815
38816diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38817index 004ecdf..db1f6e0 100644
38818--- a/drivers/gpu/drm/i810/i810_dma.c
38819+++ b/drivers/gpu/drm/i810/i810_dma.c
38820@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38821 dma->buflist[vertex->idx],
38822 vertex->discard, vertex->used);
38823
38824- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38825- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38826+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38827+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38828 sarea_priv->last_enqueue = dev_priv->counter - 1;
38829 sarea_priv->last_dispatch = (int)hw_status[5];
38830
38831@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38832 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38833 mc->last_render);
38834
38835- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38836- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38837+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38838+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38839 sarea_priv->last_enqueue = dev_priv->counter - 1;
38840 sarea_priv->last_dispatch = (int)hw_status[5];
38841
38842diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38843index 6e0acad..93c8289 100644
38844--- a/drivers/gpu/drm/i810/i810_drv.h
38845+++ b/drivers/gpu/drm/i810/i810_drv.h
38846@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38847 int page_flipping;
38848
38849 wait_queue_head_t irq_queue;
38850- atomic_t irq_received;
38851- atomic_t irq_emitted;
38852+ atomic_unchecked_t irq_received;
38853+ atomic_unchecked_t irq_emitted;
38854
38855 int front_offset;
38856 } drm_i810_private_t;
38857diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38858index e913d32..4d9b351 100644
38859--- a/drivers/gpu/drm/i915/i915_debugfs.c
38860+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38861@@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38862 I915_READ(GTIMR));
38863 }
38864 seq_printf(m, "Interrupts received: %d\n",
38865- atomic_read(&dev_priv->irq_received));
38866+ atomic_read_unchecked(&dev_priv->irq_received));
38867 for_each_ring(ring, dev_priv, i) {
38868 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38869 seq_printf(m,
38870diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38871index 17d9b0b..860e6d9 100644
38872--- a/drivers/gpu/drm/i915/i915_dma.c
38873+++ b/drivers/gpu/drm/i915/i915_dma.c
38874@@ -1259,7 +1259,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38875 bool can_switch;
38876
38877 spin_lock(&dev->count_lock);
38878- can_switch = (dev->open_count == 0);
38879+ can_switch = (local_read(&dev->open_count) == 0);
38880 spin_unlock(&dev->count_lock);
38881 return can_switch;
38882 }
38883diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38884index 47d8b68..52f5d8d 100644
38885--- a/drivers/gpu/drm/i915/i915_drv.h
38886+++ b/drivers/gpu/drm/i915/i915_drv.h
38887@@ -916,7 +916,7 @@ typedef struct drm_i915_private {
38888 drm_dma_handle_t *status_page_dmah;
38889 struct resource mch_res;
38890
38891- atomic_t irq_received;
38892+ atomic_unchecked_t irq_received;
38893
38894 /* protects the irq masks */
38895 spinlock_t irq_lock;
38896@@ -1813,7 +1813,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
38897 struct drm_i915_private *dev_priv, unsigned port);
38898 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
38899 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
38900-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
38901+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
38902 {
38903 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
38904 }
38905diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38906index 117ce38..eefd237 100644
38907--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38908+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38909@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38910
38911 static int
38912 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38913- int count)
38914+ unsigned int count)
38915 {
38916- int i;
38917+ unsigned int i;
38918 int relocs_total = 0;
38919 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38920
38921diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38922index 3c59584..500f2e9 100644
38923--- a/drivers/gpu/drm/i915/i915_ioc32.c
38924+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38925@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38926 (unsigned long)request);
38927 }
38928
38929-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38930+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38931 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38932 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38933 [DRM_I915_GETPARAM] = compat_i915_getparam,
38934@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38935 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38936 {
38937 unsigned int nr = DRM_IOCTL_NR(cmd);
38938- drm_ioctl_compat_t *fn = NULL;
38939 int ret;
38940
38941 if (nr < DRM_COMMAND_BASE)
38942 return drm_compat_ioctl(filp, cmd, arg);
38943
38944- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38945- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38946-
38947- if (fn != NULL)
38948+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38949+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38950 ret = (*fn) (filp, cmd, arg);
38951- else
38952+ } else
38953 ret = drm_ioctl(filp, cmd, arg);
38954
38955 return ret;
38956diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38957index e5e32869..1678f36 100644
38958--- a/drivers/gpu/drm/i915/i915_irq.c
38959+++ b/drivers/gpu/drm/i915/i915_irq.c
38960@@ -670,7 +670,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38961 int pipe;
38962 u32 pipe_stats[I915_MAX_PIPES];
38963
38964- atomic_inc(&dev_priv->irq_received);
38965+ atomic_inc_unchecked(&dev_priv->irq_received);
38966
38967 while (true) {
38968 iir = I915_READ(VLV_IIR);
38969@@ -835,7 +835,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
38970 irqreturn_t ret = IRQ_NONE;
38971 int i;
38972
38973- atomic_inc(&dev_priv->irq_received);
38974+ atomic_inc_unchecked(&dev_priv->irq_received);
38975
38976 /* disable master interrupt before clearing iir */
38977 de_ier = I915_READ(DEIER);
38978@@ -925,7 +925,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38979 int ret = IRQ_NONE;
38980 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
38981
38982- atomic_inc(&dev_priv->irq_received);
38983+ atomic_inc_unchecked(&dev_priv->irq_received);
38984
38985 /* disable master interrupt before clearing iir */
38986 de_ier = I915_READ(DEIER);
38987@@ -2089,7 +2089,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38988 {
38989 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38990
38991- atomic_set(&dev_priv->irq_received, 0);
38992+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38993
38994 I915_WRITE(HWSTAM, 0xeffe);
38995
38996@@ -2124,7 +2124,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38997 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38998 int pipe;
38999
39000- atomic_set(&dev_priv->irq_received, 0);
39001+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39002
39003 /* VLV magic */
39004 I915_WRITE(VLV_IMR, 0);
39005@@ -2411,7 +2411,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
39006 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39007 int pipe;
39008
39009- atomic_set(&dev_priv->irq_received, 0);
39010+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39011
39012 for_each_pipe(pipe)
39013 I915_WRITE(PIPESTAT(pipe), 0);
39014@@ -2490,7 +2490,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
39015 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39016 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39017
39018- atomic_inc(&dev_priv->irq_received);
39019+ atomic_inc_unchecked(&dev_priv->irq_received);
39020
39021 iir = I915_READ16(IIR);
39022 if (iir == 0)
39023@@ -2565,7 +2565,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
39024 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39025 int pipe;
39026
39027- atomic_set(&dev_priv->irq_received, 0);
39028+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39029
39030 if (I915_HAS_HOTPLUG(dev)) {
39031 I915_WRITE(PORT_HOTPLUG_EN, 0);
39032@@ -2664,7 +2664,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
39033 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39034 int pipe, ret = IRQ_NONE;
39035
39036- atomic_inc(&dev_priv->irq_received);
39037+ atomic_inc_unchecked(&dev_priv->irq_received);
39038
39039 iir = I915_READ(IIR);
39040 do {
39041@@ -2791,7 +2791,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
39042 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39043 int pipe;
39044
39045- atomic_set(&dev_priv->irq_received, 0);
39046+ atomic_set_unchecked(&dev_priv->irq_received, 0);
39047
39048 I915_WRITE(PORT_HOTPLUG_EN, 0);
39049 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
39050@@ -2898,7 +2898,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
39051 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39052 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39053
39054- atomic_inc(&dev_priv->irq_received);
39055+ atomic_inc_unchecked(&dev_priv->irq_received);
39056
39057 iir = I915_READ(IIR);
39058
39059diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
39060index eea5982..eeef407 100644
39061--- a/drivers/gpu/drm/i915/intel_display.c
39062+++ b/drivers/gpu/drm/i915/intel_display.c
39063@@ -8935,13 +8935,13 @@ struct intel_quirk {
39064 int subsystem_vendor;
39065 int subsystem_device;
39066 void (*hook)(struct drm_device *dev);
39067-};
39068+} __do_const;
39069
39070 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
39071 struct intel_dmi_quirk {
39072 void (*hook)(struct drm_device *dev);
39073 const struct dmi_system_id (*dmi_id_list)[];
39074-};
39075+} __do_const;
39076
39077 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39078 {
39079@@ -8949,18 +8949,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39080 return 1;
39081 }
39082
39083-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39084+static const struct dmi_system_id intel_dmi_quirks_table[] = {
39085 {
39086- .dmi_id_list = &(const struct dmi_system_id[]) {
39087- {
39088- .callback = intel_dmi_reverse_brightness,
39089- .ident = "NCR Corporation",
39090- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39091- DMI_MATCH(DMI_PRODUCT_NAME, ""),
39092- },
39093- },
39094- { } /* terminating entry */
39095+ .callback = intel_dmi_reverse_brightness,
39096+ .ident = "NCR Corporation",
39097+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39098+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
39099 },
39100+ },
39101+ { } /* terminating entry */
39102+};
39103+
39104+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39105+ {
39106+ .dmi_id_list = &intel_dmi_quirks_table,
39107 .hook = quirk_invert_brightness,
39108 },
39109 };
39110diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
39111index 54558a0..2d97005 100644
39112--- a/drivers/gpu/drm/mga/mga_drv.h
39113+++ b/drivers/gpu/drm/mga/mga_drv.h
39114@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
39115 u32 clear_cmd;
39116 u32 maccess;
39117
39118- atomic_t vbl_received; /**< Number of vblanks received. */
39119+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
39120 wait_queue_head_t fence_queue;
39121- atomic_t last_fence_retired;
39122+ atomic_unchecked_t last_fence_retired;
39123 u32 next_fence_to_post;
39124
39125 unsigned int fb_cpp;
39126diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
39127index 709e90d..89a1c0d 100644
39128--- a/drivers/gpu/drm/mga/mga_ioc32.c
39129+++ b/drivers/gpu/drm/mga/mga_ioc32.c
39130@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
39131 return 0;
39132 }
39133
39134-drm_ioctl_compat_t *mga_compat_ioctls[] = {
39135+drm_ioctl_compat_t mga_compat_ioctls[] = {
39136 [DRM_MGA_INIT] = compat_mga_init,
39137 [DRM_MGA_GETPARAM] = compat_mga_getparam,
39138 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
39139@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
39140 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39141 {
39142 unsigned int nr = DRM_IOCTL_NR(cmd);
39143- drm_ioctl_compat_t *fn = NULL;
39144 int ret;
39145
39146 if (nr < DRM_COMMAND_BASE)
39147 return drm_compat_ioctl(filp, cmd, arg);
39148
39149- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
39150- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39151-
39152- if (fn != NULL)
39153+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
39154+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39155 ret = (*fn) (filp, cmd, arg);
39156- else
39157+ } else
39158 ret = drm_ioctl(filp, cmd, arg);
39159
39160 return ret;
39161diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
39162index 598c281..60d590e 100644
39163--- a/drivers/gpu/drm/mga/mga_irq.c
39164+++ b/drivers/gpu/drm/mga/mga_irq.c
39165@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
39166 if (crtc != 0)
39167 return 0;
39168
39169- return atomic_read(&dev_priv->vbl_received);
39170+ return atomic_read_unchecked(&dev_priv->vbl_received);
39171 }
39172
39173
39174@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39175 /* VBLANK interrupt */
39176 if (status & MGA_VLINEPEN) {
39177 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
39178- atomic_inc(&dev_priv->vbl_received);
39179+ atomic_inc_unchecked(&dev_priv->vbl_received);
39180 drm_handle_vblank(dev, 0);
39181 handled = 1;
39182 }
39183@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39184 if ((prim_start & ~0x03) != (prim_end & ~0x03))
39185 MGA_WRITE(MGA_PRIMEND, prim_end);
39186
39187- atomic_inc(&dev_priv->last_fence_retired);
39188+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
39189 DRM_WAKEUP(&dev_priv->fence_queue);
39190 handled = 1;
39191 }
39192@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
39193 * using fences.
39194 */
39195 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
39196- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
39197+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
39198 - *sequence) <= (1 << 23)));
39199
39200 *sequence = cur_fence;
39201diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
39202index 6aa2137..fe8dc55 100644
39203--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
39204+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
39205@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
39206 struct bit_table {
39207 const char id;
39208 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
39209-};
39210+} __no_const;
39211
39212 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
39213
39214diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
39215index f2b30f8..d0f9a95 100644
39216--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
39217+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
39218@@ -92,7 +92,7 @@ struct nouveau_drm {
39219 struct drm_global_reference mem_global_ref;
39220 struct ttm_bo_global_ref bo_global_ref;
39221 struct ttm_bo_device bdev;
39222- atomic_t validate_sequence;
39223+ atomic_unchecked_t validate_sequence;
39224 int (*move)(struct nouveau_channel *,
39225 struct ttm_buffer_object *,
39226 struct ttm_mem_reg *, struct ttm_mem_reg *);
39227diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
39228index b4b4d0c..b7edc15 100644
39229--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
39230+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
39231@@ -322,7 +322,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
39232 int ret, i;
39233 struct nouveau_bo *res_bo = NULL;
39234
39235- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
39236+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
39237 retry:
39238 if (++trycnt > 100000) {
39239 NV_ERROR(cli, "%s failed and gave up.\n", __func__);
39240@@ -359,7 +359,7 @@ retry:
39241 if (ret) {
39242 validate_fini(op, NULL);
39243 if (unlikely(ret == -EAGAIN)) {
39244- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
39245+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
39246 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
39247 sequence);
39248 if (!ret)
39249diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39250index 08214bc..9208577 100644
39251--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39252+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39253@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
39254 unsigned long arg)
39255 {
39256 unsigned int nr = DRM_IOCTL_NR(cmd);
39257- drm_ioctl_compat_t *fn = NULL;
39258+ drm_ioctl_compat_t fn = NULL;
39259 int ret;
39260
39261 if (nr < DRM_COMMAND_BASE)
39262diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
39263index 25d3495..d81aaf6 100644
39264--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
39265+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
39266@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
39267 bool can_switch;
39268
39269 spin_lock(&dev->count_lock);
39270- can_switch = (dev->open_count == 0);
39271+ can_switch = (local_read(&dev->open_count) == 0);
39272 spin_unlock(&dev->count_lock);
39273 return can_switch;
39274 }
39275diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
39276index 489cb8c..0b8d0d3 100644
39277--- a/drivers/gpu/drm/qxl/qxl_ttm.c
39278+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
39279@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
39280 }
39281 }
39282
39283-static struct vm_operations_struct qxl_ttm_vm_ops;
39284+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
39285 static const struct vm_operations_struct *ttm_vm_ops;
39286
39287 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39288@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
39289 return r;
39290 if (unlikely(ttm_vm_ops == NULL)) {
39291 ttm_vm_ops = vma->vm_ops;
39292+ pax_open_kernel();
39293 qxl_ttm_vm_ops = *ttm_vm_ops;
39294 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
39295+ pax_close_kernel();
39296 }
39297 vma->vm_ops = &qxl_ttm_vm_ops;
39298 return 0;
39299@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
39300 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
39301 {
39302 #if defined(CONFIG_DEBUG_FS)
39303- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
39304- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
39305- unsigned i;
39306+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
39307+ {
39308+ .name = "qxl_mem_mm",
39309+ .show = &qxl_mm_dump_table,
39310+ },
39311+ {
39312+ .name = "qxl_surf_mm",
39313+ .show = &qxl_mm_dump_table,
39314+ }
39315+ };
39316
39317- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
39318- if (i == 0)
39319- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
39320- else
39321- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
39322- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
39323- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
39324- qxl_mem_types_list[i].driver_features = 0;
39325- if (i == 0)
39326- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
39327- else
39328- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
39329+ pax_open_kernel();
39330+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
39331+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
39332+ pax_close_kernel();
39333
39334- }
39335- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
39336+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
39337 #else
39338 return 0;
39339 #endif
39340diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
39341index d4660cf..70dbe65 100644
39342--- a/drivers/gpu/drm/r128/r128_cce.c
39343+++ b/drivers/gpu/drm/r128/r128_cce.c
39344@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
39345
39346 /* GH: Simple idle check.
39347 */
39348- atomic_set(&dev_priv->idle_count, 0);
39349+ atomic_set_unchecked(&dev_priv->idle_count, 0);
39350
39351 /* We don't support anything other than bus-mastering ring mode,
39352 * but the ring can be in either AGP or PCI space for the ring
39353diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
39354index 930c71b..499aded 100644
39355--- a/drivers/gpu/drm/r128/r128_drv.h
39356+++ b/drivers/gpu/drm/r128/r128_drv.h
39357@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
39358 int is_pci;
39359 unsigned long cce_buffers_offset;
39360
39361- atomic_t idle_count;
39362+ atomic_unchecked_t idle_count;
39363
39364 int page_flipping;
39365 int current_page;
39366 u32 crtc_offset;
39367 u32 crtc_offset_cntl;
39368
39369- atomic_t vbl_received;
39370+ atomic_unchecked_t vbl_received;
39371
39372 u32 color_fmt;
39373 unsigned int front_offset;
39374diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
39375index a954c54..9cc595c 100644
39376--- a/drivers/gpu/drm/r128/r128_ioc32.c
39377+++ b/drivers/gpu/drm/r128/r128_ioc32.c
39378@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
39379 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
39380 }
39381
39382-drm_ioctl_compat_t *r128_compat_ioctls[] = {
39383+drm_ioctl_compat_t r128_compat_ioctls[] = {
39384 [DRM_R128_INIT] = compat_r128_init,
39385 [DRM_R128_DEPTH] = compat_r128_depth,
39386 [DRM_R128_STIPPLE] = compat_r128_stipple,
39387@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
39388 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39389 {
39390 unsigned int nr = DRM_IOCTL_NR(cmd);
39391- drm_ioctl_compat_t *fn = NULL;
39392 int ret;
39393
39394 if (nr < DRM_COMMAND_BASE)
39395 return drm_compat_ioctl(filp, cmd, arg);
39396
39397- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
39398- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39399-
39400- if (fn != NULL)
39401+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
39402+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
39403 ret = (*fn) (filp, cmd, arg);
39404- else
39405+ } else
39406 ret = drm_ioctl(filp, cmd, arg);
39407
39408 return ret;
39409diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
39410index 2ea4f09..d391371 100644
39411--- a/drivers/gpu/drm/r128/r128_irq.c
39412+++ b/drivers/gpu/drm/r128/r128_irq.c
39413@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
39414 if (crtc != 0)
39415 return 0;
39416
39417- return atomic_read(&dev_priv->vbl_received);
39418+ return atomic_read_unchecked(&dev_priv->vbl_received);
39419 }
39420
39421 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39422@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
39423 /* VBLANK interrupt */
39424 if (status & R128_CRTC_VBLANK_INT) {
39425 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
39426- atomic_inc(&dev_priv->vbl_received);
39427+ atomic_inc_unchecked(&dev_priv->vbl_received);
39428 drm_handle_vblank(dev, 0);
39429 return IRQ_HANDLED;
39430 }
39431diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
39432index 19bb7e6..de7e2a2 100644
39433--- a/drivers/gpu/drm/r128/r128_state.c
39434+++ b/drivers/gpu/drm/r128/r128_state.c
39435@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
39436
39437 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
39438 {
39439- if (atomic_read(&dev_priv->idle_count) == 0)
39440+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
39441 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
39442 else
39443- atomic_set(&dev_priv->idle_count, 0);
39444+ atomic_set_unchecked(&dev_priv->idle_count, 0);
39445 }
39446
39447 #endif
39448diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
39449index 5a82b6b..9e69c73 100644
39450--- a/drivers/gpu/drm/radeon/mkregtable.c
39451+++ b/drivers/gpu/drm/radeon/mkregtable.c
39452@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
39453 regex_t mask_rex;
39454 regmatch_t match[4];
39455 char buf[1024];
39456- size_t end;
39457+ long end;
39458 int len;
39459 int done = 0;
39460 int r;
39461 unsigned o;
39462 struct offset *offset;
39463 char last_reg_s[10];
39464- int last_reg;
39465+ unsigned long last_reg;
39466
39467 if (regcomp
39468 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
39469diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
39470index b0dc0b6..a9bfe9c 100644
39471--- a/drivers/gpu/drm/radeon/radeon_device.c
39472+++ b/drivers/gpu/drm/radeon/radeon_device.c
39473@@ -1014,7 +1014,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
39474 bool can_switch;
39475
39476 spin_lock(&dev->count_lock);
39477- can_switch = (dev->open_count == 0);
39478+ can_switch = (local_read(&dev->open_count) == 0);
39479 spin_unlock(&dev->count_lock);
39480 return can_switch;
39481 }
39482diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
39483index b369d42..8dd04eb 100644
39484--- a/drivers/gpu/drm/radeon/radeon_drv.h
39485+++ b/drivers/gpu/drm/radeon/radeon_drv.h
39486@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
39487
39488 /* SW interrupt */
39489 wait_queue_head_t swi_queue;
39490- atomic_t swi_emitted;
39491+ atomic_unchecked_t swi_emitted;
39492 int vblank_crtc;
39493 uint32_t irq_enable_reg;
39494 uint32_t r500_disp_irq_reg;
39495diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
39496index c180df8..5fd8186 100644
39497--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
39498+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
39499@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39500 request = compat_alloc_user_space(sizeof(*request));
39501 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
39502 || __put_user(req32.param, &request->param)
39503- || __put_user((void __user *)(unsigned long)req32.value,
39504+ || __put_user((unsigned long)req32.value,
39505 &request->value))
39506 return -EFAULT;
39507
39508@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39509 #define compat_radeon_cp_setparam NULL
39510 #endif /* X86_64 || IA64 */
39511
39512-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39513+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
39514 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
39515 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
39516 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
39517@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39518 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39519 {
39520 unsigned int nr = DRM_IOCTL_NR(cmd);
39521- drm_ioctl_compat_t *fn = NULL;
39522 int ret;
39523
39524 if (nr < DRM_COMMAND_BASE)
39525 return drm_compat_ioctl(filp, cmd, arg);
39526
39527- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
39528- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39529-
39530- if (fn != NULL)
39531+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
39532+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39533 ret = (*fn) (filp, cmd, arg);
39534- else
39535+ } else
39536 ret = drm_ioctl(filp, cmd, arg);
39537
39538 return ret;
39539diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
39540index 8d68e97..9dcfed8 100644
39541--- a/drivers/gpu/drm/radeon/radeon_irq.c
39542+++ b/drivers/gpu/drm/radeon/radeon_irq.c
39543@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
39544 unsigned int ret;
39545 RING_LOCALS;
39546
39547- atomic_inc(&dev_priv->swi_emitted);
39548- ret = atomic_read(&dev_priv->swi_emitted);
39549+ atomic_inc_unchecked(&dev_priv->swi_emitted);
39550+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
39551
39552 BEGIN_RING(4);
39553 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
39554@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
39555 drm_radeon_private_t *dev_priv =
39556 (drm_radeon_private_t *) dev->dev_private;
39557
39558- atomic_set(&dev_priv->swi_emitted, 0);
39559+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
39560 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
39561
39562 dev->max_vblank_count = 0x001fffff;
39563diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
39564index 4d20910..6726b6d 100644
39565--- a/drivers/gpu/drm/radeon/radeon_state.c
39566+++ b/drivers/gpu/drm/radeon/radeon_state.c
39567@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
39568 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
39569 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
39570
39571- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39572+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39573 sarea_priv->nbox * sizeof(depth_boxes[0])))
39574 return -EFAULT;
39575
39576@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
39577 {
39578 drm_radeon_private_t *dev_priv = dev->dev_private;
39579 drm_radeon_getparam_t *param = data;
39580- int value;
39581+ int value = 0;
39582
39583 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
39584
39585diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
39586index 6c0ce89..57a2529 100644
39587--- a/drivers/gpu/drm/radeon/radeon_ttm.c
39588+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
39589@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
39590 man->size = size >> PAGE_SHIFT;
39591 }
39592
39593-static struct vm_operations_struct radeon_ttm_vm_ops;
39594+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39595 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39596
39597 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39598@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39599 }
39600 if (unlikely(ttm_vm_ops == NULL)) {
39601 ttm_vm_ops = vma->vm_ops;
39602+ pax_open_kernel();
39603 radeon_ttm_vm_ops = *ttm_vm_ops;
39604 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39605+ pax_close_kernel();
39606 }
39607 vma->vm_ops = &radeon_ttm_vm_ops;
39608 return 0;
39609@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39610 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39611 {
39612 #if defined(CONFIG_DEBUG_FS)
39613- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39614- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39615+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39616+ {
39617+ .name = "radeon_vram_mm",
39618+ .show = &radeon_mm_dump_table,
39619+ },
39620+ {
39621+ .name = "radeon_gtt_mm",
39622+ .show = &radeon_mm_dump_table,
39623+ },
39624+ {
39625+ .name = "ttm_page_pool",
39626+ .show = &ttm_page_alloc_debugfs,
39627+ },
39628+ {
39629+ .name = "ttm_dma_page_pool",
39630+ .show = &ttm_dma_page_alloc_debugfs,
39631+ },
39632+ };
39633 unsigned i;
39634
39635- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39636- if (i == 0)
39637- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39638- else
39639- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39640- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39641- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39642- radeon_mem_types_list[i].driver_features = 0;
39643- if (i == 0)
39644- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39645- else
39646- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39647-
39648- }
39649- /* Add ttm page pool to debugfs */
39650- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39651- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39652- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39653- radeon_mem_types_list[i].driver_features = 0;
39654- radeon_mem_types_list[i++].data = NULL;
39655+ pax_open_kernel();
39656+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39657+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39658+ pax_close_kernel();
39659 #ifdef CONFIG_SWIOTLB
39660- if (swiotlb_nr_tbl()) {
39661- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39662- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39663- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39664- radeon_mem_types_list[i].driver_features = 0;
39665- radeon_mem_types_list[i++].data = NULL;
39666- }
39667+ if (swiotlb_nr_tbl())
39668+ i++;
39669 #endif
39670 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39671
39672diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39673index 55880d5..9e95342 100644
39674--- a/drivers/gpu/drm/radeon/rs690.c
39675+++ b/drivers/gpu/drm/radeon/rs690.c
39676@@ -327,9 +327,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39677 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39678 rdev->pm.sideport_bandwidth.full)
39679 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
39680- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39681+ read_delay_latency.full = dfixed_const(800 * 1000);
39682 read_delay_latency.full = dfixed_div(read_delay_latency,
39683 rdev->pm.igp_sideport_mclk);
39684+ a.full = dfixed_const(370);
39685+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39686 } else {
39687 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39688 rdev->pm.k8_bandwidth.full)
39689diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39690index dbc2def..0a9f710 100644
39691--- a/drivers/gpu/drm/ttm/ttm_memory.c
39692+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39693@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39694 zone->glob = glob;
39695 glob->zone_kernel = zone;
39696 ret = kobject_init_and_add(
39697- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39698+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39699 if (unlikely(ret != 0)) {
39700 kobject_put(&zone->kobj);
39701 return ret;
39702@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39703 zone->glob = glob;
39704 glob->zone_dma32 = zone;
39705 ret = kobject_init_and_add(
39706- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39707+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39708 if (unlikely(ret != 0)) {
39709 kobject_put(&zone->kobj);
39710 return ret;
39711diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39712index bd2a3b4..122d9ad 100644
39713--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39714+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39715@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
39716 static int ttm_pool_mm_shrink(struct shrinker *shrink,
39717 struct shrink_control *sc)
39718 {
39719- static atomic_t start_pool = ATOMIC_INIT(0);
39720+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39721 unsigned i;
39722- unsigned pool_offset = atomic_add_return(1, &start_pool);
39723+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39724 struct ttm_page_pool *pool;
39725 int shrink_pages = sc->nr_to_scan;
39726
39727diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39728index dc0c065..58a0782 100644
39729--- a/drivers/gpu/drm/udl/udl_fb.c
39730+++ b/drivers/gpu/drm/udl/udl_fb.c
39731@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39732 fb_deferred_io_cleanup(info);
39733 kfree(info->fbdefio);
39734 info->fbdefio = NULL;
39735- info->fbops->fb_mmap = udl_fb_mmap;
39736 }
39737
39738 pr_warn("released /dev/fb%d user=%d count=%d\n",
39739diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39740index 893a650..6190d3b 100644
39741--- a/drivers/gpu/drm/via/via_drv.h
39742+++ b/drivers/gpu/drm/via/via_drv.h
39743@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39744 typedef uint32_t maskarray_t[5];
39745
39746 typedef struct drm_via_irq {
39747- atomic_t irq_received;
39748+ atomic_unchecked_t irq_received;
39749 uint32_t pending_mask;
39750 uint32_t enable_mask;
39751 wait_queue_head_t irq_queue;
39752@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39753 struct timeval last_vblank;
39754 int last_vblank_valid;
39755 unsigned usec_per_vblank;
39756- atomic_t vbl_received;
39757+ atomic_unchecked_t vbl_received;
39758 drm_via_state_t hc_state;
39759 char pci_buf[VIA_PCI_BUF_SIZE];
39760 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39761diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39762index ac98964..5dbf512 100644
39763--- a/drivers/gpu/drm/via/via_irq.c
39764+++ b/drivers/gpu/drm/via/via_irq.c
39765@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39766 if (crtc != 0)
39767 return 0;
39768
39769- return atomic_read(&dev_priv->vbl_received);
39770+ return atomic_read_unchecked(&dev_priv->vbl_received);
39771 }
39772
39773 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39774@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39775
39776 status = VIA_READ(VIA_REG_INTERRUPT);
39777 if (status & VIA_IRQ_VBLANK_PENDING) {
39778- atomic_inc(&dev_priv->vbl_received);
39779- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39780+ atomic_inc_unchecked(&dev_priv->vbl_received);
39781+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39782 do_gettimeofday(&cur_vblank);
39783 if (dev_priv->last_vblank_valid) {
39784 dev_priv->usec_per_vblank =
39785@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39786 dev_priv->last_vblank = cur_vblank;
39787 dev_priv->last_vblank_valid = 1;
39788 }
39789- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39790+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39791 DRM_DEBUG("US per vblank is: %u\n",
39792 dev_priv->usec_per_vblank);
39793 }
39794@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39795
39796 for (i = 0; i < dev_priv->num_irqs; ++i) {
39797 if (status & cur_irq->pending_mask) {
39798- atomic_inc(&cur_irq->irq_received);
39799+ atomic_inc_unchecked(&cur_irq->irq_received);
39800 DRM_WAKEUP(&cur_irq->irq_queue);
39801 handled = 1;
39802 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39803@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39804 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39805 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39806 masks[irq][4]));
39807- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39808+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39809 } else {
39810 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39811 (((cur_irq_sequence =
39812- atomic_read(&cur_irq->irq_received)) -
39813+ atomic_read_unchecked(&cur_irq->irq_received)) -
39814 *sequence) <= (1 << 23)));
39815 }
39816 *sequence = cur_irq_sequence;
39817@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39818 }
39819
39820 for (i = 0; i < dev_priv->num_irqs; ++i) {
39821- atomic_set(&cur_irq->irq_received, 0);
39822+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39823 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39824 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39825 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39826@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39827 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39828 case VIA_IRQ_RELATIVE:
39829 irqwait->request.sequence +=
39830- atomic_read(&cur_irq->irq_received);
39831+ atomic_read_unchecked(&cur_irq->irq_received);
39832 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39833 case VIA_IRQ_ABSOLUTE:
39834 break;
39835diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39836index 13aeda7..4a952d1 100644
39837--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39838+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39839@@ -290,7 +290,7 @@ struct vmw_private {
39840 * Fencing and IRQs.
39841 */
39842
39843- atomic_t marker_seq;
39844+ atomic_unchecked_t marker_seq;
39845 wait_queue_head_t fence_queue;
39846 wait_queue_head_t fifo_queue;
39847 int fence_queue_waiters; /* Protected by hw_mutex */
39848diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39849index 3eb1486..0a47ee9 100644
39850--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39851+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39852@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39853 (unsigned int) min,
39854 (unsigned int) fifo->capabilities);
39855
39856- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39857+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39858 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39859 vmw_marker_queue_init(&fifo->marker_queue);
39860 return vmw_fifo_send_fence(dev_priv, &dummy);
39861@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39862 if (reserveable)
39863 iowrite32(bytes, fifo_mem +
39864 SVGA_FIFO_RESERVED);
39865- return fifo_mem + (next_cmd >> 2);
39866+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39867 } else {
39868 need_bounce = true;
39869 }
39870@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39871
39872 fm = vmw_fifo_reserve(dev_priv, bytes);
39873 if (unlikely(fm == NULL)) {
39874- *seqno = atomic_read(&dev_priv->marker_seq);
39875+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39876 ret = -ENOMEM;
39877 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39878 false, 3*HZ);
39879@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39880 }
39881
39882 do {
39883- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39884+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39885 } while (*seqno == 0);
39886
39887 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39888diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39889index c509d40..3b640c3 100644
39890--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39891+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39892@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39893 int ret;
39894
39895 num_clips = arg->num_clips;
39896- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39897+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39898
39899 if (unlikely(num_clips == 0))
39900 return 0;
39901@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39902 int ret;
39903
39904 num_clips = arg->num_clips;
39905- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39906+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39907
39908 if (unlikely(num_clips == 0))
39909 return 0;
39910diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39911index 4640adb..e1384ed 100644
39912--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39913+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39914@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39915 * emitted. Then the fence is stale and signaled.
39916 */
39917
39918- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39919+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39920 > VMW_FENCE_WRAP);
39921
39922 return ret;
39923@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39924
39925 if (fifo_idle)
39926 down_read(&fifo_state->rwsem);
39927- signal_seq = atomic_read(&dev_priv->marker_seq);
39928+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39929 ret = 0;
39930
39931 for (;;) {
39932diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39933index 8a8725c2..afed796 100644
39934--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39935+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39936@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39937 while (!vmw_lag_lt(queue, us)) {
39938 spin_lock(&queue->lock);
39939 if (list_empty(&queue->head))
39940- seqno = atomic_read(&dev_priv->marker_seq);
39941+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39942 else {
39943 marker = list_first_entry(&queue->head,
39944 struct vmw_marker, head);
39945diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39946index 8c04943..4370ed9 100644
39947--- a/drivers/gpu/host1x/drm/dc.c
39948+++ b/drivers/gpu/host1x/drm/dc.c
39949@@ -999,7 +999,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39950 }
39951
39952 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39953- dc->debugfs_files[i].data = dc;
39954+ *(void **)&dc->debugfs_files[i].data = dc;
39955
39956 err = drm_debugfs_create_files(dc->debugfs_files,
39957 ARRAY_SIZE(debugfs_files),
39958diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39959index 402f486..5340852 100644
39960--- a/drivers/hid/hid-core.c
39961+++ b/drivers/hid/hid-core.c
39962@@ -63,6 +63,8 @@ struct hid_report *hid_register_report(struct hid_device *device, unsigned type,
39963 struct hid_report_enum *report_enum = device->report_enum + type;
39964 struct hid_report *report;
39965
39966+ if (id >= HID_MAX_IDS)
39967+ return NULL;
39968 if (report_enum->report_id_hash[id])
39969 return report_enum->report_id_hash[id];
39970
39971@@ -404,8 +406,10 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
39972
39973 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
39974 parser->global.report_id = item_udata(item);
39975- if (parser->global.report_id == 0) {
39976- hid_err(parser->device, "report_id 0 is invalid\n");
39977+ if (parser->global.report_id == 0 ||
39978+ parser->global.report_id >= HID_MAX_IDS) {
39979+ hid_err(parser->device, "report_id %u is invalid\n",
39980+ parser->global.report_id);
39981 return -1;
39982 }
39983 return 0;
39984@@ -575,7 +579,7 @@ static void hid_close_report(struct hid_device *device)
39985 for (i = 0; i < HID_REPORT_TYPES; i++) {
39986 struct hid_report_enum *report_enum = device->report_enum + i;
39987
39988- for (j = 0; j < 256; j++) {
39989+ for (j = 0; j < HID_MAX_IDS; j++) {
39990 struct hid_report *report = report_enum->report_id_hash[j];
39991 if (report)
39992 hid_free_report(report);
39993@@ -755,6 +759,56 @@ int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
39994 }
39995 EXPORT_SYMBOL_GPL(hid_parse_report);
39996
39997+static const char * const hid_report_names[] = {
39998+ "HID_INPUT_REPORT",
39999+ "HID_OUTPUT_REPORT",
40000+ "HID_FEATURE_REPORT",
40001+};
40002+/**
40003+ * hid_validate_report - validate existing device report
40004+ *
40005+ * @device: hid device
40006+ * @type: which report type to examine
40007+ * @id: which report ID to examine (0 for first)
40008+ * @fields: expected number of fields
40009+ * @report_counts: expected number of values per field
40010+ *
40011+ * Validate the report details after parsing.
40012+ */
40013+struct hid_report *hid_validate_report(struct hid_device *hid,
40014+ unsigned int type, unsigned int id,
40015+ unsigned int fields,
40016+ unsigned int report_counts)
40017+{
40018+ struct hid_report *report;
40019+ unsigned int i;
40020+
40021+ if (type > HID_FEATURE_REPORT) {
40022+ hid_err(hid, "invalid HID report %u\n", type);
40023+ return NULL;
40024+ }
40025+
40026+ report = hid->report_enum[type].report_id_hash[id];
40027+ if (!report) {
40028+ hid_err(hid, "missing %s %u\n", hid_report_names[type], id);
40029+ return NULL;
40030+ }
40031+ if (report->maxfield < fields) {
40032+ hid_err(hid, "not enough fields in %s %u\n",
40033+ hid_report_names[type], id);
40034+ return NULL;
40035+ }
40036+ for (i = 0; i < fields; i++) {
40037+ if (report->field[i]->report_count < report_counts) {
40038+ hid_err(hid, "not enough values in %s %u fields\n",
40039+ hid_report_names[type], id);
40040+ return NULL;
40041+ }
40042+ }
40043+ return report;
40044+}
40045+EXPORT_SYMBOL_GPL(hid_validate_report);
40046+
40047 /**
40048 * hid_open_report - open a driver-specific device report
40049 *
40050@@ -1152,7 +1206,12 @@ EXPORT_SYMBOL_GPL(hid_output_report);
40051
40052 int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
40053 {
40054- unsigned size = field->report_size;
40055+ unsigned size;
40056+
40057+ if (!field)
40058+ return -1;
40059+
40060+ size = field->report_size;
40061
40062 hid_dump_input(field->report->device, field->usage + offset, value);
40063
40064@@ -2275,7 +2334,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
40065
40066 int hid_add_device(struct hid_device *hdev)
40067 {
40068- static atomic_t id = ATOMIC_INIT(0);
40069+ static atomic_unchecked_t id = ATOMIC_INIT(0);
40070 int ret;
40071
40072 if (WARN_ON(hdev->status & HID_STAT_ADDED))
40073@@ -2309,7 +2368,7 @@ int hid_add_device(struct hid_device *hdev)
40074 /* XXX hack, any other cleaner solution after the driver core
40075 * is converted to allow more than 20 bytes as the device name? */
40076 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
40077- hdev->vendor, hdev->product, atomic_inc_return(&id));
40078+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
40079
40080 hid_debug_register(hdev, dev_name(&hdev->dev));
40081 ret = device_add(&hdev->dev);
40082diff --git a/drivers/hid/hid-lenovo-tpkbd.c b/drivers/hid/hid-lenovo-tpkbd.c
40083index 07837f5..b697ada 100644
40084--- a/drivers/hid/hid-lenovo-tpkbd.c
40085+++ b/drivers/hid/hid-lenovo-tpkbd.c
40086@@ -341,6 +341,11 @@ static int tpkbd_probe_tp(struct hid_device *hdev)
40087 char *name_mute, *name_micmute;
40088 int ret;
40089
40090+ /* Validate required reports. */
40091+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, 4, 4, 1) ||
40092+ !hid_validate_report(hdev, HID_OUTPUT_REPORT, 3, 1, 2))
40093+ return -ENODEV;
40094+
40095 if (sysfs_create_group(&hdev->dev.kobj,
40096 &tpkbd_attr_group_pointer)) {
40097 hid_warn(hdev, "Could not create sysfs group\n");
40098diff --git a/drivers/hid/hid-lg2ff.c b/drivers/hid/hid-lg2ff.c
40099index b3cd150..9805197 100644
40100--- a/drivers/hid/hid-lg2ff.c
40101+++ b/drivers/hid/hid-lg2ff.c
40102@@ -64,26 +64,13 @@ int lg2ff_init(struct hid_device *hid)
40103 struct hid_report *report;
40104 struct hid_input *hidinput = list_entry(hid->inputs.next,
40105 struct hid_input, list);
40106- struct list_head *report_list =
40107- &hid->report_enum[HID_OUTPUT_REPORT].report_list;
40108 struct input_dev *dev = hidinput->input;
40109 int error;
40110
40111- if (list_empty(report_list)) {
40112- hid_err(hid, "no output report found\n");
40113+ /* Check that the report looks ok */
40114+ report = hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7);
40115+ if (!report)
40116 return -ENODEV;
40117- }
40118-
40119- report = list_entry(report_list->next, struct hid_report, list);
40120-
40121- if (report->maxfield < 1) {
40122- hid_err(hid, "output report is empty\n");
40123- return -ENODEV;
40124- }
40125- if (report->field[0]->report_count < 7) {
40126- hid_err(hid, "not enough values in the field\n");
40127- return -ENODEV;
40128- }
40129
40130 lg2ff = kmalloc(sizeof(struct lg2ff_device), GFP_KERNEL);
40131 if (!lg2ff)
40132diff --git a/drivers/hid/hid-lg3ff.c b/drivers/hid/hid-lg3ff.c
40133index e52f181..53ac79b 100644
40134--- a/drivers/hid/hid-lg3ff.c
40135+++ b/drivers/hid/hid-lg3ff.c
40136@@ -66,10 +66,11 @@ static int hid_lg3ff_play(struct input_dev *dev, void *data,
40137 int x, y;
40138
40139 /*
40140- * Maxusage should always be 63 (maximum fields)
40141- * likely a better way to ensure this data is clean
40142+ * Available values in the field should always be 63, but we only use up to
40143+ * 35. Instead, clear the entire area, however big it is.
40144 */
40145- memset(report->field[0]->value, 0, sizeof(__s32)*report->field[0]->maxusage);
40146+ memset(report->field[0]->value, 0,
40147+ sizeof(__s32) * report->field[0]->report_count);
40148
40149 switch (effect->type) {
40150 case FF_CONSTANT:
40151@@ -129,32 +130,14 @@ static const signed short ff3_joystick_ac[] = {
40152 int lg3ff_init(struct hid_device *hid)
40153 {
40154 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
40155- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
40156 struct input_dev *dev = hidinput->input;
40157- struct hid_report *report;
40158- struct hid_field *field;
40159 const signed short *ff_bits = ff3_joystick_ac;
40160 int error;
40161 int i;
40162
40163- /* Find the report to use */
40164- if (list_empty(report_list)) {
40165- hid_err(hid, "No output report found\n");
40166- return -1;
40167- }
40168-
40169 /* Check that the report looks ok */
40170- report = list_entry(report_list->next, struct hid_report, list);
40171- if (!report) {
40172- hid_err(hid, "NULL output report\n");
40173- return -1;
40174- }
40175-
40176- field = report->field[0];
40177- if (!field) {
40178- hid_err(hid, "NULL field\n");
40179- return -1;
40180- }
40181+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 35))
40182+ return -ENODEV;
40183
40184 /* Assume single fixed device G940 */
40185 for (i = 0; ff_bits[i] >= 0; i++)
40186diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
40187index 0ddae2a..8b89f0f 100644
40188--- a/drivers/hid/hid-lg4ff.c
40189+++ b/drivers/hid/hid-lg4ff.c
40190@@ -484,34 +484,16 @@ static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cde
40191 int lg4ff_init(struct hid_device *hid)
40192 {
40193 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
40194- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
40195 struct input_dev *dev = hidinput->input;
40196- struct hid_report *report;
40197- struct hid_field *field;
40198 struct lg4ff_device_entry *entry;
40199 struct lg_drv_data *drv_data;
40200 struct usb_device_descriptor *udesc;
40201 int error, i, j;
40202 __u16 bcdDevice, rev_maj, rev_min;
40203
40204- /* Find the report to use */
40205- if (list_empty(report_list)) {
40206- hid_err(hid, "No output report found\n");
40207- return -1;
40208- }
40209-
40210 /* Check that the report looks ok */
40211- report = list_entry(report_list->next, struct hid_report, list);
40212- if (!report) {
40213- hid_err(hid, "NULL output report\n");
40214+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7))
40215 return -1;
40216- }
40217-
40218- field = report->field[0];
40219- if (!field) {
40220- hid_err(hid, "NULL field\n");
40221- return -1;
40222- }
40223
40224 /* Check what wheel has been connected */
40225 for (i = 0; i < ARRAY_SIZE(lg4ff_devices); i++) {
40226diff --git a/drivers/hid/hid-lgff.c b/drivers/hid/hid-lgff.c
40227index d7ea8c8..a84fb40 100644
40228--- a/drivers/hid/hid-lgff.c
40229+++ b/drivers/hid/hid-lgff.c
40230@@ -128,27 +128,14 @@ static void hid_lgff_set_autocenter(struct input_dev *dev, u16 magnitude)
40231 int lgff_init(struct hid_device* hid)
40232 {
40233 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
40234- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
40235 struct input_dev *dev = hidinput->input;
40236- struct hid_report *report;
40237- struct hid_field *field;
40238 const signed short *ff_bits = ff_joystick;
40239 int error;
40240 int i;
40241
40242- /* Find the report to use */
40243- if (list_empty(report_list)) {
40244- hid_err(hid, "No output report found\n");
40245- return -1;
40246- }
40247-
40248 /* Check that the report looks ok */
40249- report = list_entry(report_list->next, struct hid_report, list);
40250- field = report->field[0];
40251- if (!field) {
40252- hid_err(hid, "NULL field\n");
40253- return -1;
40254- }
40255+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7))
40256+ return -ENODEV;
40257
40258 for (i = 0; i < ARRAY_SIZE(devices); i++) {
40259 if (dev->id.vendor == devices[i].idVendor &&
40260diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
40261index 5207591a..6c9197f 100644
40262--- a/drivers/hid/hid-logitech-dj.c
40263+++ b/drivers/hid/hid-logitech-dj.c
40264@@ -421,7 +421,7 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
40265 struct hid_report *report;
40266 struct hid_report_enum *output_report_enum;
40267 u8 *data = (u8 *)(&dj_report->device_index);
40268- int i;
40269+ unsigned int i, length;
40270
40271 output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT];
40272 report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];
40273@@ -431,7 +431,9 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
40274 return -ENODEV;
40275 }
40276
40277- for (i = 0; i < report->field[0]->report_count; i++)
40278+ length = min_t(size_t, sizeof(*dj_report) - 1,
40279+ report->field[0]->report_count);
40280+ for (i = 0; i < length; i++)
40281 report->field[0]->value[i] = data[i];
40282
40283 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
40284@@ -738,6 +740,12 @@ static int logi_dj_probe(struct hid_device *hdev,
40285 goto hid_parse_fail;
40286 }
40287
40288+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, REPORT_ID_DJ_SHORT,
40289+ 1, 3)) {
40290+ retval = -ENODEV;
40291+ goto hid_parse_fail;
40292+ }
40293+
40294 /* Starts the usb device and connects to upper interfaces hiddev and
40295 * hidraw */
40296 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
40297diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
40298index d39a5ce..4892dfc 100644
40299--- a/drivers/hid/hid-multitouch.c
40300+++ b/drivers/hid/hid-multitouch.c
40301@@ -330,9 +330,18 @@ static void mt_feature_mapping(struct hid_device *hdev,
40302 break;
40303 }
40304 }
40305+ /* Ignore if value index is out of bounds. */
40306+ if (td->inputmode_index < 0 ||
40307+ td->inputmode_index >= field->report_count) {
40308+ dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
40309+ td->inputmode = -1;
40310+ }
40311
40312 break;
40313 case HID_DG_CONTACTMAX:
40314+ /* Ignore if value count is out of bounds. */
40315+ if (field->report_count < 1)
40316+ break;
40317 td->maxcontact_report_id = field->report->id;
40318 td->maxcontacts = field->value[0];
40319 if (!td->maxcontacts &&
40320@@ -743,15 +752,21 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
40321 unsigned count;
40322 int r, n;
40323
40324+ if (report->maxfield == 0)
40325+ return;
40326+
40327 /*
40328 * Includes multi-packet support where subsequent
40329 * packets are sent with zero contactcount.
40330 */
40331- if (td->cc_index >= 0) {
40332- struct hid_field *field = report->field[td->cc_index];
40333- int value = field->value[td->cc_value_index];
40334- if (value)
40335- td->num_expected = value;
40336+ if (td->cc_index >= 0 && td->cc_index < report->maxfield) {
40337+ field = report->field[td->cc_index];
40338+ if (td->cc_value_index >= 0 &&
40339+ td->cc_value_index < field->report_count) {
40340+ int value = field->value[td->cc_value_index];
40341+ if (value)
40342+ td->num_expected = value;
40343+ }
40344 }
40345
40346 for (r = 0; r < report->maxfield; r++) {
40347diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
40348index ef95102..5482156 100644
40349--- a/drivers/hid/hid-ntrig.c
40350+++ b/drivers/hid/hid-ntrig.c
40351@@ -115,7 +115,8 @@ static inline int ntrig_get_mode(struct hid_device *hdev)
40352 struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT].
40353 report_id_hash[0x0d];
40354
40355- if (!report)
40356+ if (!report || report->maxfield < 1 ||
40357+ report->field[0]->report_count < 1)
40358 return -EINVAL;
40359
40360 hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
40361diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
40362index b48092d..72bba1e 100644
40363--- a/drivers/hid/hid-picolcd_core.c
40364+++ b/drivers/hid/hid-picolcd_core.c
40365@@ -290,7 +290,7 @@ static ssize_t picolcd_operation_mode_store(struct device *dev,
40366 buf += 10;
40367 cnt -= 10;
40368 }
40369- if (!report)
40370+ if (!report || report->maxfield < 1)
40371 return -EINVAL;
40372
40373 while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))
40374diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c
40375index d29112f..2dcd7d9 100644
40376--- a/drivers/hid/hid-pl.c
40377+++ b/drivers/hid/hid-pl.c
40378@@ -132,8 +132,14 @@ static int plff_init(struct hid_device *hid)
40379 strong = &report->field[0]->value[2];
40380 weak = &report->field[0]->value[3];
40381 debug("detected single-field device");
40382- } else if (report->maxfield >= 4 && report->field[0]->maxusage == 1 &&
40383- report->field[0]->usage[0].hid == (HID_UP_LED | 0x43)) {
40384+ } else if (report->field[0]->maxusage == 1 &&
40385+ report->field[0]->usage[0].hid ==
40386+ (HID_UP_LED | 0x43) &&
40387+ report->maxfield >= 4 &&
40388+ report->field[0]->report_count >= 1 &&
40389+ report->field[1]->report_count >= 1 &&
40390+ report->field[2]->report_count >= 1 &&
40391+ report->field[3]->report_count >= 1) {
40392 report->field[0]->value[0] = 0x00;
40393 report->field[1]->value[0] = 0x00;
40394 strong = &report->field[2]->value[0];
40395diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
40396index ca749810..aa34755 100644
40397--- a/drivers/hid/hid-sensor-hub.c
40398+++ b/drivers/hid/hid-sensor-hub.c
40399@@ -221,7 +221,8 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
40400
40401 mutex_lock(&data->mutex);
40402 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
40403- if (!report || (field_index >= report->maxfield)) {
40404+ if (!report || (field_index >= report->maxfield) ||
40405+ report->field[field_index]->report_count < 1) {
40406 ret = -EINVAL;
40407 goto done_proc;
40408 }
40409diff --git a/drivers/hid/hid-steelseries.c b/drivers/hid/hid-steelseries.c
40410index d164911..ef42e86 100644
40411--- a/drivers/hid/hid-steelseries.c
40412+++ b/drivers/hid/hid-steelseries.c
40413@@ -249,6 +249,11 @@ static int steelseries_srws1_probe(struct hid_device *hdev,
40414 goto err_free;
40415 }
40416
40417+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, 0, 1, 16)) {
40418+ ret = -ENODEV;
40419+ goto err_free;
40420+ }
40421+
40422 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
40423 if (ret) {
40424 hid_err(hdev, "hw start failed\n");
40425diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
40426index 90124ff..3761764 100644
40427--- a/drivers/hid/hid-wiimote-debug.c
40428+++ b/drivers/hid/hid-wiimote-debug.c
40429@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
40430 else if (size == 0)
40431 return -EIO;
40432
40433- if (copy_to_user(u, buf, size))
40434+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
40435 return -EFAULT;
40436
40437 *off += size;
40438diff --git a/drivers/hid/hid-zpff.c b/drivers/hid/hid-zpff.c
40439index 6ec28a3..b124991 100644
40440--- a/drivers/hid/hid-zpff.c
40441+++ b/drivers/hid/hid-zpff.c
40442@@ -68,22 +68,12 @@ static int zpff_init(struct hid_device *hid)
40443 struct hid_report *report;
40444 struct hid_input *hidinput = list_entry(hid->inputs.next,
40445 struct hid_input, list);
40446- struct list_head *report_list =
40447- &hid->report_enum[HID_OUTPUT_REPORT].report_list;
40448 struct input_dev *dev = hidinput->input;
40449 int error;
40450
40451- if (list_empty(report_list)) {
40452- hid_err(hid, "no output report found\n");
40453+ report = hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 4, 1);
40454+ if (!report)
40455 return -ENODEV;
40456- }
40457-
40458- report = list_entry(report_list->next, struct hid_report, list);
40459-
40460- if (report->maxfield < 4) {
40461- hid_err(hid, "not enough fields in report\n");
40462- return -ENODEV;
40463- }
40464
40465 zpff = kzalloc(sizeof(struct zpff_device), GFP_KERNEL);
40466 if (!zpff)
40467diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
40468index fc307e0..2b255e8 100644
40469--- a/drivers/hid/uhid.c
40470+++ b/drivers/hid/uhid.c
40471@@ -47,7 +47,7 @@ struct uhid_device {
40472 struct mutex report_lock;
40473 wait_queue_head_t report_wait;
40474 atomic_t report_done;
40475- atomic_t report_id;
40476+ atomic_unchecked_t report_id;
40477 struct uhid_event report_buf;
40478 };
40479
40480@@ -187,7 +187,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
40481
40482 spin_lock_irqsave(&uhid->qlock, flags);
40483 ev->type = UHID_FEATURE;
40484- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
40485+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
40486 ev->u.feature.rnum = rnum;
40487 ev->u.feature.rtype = report_type;
40488
40489@@ -471,7 +471,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
40490 spin_lock_irqsave(&uhid->qlock, flags);
40491
40492 /* id for old report; drop it silently */
40493- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
40494+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
40495 goto unlock;
40496 if (atomic_read(&uhid->report_done))
40497 goto unlock;
40498diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
40499index 0b122f8..b1d8160 100644
40500--- a/drivers/hv/channel.c
40501+++ b/drivers/hv/channel.c
40502@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
40503 int ret = 0;
40504 int t;
40505
40506- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
40507- atomic_inc(&vmbus_connection.next_gpadl_handle);
40508+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
40509+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
40510
40511 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
40512 if (ret)
40513diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
40514index ae49237..380d4c9 100644
40515--- a/drivers/hv/hv.c
40516+++ b/drivers/hv/hv.c
40517@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
40518 u64 output_address = (output) ? virt_to_phys(output) : 0;
40519 u32 output_address_hi = output_address >> 32;
40520 u32 output_address_lo = output_address & 0xFFFFFFFF;
40521- void *hypercall_page = hv_context.hypercall_page;
40522+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
40523
40524 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
40525 "=a"(hv_status_lo) : "d" (control_hi),
40526diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
40527index deb5c25..ed2d4fd 100644
40528--- a/drivers/hv/hv_balloon.c
40529+++ b/drivers/hv/hv_balloon.c
40530@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
40531
40532 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
40533 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
40534-static atomic_t trans_id = ATOMIC_INIT(0);
40535+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
40536
40537 static int dm_ring_size = (5 * PAGE_SIZE);
40538
40539@@ -825,7 +825,7 @@ static void hot_add_req(struct work_struct *dummy)
40540 memset(&resp, 0, sizeof(struct dm_hot_add_response));
40541 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE;
40542 resp.hdr.size = sizeof(struct dm_hot_add_response);
40543- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40544+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40545
40546 #ifdef CONFIG_MEMORY_HOTPLUG
40547 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
40548@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
40549 memset(&status, 0, sizeof(struct dm_status));
40550 status.hdr.type = DM_STATUS_REPORT;
40551 status.hdr.size = sizeof(struct dm_status);
40552- status.hdr.trans_id = atomic_inc_return(&trans_id);
40553+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40554
40555 /*
40556 * The host expects the guest to report free memory.
40557@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
40558 * send the status. This can happen if we were interrupted
40559 * after we picked our transaction ID.
40560 */
40561- if (status.hdr.trans_id != atomic_read(&trans_id))
40562+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
40563 return;
40564
40565 vmbus_sendpacket(dm->dev->channel, &status,
40566@@ -1081,7 +1081,7 @@ static void balloon_up(struct work_struct *dummy)
40567 bl_resp = (struct dm_balloon_response *)send_buffer;
40568 memset(send_buffer, 0, PAGE_SIZE);
40569 bl_resp->hdr.type = DM_BALLOON_RESPONSE;
40570- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
40571+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40572 bl_resp->hdr.size = sizeof(struct dm_balloon_response);
40573 bl_resp->more_pages = 1;
40574
40575@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
40576
40577 memset(&resp, 0, sizeof(struct dm_unballoon_response));
40578 resp.hdr.type = DM_UNBALLOON_RESPONSE;
40579- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40580+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40581 resp.hdr.size = sizeof(struct dm_unballoon_response);
40582
40583 vmbus_sendpacket(dm_device.dev->channel, &resp,
40584@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
40585 memset(&version_req, 0, sizeof(struct dm_version_request));
40586 version_req.hdr.type = DM_VERSION_REQUEST;
40587 version_req.hdr.size = sizeof(struct dm_version_request);
40588- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40589+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40590 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
40591 version_req.is_last_attempt = 1;
40592
40593@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
40594 memset(&version_req, 0, sizeof(struct dm_version_request));
40595 version_req.hdr.type = DM_VERSION_REQUEST;
40596 version_req.hdr.size = sizeof(struct dm_version_request);
40597- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40598+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40599 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
40600 version_req.is_last_attempt = 0;
40601
40602@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
40603 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
40604 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
40605 cap_msg.hdr.size = sizeof(struct dm_capabilities);
40606- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
40607+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40608
40609 cap_msg.caps.cap_bits.balloon = 1;
40610 cap_msg.caps.cap_bits.hot_add = 1;
40611diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
40612index 12f2f9e..679603c 100644
40613--- a/drivers/hv/hyperv_vmbus.h
40614+++ b/drivers/hv/hyperv_vmbus.h
40615@@ -591,7 +591,7 @@ enum vmbus_connect_state {
40616 struct vmbus_connection {
40617 enum vmbus_connect_state conn_state;
40618
40619- atomic_t next_gpadl_handle;
40620+ atomic_unchecked_t next_gpadl_handle;
40621
40622 /*
40623 * Represents channel interrupts. Each bit position represents a
40624diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
40625index 4004e54..c2de226 100644
40626--- a/drivers/hv/vmbus_drv.c
40627+++ b/drivers/hv/vmbus_drv.c
40628@@ -668,10 +668,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
40629 {
40630 int ret = 0;
40631
40632- static atomic_t device_num = ATOMIC_INIT(0);
40633+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
40634
40635 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
40636- atomic_inc_return(&device_num));
40637+ atomic_inc_return_unchecked(&device_num));
40638
40639 child_device_obj->device.bus = &hv_bus;
40640 child_device_obj->device.parent = &hv_acpi_dev->dev;
40641diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40642index 6351aba..dc4aaf4 100644
40643--- a/drivers/hwmon/acpi_power_meter.c
40644+++ b/drivers/hwmon/acpi_power_meter.c
40645@@ -117,7 +117,7 @@ struct sensor_template {
40646 struct device_attribute *devattr,
40647 const char *buf, size_t count);
40648 int index;
40649-};
40650+} __do_const;
40651
40652 /* Averaging interval */
40653 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40654@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40655 struct sensor_template *attrs)
40656 {
40657 struct device *dev = &resource->acpi_dev->dev;
40658- struct sensor_device_attribute *sensors =
40659+ sensor_device_attribute_no_const *sensors =
40660 &resource->sensors[resource->num_sensors];
40661 int res = 0;
40662
40663diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
40664index 62c2e32..8f2859a 100644
40665--- a/drivers/hwmon/applesmc.c
40666+++ b/drivers/hwmon/applesmc.c
40667@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
40668 {
40669 struct applesmc_node_group *grp;
40670 struct applesmc_dev_attr *node;
40671- struct attribute *attr;
40672+ attribute_no_const *attr;
40673 int ret, i;
40674
40675 for (grp = groups; grp->format; grp++) {
40676diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
40677index b25c643..a13460d 100644
40678--- a/drivers/hwmon/asus_atk0110.c
40679+++ b/drivers/hwmon/asus_atk0110.c
40680@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
40681 struct atk_sensor_data {
40682 struct list_head list;
40683 struct atk_data *data;
40684- struct device_attribute label_attr;
40685- struct device_attribute input_attr;
40686- struct device_attribute limit1_attr;
40687- struct device_attribute limit2_attr;
40688+ device_attribute_no_const label_attr;
40689+ device_attribute_no_const input_attr;
40690+ device_attribute_no_const limit1_attr;
40691+ device_attribute_no_const limit2_attr;
40692 char label_attr_name[ATTR_NAME_SIZE];
40693 char input_attr_name[ATTR_NAME_SIZE];
40694 char limit1_attr_name[ATTR_NAME_SIZE];
40695@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
40696 static struct device_attribute atk_name_attr =
40697 __ATTR(name, 0444, atk_name_show, NULL);
40698
40699-static void atk_init_attribute(struct device_attribute *attr, char *name,
40700+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
40701 sysfs_show_func show)
40702 {
40703 sysfs_attr_init(&attr->attr);
40704diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
40705index 658ce3a..0d0c2f3 100644
40706--- a/drivers/hwmon/coretemp.c
40707+++ b/drivers/hwmon/coretemp.c
40708@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
40709 return NOTIFY_OK;
40710 }
40711
40712-static struct notifier_block coretemp_cpu_notifier __refdata = {
40713+static struct notifier_block coretemp_cpu_notifier = {
40714 .notifier_call = coretemp_cpu_callback,
40715 };
40716
40717diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
40718index 1429f6e..ee03d59 100644
40719--- a/drivers/hwmon/ibmaem.c
40720+++ b/drivers/hwmon/ibmaem.c
40721@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
40722 struct aem_rw_sensor_template *rw)
40723 {
40724 struct device *dev = &data->pdev->dev;
40725- struct sensor_device_attribute *sensors = data->sensors;
40726+ sensor_device_attribute_no_const *sensors = data->sensors;
40727 int err;
40728
40729 /* Set up read-only sensors */
40730diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
40731index 52b77af..aed1ddf 100644
40732--- a/drivers/hwmon/iio_hwmon.c
40733+++ b/drivers/hwmon/iio_hwmon.c
40734@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
40735 {
40736 struct device *dev = &pdev->dev;
40737 struct iio_hwmon_state *st;
40738- struct sensor_device_attribute *a;
40739+ sensor_device_attribute_no_const *a;
40740 int ret, i;
40741 int in_i = 1, temp_i = 1, curr_i = 1;
40742 enum iio_chan_type type;
40743diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
40744index 9add6092..ee7ba3f 100644
40745--- a/drivers/hwmon/pmbus/pmbus_core.c
40746+++ b/drivers/hwmon/pmbus/pmbus_core.c
40747@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
40748 return 0;
40749 }
40750
40751-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40752+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
40753 const char *name,
40754 umode_t mode,
40755 ssize_t (*show)(struct device *dev,
40756@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40757 dev_attr->store = store;
40758 }
40759
40760-static void pmbus_attr_init(struct sensor_device_attribute *a,
40761+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
40762 const char *name,
40763 umode_t mode,
40764 ssize_t (*show)(struct device *dev,
40765@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
40766 u16 reg, u8 mask)
40767 {
40768 struct pmbus_boolean *boolean;
40769- struct sensor_device_attribute *a;
40770+ sensor_device_attribute_no_const *a;
40771
40772 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
40773 if (!boolean)
40774@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
40775 bool update, bool readonly)
40776 {
40777 struct pmbus_sensor *sensor;
40778- struct device_attribute *a;
40779+ device_attribute_no_const *a;
40780
40781 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
40782 if (!sensor)
40783@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
40784 const char *lstring, int index)
40785 {
40786 struct pmbus_label *label;
40787- struct device_attribute *a;
40788+ device_attribute_no_const *a;
40789
40790 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
40791 if (!label)
40792diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
40793index 2507f90..1645765 100644
40794--- a/drivers/hwmon/sht15.c
40795+++ b/drivers/hwmon/sht15.c
40796@@ -169,7 +169,7 @@ struct sht15_data {
40797 int supply_uv;
40798 bool supply_uv_valid;
40799 struct work_struct update_supply_work;
40800- atomic_t interrupt_handled;
40801+ atomic_unchecked_t interrupt_handled;
40802 };
40803
40804 /**
40805@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
40806 ret = gpio_direction_input(data->pdata->gpio_data);
40807 if (ret)
40808 return ret;
40809- atomic_set(&data->interrupt_handled, 0);
40810+ atomic_set_unchecked(&data->interrupt_handled, 0);
40811
40812 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40813 if (gpio_get_value(data->pdata->gpio_data) == 0) {
40814 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
40815 /* Only relevant if the interrupt hasn't occurred. */
40816- if (!atomic_read(&data->interrupt_handled))
40817+ if (!atomic_read_unchecked(&data->interrupt_handled))
40818 schedule_work(&data->read_work);
40819 }
40820 ret = wait_event_timeout(data->wait_queue,
40821@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
40822
40823 /* First disable the interrupt */
40824 disable_irq_nosync(irq);
40825- atomic_inc(&data->interrupt_handled);
40826+ atomic_inc_unchecked(&data->interrupt_handled);
40827 /* Then schedule a reading work struct */
40828 if (data->state != SHT15_READING_NOTHING)
40829 schedule_work(&data->read_work);
40830@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
40831 * If not, then start the interrupt again - care here as could
40832 * have gone low in meantime so verify it hasn't!
40833 */
40834- atomic_set(&data->interrupt_handled, 0);
40835+ atomic_set_unchecked(&data->interrupt_handled, 0);
40836 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40837 /* If still not occurred or another handler was scheduled */
40838 if (gpio_get_value(data->pdata->gpio_data)
40839- || atomic_read(&data->interrupt_handled))
40840+ || atomic_read_unchecked(&data->interrupt_handled))
40841 return;
40842 }
40843
40844diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
40845index 76f157b..9c0db1b 100644
40846--- a/drivers/hwmon/via-cputemp.c
40847+++ b/drivers/hwmon/via-cputemp.c
40848@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
40849 return NOTIFY_OK;
40850 }
40851
40852-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
40853+static struct notifier_block via_cputemp_cpu_notifier = {
40854 .notifier_call = via_cputemp_cpu_callback,
40855 };
40856
40857diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
40858index 07f01ac..d79ad3d 100644
40859--- a/drivers/i2c/busses/i2c-amd756-s4882.c
40860+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
40861@@ -43,7 +43,7 @@
40862 extern struct i2c_adapter amd756_smbus;
40863
40864 static struct i2c_adapter *s4882_adapter;
40865-static struct i2c_algorithm *s4882_algo;
40866+static i2c_algorithm_no_const *s4882_algo;
40867
40868 /* Wrapper access functions for multiplexed SMBus */
40869 static DEFINE_MUTEX(amd756_lock);
40870diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
40871index 2ca268d..c6acbdf 100644
40872--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
40873+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
40874@@ -41,7 +41,7 @@
40875 extern struct i2c_adapter *nforce2_smbus;
40876
40877 static struct i2c_adapter *s4985_adapter;
40878-static struct i2c_algorithm *s4985_algo;
40879+static i2c_algorithm_no_const *s4985_algo;
40880
40881 /* Wrapper access functions for multiplexed SMBus */
40882 static DEFINE_MUTEX(nforce2_lock);
40883diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
40884index c3ccdea..5b3dc1a 100644
40885--- a/drivers/i2c/i2c-dev.c
40886+++ b/drivers/i2c/i2c-dev.c
40887@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
40888 break;
40889 }
40890
40891- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
40892+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
40893 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
40894 if (IS_ERR(rdwr_pa[i].buf)) {
40895 res = PTR_ERR(rdwr_pa[i].buf);
40896diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40897index 2ff6204..218c16e 100644
40898--- a/drivers/ide/ide-cd.c
40899+++ b/drivers/ide/ide-cd.c
40900@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40901 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40902 if ((unsigned long)buf & alignment
40903 || blk_rq_bytes(rq) & q->dma_pad_mask
40904- || object_is_on_stack(buf))
40905+ || object_starts_on_stack(buf))
40906 drive->dma = 0;
40907 }
40908 }
40909diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40910index e145931..08bfc59 100644
40911--- a/drivers/iio/industrialio-core.c
40912+++ b/drivers/iio/industrialio-core.c
40913@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40914 }
40915
40916 static
40917-int __iio_device_attr_init(struct device_attribute *dev_attr,
40918+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40919 const char *postfix,
40920 struct iio_chan_spec const *chan,
40921 ssize_t (*readfunc)(struct device *dev,
40922diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40923index 784b97c..c9ceadf 100644
40924--- a/drivers/infiniband/core/cm.c
40925+++ b/drivers/infiniband/core/cm.c
40926@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40927
40928 struct cm_counter_group {
40929 struct kobject obj;
40930- atomic_long_t counter[CM_ATTR_COUNT];
40931+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40932 };
40933
40934 struct cm_counter_attribute {
40935@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40936 struct ib_mad_send_buf *msg = NULL;
40937 int ret;
40938
40939- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40940+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40941 counter[CM_REQ_COUNTER]);
40942
40943 /* Quick state check to discard duplicate REQs. */
40944@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40945 if (!cm_id_priv)
40946 return;
40947
40948- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40949+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40950 counter[CM_REP_COUNTER]);
40951 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40952 if (ret)
40953@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40954 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40955 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40956 spin_unlock_irq(&cm_id_priv->lock);
40957- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40958+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40959 counter[CM_RTU_COUNTER]);
40960 goto out;
40961 }
40962@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40963 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40964 dreq_msg->local_comm_id);
40965 if (!cm_id_priv) {
40966- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40967+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40968 counter[CM_DREQ_COUNTER]);
40969 cm_issue_drep(work->port, work->mad_recv_wc);
40970 return -EINVAL;
40971@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40972 case IB_CM_MRA_REP_RCVD:
40973 break;
40974 case IB_CM_TIMEWAIT:
40975- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40976+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40977 counter[CM_DREQ_COUNTER]);
40978 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40979 goto unlock;
40980@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40981 cm_free_msg(msg);
40982 goto deref;
40983 case IB_CM_DREQ_RCVD:
40984- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40985+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40986 counter[CM_DREQ_COUNTER]);
40987 goto unlock;
40988 default:
40989@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40990 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40991 cm_id_priv->msg, timeout)) {
40992 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40993- atomic_long_inc(&work->port->
40994+ atomic_long_inc_unchecked(&work->port->
40995 counter_group[CM_RECV_DUPLICATES].
40996 counter[CM_MRA_COUNTER]);
40997 goto out;
40998@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40999 break;
41000 case IB_CM_MRA_REQ_RCVD:
41001 case IB_CM_MRA_REP_RCVD:
41002- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41003+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41004 counter[CM_MRA_COUNTER]);
41005 /* fall through */
41006 default:
41007@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
41008 case IB_CM_LAP_IDLE:
41009 break;
41010 case IB_CM_MRA_LAP_SENT:
41011- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41012+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41013 counter[CM_LAP_COUNTER]);
41014 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41015 goto unlock;
41016@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
41017 cm_free_msg(msg);
41018 goto deref;
41019 case IB_CM_LAP_RCVD:
41020- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41021+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41022 counter[CM_LAP_COUNTER]);
41023 goto unlock;
41024 default:
41025@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41026 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41027 if (cur_cm_id_priv) {
41028 spin_unlock_irq(&cm.lock);
41029- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41030+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41031 counter[CM_SIDR_REQ_COUNTER]);
41032 goto out; /* Duplicate message. */
41033 }
41034@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
41035 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
41036 msg->retries = 1;
41037
41038- atomic_long_add(1 + msg->retries,
41039+ atomic_long_add_unchecked(1 + msg->retries,
41040 &port->counter_group[CM_XMIT].counter[attr_index]);
41041 if (msg->retries)
41042- atomic_long_add(msg->retries,
41043+ atomic_long_add_unchecked(msg->retries,
41044 &port->counter_group[CM_XMIT_RETRIES].
41045 counter[attr_index]);
41046
41047@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
41048 }
41049
41050 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
41051- atomic_long_inc(&port->counter_group[CM_RECV].
41052+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
41053 counter[attr_id - CM_ATTR_ID_OFFSET]);
41054
41055 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
41056@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
41057 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
41058
41059 return sprintf(buf, "%ld\n",
41060- atomic_long_read(&group->counter[cm_attr->index]));
41061+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
41062 }
41063
41064 static const struct sysfs_ops cm_counter_ops = {
41065diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
41066index 9f5ad7c..588cd84 100644
41067--- a/drivers/infiniband/core/fmr_pool.c
41068+++ b/drivers/infiniband/core/fmr_pool.c
41069@@ -98,8 +98,8 @@ struct ib_fmr_pool {
41070
41071 struct task_struct *thread;
41072
41073- atomic_t req_ser;
41074- atomic_t flush_ser;
41075+ atomic_unchecked_t req_ser;
41076+ atomic_unchecked_t flush_ser;
41077
41078 wait_queue_head_t force_wait;
41079 };
41080@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41081 struct ib_fmr_pool *pool = pool_ptr;
41082
41083 do {
41084- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
41085+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
41086 ib_fmr_batch_release(pool);
41087
41088- atomic_inc(&pool->flush_ser);
41089+ atomic_inc_unchecked(&pool->flush_ser);
41090 wake_up_interruptible(&pool->force_wait);
41091
41092 if (pool->flush_function)
41093@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41094 }
41095
41096 set_current_state(TASK_INTERRUPTIBLE);
41097- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
41098+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
41099 !kthread_should_stop())
41100 schedule();
41101 __set_current_state(TASK_RUNNING);
41102@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
41103 pool->dirty_watermark = params->dirty_watermark;
41104 pool->dirty_len = 0;
41105 spin_lock_init(&pool->pool_lock);
41106- atomic_set(&pool->req_ser, 0);
41107- atomic_set(&pool->flush_ser, 0);
41108+ atomic_set_unchecked(&pool->req_ser, 0);
41109+ atomic_set_unchecked(&pool->flush_ser, 0);
41110 init_waitqueue_head(&pool->force_wait);
41111
41112 pool->thread = kthread_run(ib_fmr_cleanup_thread,
41113@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
41114 }
41115 spin_unlock_irq(&pool->pool_lock);
41116
41117- serial = atomic_inc_return(&pool->req_ser);
41118+ serial = atomic_inc_return_unchecked(&pool->req_ser);
41119 wake_up_process(pool->thread);
41120
41121 if (wait_event_interruptible(pool->force_wait,
41122- atomic_read(&pool->flush_ser) - serial >= 0))
41123+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
41124 return -EINTR;
41125
41126 return 0;
41127@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
41128 } else {
41129 list_add_tail(&fmr->list, &pool->dirty_list);
41130 if (++pool->dirty_len >= pool->dirty_watermark) {
41131- atomic_inc(&pool->req_ser);
41132+ atomic_inc_unchecked(&pool->req_ser);
41133 wake_up_process(pool->thread);
41134 }
41135 }
41136diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
41137index 4cb8eb2..146bf60 100644
41138--- a/drivers/infiniband/hw/cxgb4/mem.c
41139+++ b/drivers/infiniband/hw/cxgb4/mem.c
41140@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41141 int err;
41142 struct fw_ri_tpte tpt;
41143 u32 stag_idx;
41144- static atomic_t key;
41145+ static atomic_unchecked_t key;
41146
41147 if (c4iw_fatal_error(rdev))
41148 return -EIO;
41149@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41150 if (rdev->stats.stag.cur > rdev->stats.stag.max)
41151 rdev->stats.stag.max = rdev->stats.stag.cur;
41152 mutex_unlock(&rdev->stats.lock);
41153- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
41154+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
41155 }
41156 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
41157 __func__, stag_state, type, pdid, stag_idx);
41158diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
41159index 79b3dbc..96e5fcc 100644
41160--- a/drivers/infiniband/hw/ipath/ipath_rc.c
41161+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
41162@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41163 struct ib_atomic_eth *ateth;
41164 struct ipath_ack_entry *e;
41165 u64 vaddr;
41166- atomic64_t *maddr;
41167+ atomic64_unchecked_t *maddr;
41168 u64 sdata;
41169 u32 rkey;
41170 u8 next;
41171@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41172 IB_ACCESS_REMOTE_ATOMIC)))
41173 goto nack_acc_unlck;
41174 /* Perform atomic OP and save result. */
41175- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41176+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41177 sdata = be64_to_cpu(ateth->swap_data);
41178 e = &qp->s_ack_queue[qp->r_head_ack_queue];
41179 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
41180- (u64) atomic64_add_return(sdata, maddr) - sdata :
41181+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41182 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41183 be64_to_cpu(ateth->compare_data),
41184 sdata);
41185diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
41186index 1f95bba..9530f87 100644
41187--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
41188+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
41189@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
41190 unsigned long flags;
41191 struct ib_wc wc;
41192 u64 sdata;
41193- atomic64_t *maddr;
41194+ atomic64_unchecked_t *maddr;
41195 enum ib_wc_status send_status;
41196
41197 /*
41198@@ -382,11 +382,11 @@ again:
41199 IB_ACCESS_REMOTE_ATOMIC)))
41200 goto acc_err;
41201 /* Perform atomic OP and save result. */
41202- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41203+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41204 sdata = wqe->wr.wr.atomic.compare_add;
41205 *(u64 *) sqp->s_sge.sge.vaddr =
41206 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
41207- (u64) atomic64_add_return(sdata, maddr) - sdata :
41208+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41209 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41210 sdata, wqe->wr.wr.atomic.swap);
41211 goto send_comp;
41212diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
41213index 4d599ce..697b17f 100644
41214--- a/drivers/infiniband/hw/mlx4/mad.c
41215+++ b/drivers/infiniband/hw/mlx4/mad.c
41216@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
41217
41218 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
41219 {
41220- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
41221+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
41222 cpu_to_be64(0xff00000000000000LL);
41223 }
41224
41225diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41226index f61ec26..ebf72cf 100644
41227--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
41228+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41229@@ -398,7 +398,7 @@ struct mlx4_ib_demux_ctx {
41230 struct list_head mcg_mgid0_list;
41231 struct workqueue_struct *mcg_wq;
41232 struct mlx4_ib_demux_pv_ctx **tun;
41233- atomic_t tid;
41234+ atomic_unchecked_t tid;
41235 int flushing; /* flushing the work queue */
41236 };
41237
41238diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
41239index 9d3e5c1..d9afe4a 100644
41240--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
41241+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
41242@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
41243 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
41244 }
41245
41246-int mthca_QUERY_FW(struct mthca_dev *dev)
41247+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
41248 {
41249 struct mthca_mailbox *mailbox;
41250 u32 *outbox;
41251diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
41252index ed9a989..e0c5871 100644
41253--- a/drivers/infiniband/hw/mthca/mthca_mr.c
41254+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
41255@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
41256 return key;
41257 }
41258
41259-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41260+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41261 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
41262 {
41263 struct mthca_mailbox *mailbox;
41264diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
41265index 4291410..d2ab1fb 100644
41266--- a/drivers/infiniband/hw/nes/nes.c
41267+++ b/drivers/infiniband/hw/nes/nes.c
41268@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
41269 LIST_HEAD(nes_adapter_list);
41270 static LIST_HEAD(nes_dev_list);
41271
41272-atomic_t qps_destroyed;
41273+atomic_unchecked_t qps_destroyed;
41274
41275 static unsigned int ee_flsh_adapter;
41276 static unsigned int sysfs_nonidx_addr;
41277@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
41278 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
41279 struct nes_adapter *nesadapter = nesdev->nesadapter;
41280
41281- atomic_inc(&qps_destroyed);
41282+ atomic_inc_unchecked(&qps_destroyed);
41283
41284 /* Free the control structures */
41285
41286diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
41287index 33cc589..3bd6538 100644
41288--- a/drivers/infiniband/hw/nes/nes.h
41289+++ b/drivers/infiniband/hw/nes/nes.h
41290@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
41291 extern unsigned int wqm_quanta;
41292 extern struct list_head nes_adapter_list;
41293
41294-extern atomic_t cm_connects;
41295-extern atomic_t cm_accepts;
41296-extern atomic_t cm_disconnects;
41297-extern atomic_t cm_closes;
41298-extern atomic_t cm_connecteds;
41299-extern atomic_t cm_connect_reqs;
41300-extern atomic_t cm_rejects;
41301-extern atomic_t mod_qp_timouts;
41302-extern atomic_t qps_created;
41303-extern atomic_t qps_destroyed;
41304-extern atomic_t sw_qps_destroyed;
41305+extern atomic_unchecked_t cm_connects;
41306+extern atomic_unchecked_t cm_accepts;
41307+extern atomic_unchecked_t cm_disconnects;
41308+extern atomic_unchecked_t cm_closes;
41309+extern atomic_unchecked_t cm_connecteds;
41310+extern atomic_unchecked_t cm_connect_reqs;
41311+extern atomic_unchecked_t cm_rejects;
41312+extern atomic_unchecked_t mod_qp_timouts;
41313+extern atomic_unchecked_t qps_created;
41314+extern atomic_unchecked_t qps_destroyed;
41315+extern atomic_unchecked_t sw_qps_destroyed;
41316 extern u32 mh_detected;
41317 extern u32 mh_pauses_sent;
41318 extern u32 cm_packets_sent;
41319@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
41320 extern u32 cm_packets_received;
41321 extern u32 cm_packets_dropped;
41322 extern u32 cm_packets_retrans;
41323-extern atomic_t cm_listens_created;
41324-extern atomic_t cm_listens_destroyed;
41325+extern atomic_unchecked_t cm_listens_created;
41326+extern atomic_unchecked_t cm_listens_destroyed;
41327 extern u32 cm_backlog_drops;
41328-extern atomic_t cm_loopbacks;
41329-extern atomic_t cm_nodes_created;
41330-extern atomic_t cm_nodes_destroyed;
41331-extern atomic_t cm_accel_dropped_pkts;
41332-extern atomic_t cm_resets_recvd;
41333-extern atomic_t pau_qps_created;
41334-extern atomic_t pau_qps_destroyed;
41335+extern atomic_unchecked_t cm_loopbacks;
41336+extern atomic_unchecked_t cm_nodes_created;
41337+extern atomic_unchecked_t cm_nodes_destroyed;
41338+extern atomic_unchecked_t cm_accel_dropped_pkts;
41339+extern atomic_unchecked_t cm_resets_recvd;
41340+extern atomic_unchecked_t pau_qps_created;
41341+extern atomic_unchecked_t pau_qps_destroyed;
41342
41343 extern u32 int_mod_timer_init;
41344 extern u32 int_mod_cq_depth_256;
41345diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
41346index 24b9f1a..00fd004 100644
41347--- a/drivers/infiniband/hw/nes/nes_cm.c
41348+++ b/drivers/infiniband/hw/nes/nes_cm.c
41349@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
41350 u32 cm_packets_retrans;
41351 u32 cm_packets_created;
41352 u32 cm_packets_received;
41353-atomic_t cm_listens_created;
41354-atomic_t cm_listens_destroyed;
41355+atomic_unchecked_t cm_listens_created;
41356+atomic_unchecked_t cm_listens_destroyed;
41357 u32 cm_backlog_drops;
41358-atomic_t cm_loopbacks;
41359-atomic_t cm_nodes_created;
41360-atomic_t cm_nodes_destroyed;
41361-atomic_t cm_accel_dropped_pkts;
41362-atomic_t cm_resets_recvd;
41363+atomic_unchecked_t cm_loopbacks;
41364+atomic_unchecked_t cm_nodes_created;
41365+atomic_unchecked_t cm_nodes_destroyed;
41366+atomic_unchecked_t cm_accel_dropped_pkts;
41367+atomic_unchecked_t cm_resets_recvd;
41368
41369 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
41370 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
41371@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
41372
41373 static struct nes_cm_core *g_cm_core;
41374
41375-atomic_t cm_connects;
41376-atomic_t cm_accepts;
41377-atomic_t cm_disconnects;
41378-atomic_t cm_closes;
41379-atomic_t cm_connecteds;
41380-atomic_t cm_connect_reqs;
41381-atomic_t cm_rejects;
41382+atomic_unchecked_t cm_connects;
41383+atomic_unchecked_t cm_accepts;
41384+atomic_unchecked_t cm_disconnects;
41385+atomic_unchecked_t cm_closes;
41386+atomic_unchecked_t cm_connecteds;
41387+atomic_unchecked_t cm_connect_reqs;
41388+atomic_unchecked_t cm_rejects;
41389
41390 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
41391 {
41392@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
41393 kfree(listener);
41394 listener = NULL;
41395 ret = 0;
41396- atomic_inc(&cm_listens_destroyed);
41397+ atomic_inc_unchecked(&cm_listens_destroyed);
41398 } else {
41399 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
41400 }
41401@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
41402 cm_node->rem_mac);
41403
41404 add_hte_node(cm_core, cm_node);
41405- atomic_inc(&cm_nodes_created);
41406+ atomic_inc_unchecked(&cm_nodes_created);
41407
41408 return cm_node;
41409 }
41410@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
41411 }
41412
41413 atomic_dec(&cm_core->node_cnt);
41414- atomic_inc(&cm_nodes_destroyed);
41415+ atomic_inc_unchecked(&cm_nodes_destroyed);
41416 nesqp = cm_node->nesqp;
41417 if (nesqp) {
41418 nesqp->cm_node = NULL;
41419@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
41420
41421 static void drop_packet(struct sk_buff *skb)
41422 {
41423- atomic_inc(&cm_accel_dropped_pkts);
41424+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
41425 dev_kfree_skb_any(skb);
41426 }
41427
41428@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
41429 {
41430
41431 int reset = 0; /* whether to send reset in case of err.. */
41432- atomic_inc(&cm_resets_recvd);
41433+ atomic_inc_unchecked(&cm_resets_recvd);
41434 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
41435 " refcnt=%d\n", cm_node, cm_node->state,
41436 atomic_read(&cm_node->ref_count));
41437@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
41438 rem_ref_cm_node(cm_node->cm_core, cm_node);
41439 return NULL;
41440 }
41441- atomic_inc(&cm_loopbacks);
41442+ atomic_inc_unchecked(&cm_loopbacks);
41443 loopbackremotenode->loopbackpartner = cm_node;
41444 loopbackremotenode->tcp_cntxt.rcv_wscale =
41445 NES_CM_DEFAULT_RCV_WND_SCALE;
41446@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
41447 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
41448 else {
41449 rem_ref_cm_node(cm_core, cm_node);
41450- atomic_inc(&cm_accel_dropped_pkts);
41451+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
41452 dev_kfree_skb_any(skb);
41453 }
41454 break;
41455@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41456
41457 if ((cm_id) && (cm_id->event_handler)) {
41458 if (issue_disconn) {
41459- atomic_inc(&cm_disconnects);
41460+ atomic_inc_unchecked(&cm_disconnects);
41461 cm_event.event = IW_CM_EVENT_DISCONNECT;
41462 cm_event.status = disconn_status;
41463 cm_event.local_addr = cm_id->local_addr;
41464@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41465 }
41466
41467 if (issue_close) {
41468- atomic_inc(&cm_closes);
41469+ atomic_inc_unchecked(&cm_closes);
41470 nes_disconnect(nesqp, 1);
41471
41472 cm_id->provider_data = nesqp;
41473@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41474
41475 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
41476 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
41477- atomic_inc(&cm_accepts);
41478+ atomic_inc_unchecked(&cm_accepts);
41479
41480 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
41481 netdev_refcnt_read(nesvnic->netdev));
41482@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
41483 struct nes_cm_core *cm_core;
41484 u8 *start_buff;
41485
41486- atomic_inc(&cm_rejects);
41487+ atomic_inc_unchecked(&cm_rejects);
41488 cm_node = (struct nes_cm_node *)cm_id->provider_data;
41489 loopback = cm_node->loopbackpartner;
41490 cm_core = cm_node->cm_core;
41491@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41492 ntohl(cm_id->local_addr.sin_addr.s_addr),
41493 ntohs(cm_id->local_addr.sin_port));
41494
41495- atomic_inc(&cm_connects);
41496+ atomic_inc_unchecked(&cm_connects);
41497 nesqp->active_conn = 1;
41498
41499 /* cache the cm_id in the qp */
41500@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
41501 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
41502 return err;
41503 }
41504- atomic_inc(&cm_listens_created);
41505+ atomic_inc_unchecked(&cm_listens_created);
41506 }
41507
41508 cm_id->add_ref(cm_id);
41509@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
41510
41511 if (nesqp->destroyed)
41512 return;
41513- atomic_inc(&cm_connecteds);
41514+ atomic_inc_unchecked(&cm_connecteds);
41515 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
41516 " local port 0x%04X. jiffies = %lu.\n",
41517 nesqp->hwqp.qp_id,
41518@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
41519
41520 cm_id->add_ref(cm_id);
41521 ret = cm_id->event_handler(cm_id, &cm_event);
41522- atomic_inc(&cm_closes);
41523+ atomic_inc_unchecked(&cm_closes);
41524 cm_event.event = IW_CM_EVENT_CLOSE;
41525 cm_event.status = 0;
41526 cm_event.provider_data = cm_id->provider_data;
41527@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
41528 return;
41529 cm_id = cm_node->cm_id;
41530
41531- atomic_inc(&cm_connect_reqs);
41532+ atomic_inc_unchecked(&cm_connect_reqs);
41533 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41534 cm_node, cm_id, jiffies);
41535
41536@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
41537 return;
41538 cm_id = cm_node->cm_id;
41539
41540- atomic_inc(&cm_connect_reqs);
41541+ atomic_inc_unchecked(&cm_connect_reqs);
41542 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41543 cm_node, cm_id, jiffies);
41544
41545diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
41546index 4166452..fc952c3 100644
41547--- a/drivers/infiniband/hw/nes/nes_mgt.c
41548+++ b/drivers/infiniband/hw/nes/nes_mgt.c
41549@@ -40,8 +40,8 @@
41550 #include "nes.h"
41551 #include "nes_mgt.h"
41552
41553-atomic_t pau_qps_created;
41554-atomic_t pau_qps_destroyed;
41555+atomic_unchecked_t pau_qps_created;
41556+atomic_unchecked_t pau_qps_destroyed;
41557
41558 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
41559 {
41560@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
41561 {
41562 struct sk_buff *skb;
41563 unsigned long flags;
41564- atomic_inc(&pau_qps_destroyed);
41565+ atomic_inc_unchecked(&pau_qps_destroyed);
41566
41567 /* Free packets that have not yet been forwarded */
41568 /* Lock is acquired by skb_dequeue when removing the skb */
41569@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
41570 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
41571 skb_queue_head_init(&nesqp->pau_list);
41572 spin_lock_init(&nesqp->pau_lock);
41573- atomic_inc(&pau_qps_created);
41574+ atomic_inc_unchecked(&pau_qps_created);
41575 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
41576 }
41577
41578diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
41579index 49eb511..a774366 100644
41580--- a/drivers/infiniband/hw/nes/nes_nic.c
41581+++ b/drivers/infiniband/hw/nes/nes_nic.c
41582@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
41583 target_stat_values[++index] = mh_detected;
41584 target_stat_values[++index] = mh_pauses_sent;
41585 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
41586- target_stat_values[++index] = atomic_read(&cm_connects);
41587- target_stat_values[++index] = atomic_read(&cm_accepts);
41588- target_stat_values[++index] = atomic_read(&cm_disconnects);
41589- target_stat_values[++index] = atomic_read(&cm_connecteds);
41590- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
41591- target_stat_values[++index] = atomic_read(&cm_rejects);
41592- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
41593- target_stat_values[++index] = atomic_read(&qps_created);
41594- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
41595- target_stat_values[++index] = atomic_read(&qps_destroyed);
41596- target_stat_values[++index] = atomic_read(&cm_closes);
41597+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
41598+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
41599+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
41600+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
41601+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
41602+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
41603+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
41604+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
41605+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
41606+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
41607+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
41608 target_stat_values[++index] = cm_packets_sent;
41609 target_stat_values[++index] = cm_packets_bounced;
41610 target_stat_values[++index] = cm_packets_created;
41611 target_stat_values[++index] = cm_packets_received;
41612 target_stat_values[++index] = cm_packets_dropped;
41613 target_stat_values[++index] = cm_packets_retrans;
41614- target_stat_values[++index] = atomic_read(&cm_listens_created);
41615- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
41616+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
41617+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
41618 target_stat_values[++index] = cm_backlog_drops;
41619- target_stat_values[++index] = atomic_read(&cm_loopbacks);
41620- target_stat_values[++index] = atomic_read(&cm_nodes_created);
41621- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
41622- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
41623- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
41624+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
41625+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
41626+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
41627+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
41628+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
41629 target_stat_values[++index] = nesadapter->free_4kpbl;
41630 target_stat_values[++index] = nesadapter->free_256pbl;
41631 target_stat_values[++index] = int_mod_timer_init;
41632 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
41633 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
41634 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
41635- target_stat_values[++index] = atomic_read(&pau_qps_created);
41636- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
41637+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
41638+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
41639 }
41640
41641 /**
41642diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
41643index 8f67fe2..8960859 100644
41644--- a/drivers/infiniband/hw/nes/nes_verbs.c
41645+++ b/drivers/infiniband/hw/nes/nes_verbs.c
41646@@ -46,9 +46,9 @@
41647
41648 #include <rdma/ib_umem.h>
41649
41650-atomic_t mod_qp_timouts;
41651-atomic_t qps_created;
41652-atomic_t sw_qps_destroyed;
41653+atomic_unchecked_t mod_qp_timouts;
41654+atomic_unchecked_t qps_created;
41655+atomic_unchecked_t sw_qps_destroyed;
41656
41657 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
41658
41659@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
41660 if (init_attr->create_flags)
41661 return ERR_PTR(-EINVAL);
41662
41663- atomic_inc(&qps_created);
41664+ atomic_inc_unchecked(&qps_created);
41665 switch (init_attr->qp_type) {
41666 case IB_QPT_RC:
41667 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
41668@@ -1465,7 +1465,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
41669 struct iw_cm_event cm_event;
41670 int ret = 0;
41671
41672- atomic_inc(&sw_qps_destroyed);
41673+ atomic_inc_unchecked(&sw_qps_destroyed);
41674 nesqp->destroyed = 1;
41675
41676 /* Blow away the connection if it exists. */
41677diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
41678index 4d11575..3e890e5 100644
41679--- a/drivers/infiniband/hw/qib/qib.h
41680+++ b/drivers/infiniband/hw/qib/qib.h
41681@@ -51,6 +51,7 @@
41682 #include <linux/completion.h>
41683 #include <linux/kref.h>
41684 #include <linux/sched.h>
41685+#include <linux/slab.h>
41686
41687 #include "qib_common.h"
41688 #include "qib_verbs.h"
41689diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
41690index da739d9..da1c7f4 100644
41691--- a/drivers/input/gameport/gameport.c
41692+++ b/drivers/input/gameport/gameport.c
41693@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
41694 */
41695 static void gameport_init_port(struct gameport *gameport)
41696 {
41697- static atomic_t gameport_no = ATOMIC_INIT(0);
41698+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
41699
41700 __module_get(THIS_MODULE);
41701
41702 mutex_init(&gameport->drv_mutex);
41703 device_initialize(&gameport->dev);
41704 dev_set_name(&gameport->dev, "gameport%lu",
41705- (unsigned long)atomic_inc_return(&gameport_no) - 1);
41706+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
41707 gameport->dev.bus = &gameport_bus;
41708 gameport->dev.release = gameport_release_port;
41709 if (gameport->parent)
41710diff --git a/drivers/input/input.c b/drivers/input/input.c
41711index c044699..174d71a 100644
41712--- a/drivers/input/input.c
41713+++ b/drivers/input/input.c
41714@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
41715 */
41716 int input_register_device(struct input_dev *dev)
41717 {
41718- static atomic_t input_no = ATOMIC_INIT(0);
41719+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
41720 struct input_devres *devres = NULL;
41721 struct input_handler *handler;
41722 unsigned int packet_size;
41723@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
41724 dev->setkeycode = input_default_setkeycode;
41725
41726 dev_set_name(&dev->dev, "input%ld",
41727- (unsigned long) atomic_inc_return(&input_no) - 1);
41728+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
41729
41730 error = device_add(&dev->dev);
41731 if (error)
41732diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
41733index 04c69af..5f92d00 100644
41734--- a/drivers/input/joystick/sidewinder.c
41735+++ b/drivers/input/joystick/sidewinder.c
41736@@ -30,6 +30,7 @@
41737 #include <linux/kernel.h>
41738 #include <linux/module.h>
41739 #include <linux/slab.h>
41740+#include <linux/sched.h>
41741 #include <linux/init.h>
41742 #include <linux/input.h>
41743 #include <linux/gameport.h>
41744diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
41745index fa061d4..4a6957c 100644
41746--- a/drivers/input/joystick/xpad.c
41747+++ b/drivers/input/joystick/xpad.c
41748@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
41749
41750 static int xpad_led_probe(struct usb_xpad *xpad)
41751 {
41752- static atomic_t led_seq = ATOMIC_INIT(0);
41753+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
41754 long led_no;
41755 struct xpad_led *led;
41756 struct led_classdev *led_cdev;
41757@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
41758 if (!led)
41759 return -ENOMEM;
41760
41761- led_no = (long)atomic_inc_return(&led_seq) - 1;
41762+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
41763
41764 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
41765 led->xpad = xpad;
41766diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
41767index e204f26..8459f15 100644
41768--- a/drivers/input/misc/ims-pcu.c
41769+++ b/drivers/input/misc/ims-pcu.c
41770@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
41771
41772 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41773 {
41774- static atomic_t device_no = ATOMIC_INIT(0);
41775+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
41776
41777 const struct ims_pcu_device_info *info;
41778 u8 device_id;
41779@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41780 }
41781
41782 /* Device appears to be operable, complete initialization */
41783- pcu->device_no = atomic_inc_return(&device_no) - 1;
41784+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
41785
41786 error = ims_pcu_setup_backlight(pcu);
41787 if (error)
41788diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
41789index 2f0b39d..7370f13 100644
41790--- a/drivers/input/mouse/psmouse.h
41791+++ b/drivers/input/mouse/psmouse.h
41792@@ -116,7 +116,7 @@ struct psmouse_attribute {
41793 ssize_t (*set)(struct psmouse *psmouse, void *data,
41794 const char *buf, size_t count);
41795 bool protect;
41796-};
41797+} __do_const;
41798 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
41799
41800 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
41801diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
41802index 4c842c3..590b0bf 100644
41803--- a/drivers/input/mousedev.c
41804+++ b/drivers/input/mousedev.c
41805@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
41806
41807 spin_unlock_irq(&client->packet_lock);
41808
41809- if (copy_to_user(buffer, data, count))
41810+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
41811 return -EFAULT;
41812
41813 return count;
41814diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
41815index 25fc597..558bf3b3 100644
41816--- a/drivers/input/serio/serio.c
41817+++ b/drivers/input/serio/serio.c
41818@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
41819 */
41820 static void serio_init_port(struct serio *serio)
41821 {
41822- static atomic_t serio_no = ATOMIC_INIT(0);
41823+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
41824
41825 __module_get(THIS_MODULE);
41826
41827@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
41828 mutex_init(&serio->drv_mutex);
41829 device_initialize(&serio->dev);
41830 dev_set_name(&serio->dev, "serio%ld",
41831- (long)atomic_inc_return(&serio_no) - 1);
41832+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
41833 serio->dev.bus = &serio_bus;
41834 serio->dev.release = serio_release_port;
41835 serio->dev.groups = serio_device_attr_groups;
41836diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
41837index 59df2e7..8f1cafb 100644
41838--- a/drivers/input/serio/serio_raw.c
41839+++ b/drivers/input/serio/serio_raw.c
41840@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
41841
41842 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41843 {
41844- static atomic_t serio_raw_no = ATOMIC_INIT(0);
41845+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41846 struct serio_raw *serio_raw;
41847 int err;
41848
41849@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41850 }
41851
41852 snprintf(serio_raw->name, sizeof(serio_raw->name),
41853- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41854+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41855 kref_init(&serio_raw->kref);
41856 INIT_LIST_HEAD(&serio_raw->client_list);
41857 init_waitqueue_head(&serio_raw->wait);
41858diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41859index d8f98b1..f62a640 100644
41860--- a/drivers/iommu/iommu.c
41861+++ b/drivers/iommu/iommu.c
41862@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41863 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41864 {
41865 bus_register_notifier(bus, &iommu_bus_nb);
41866- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41867+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41868 }
41869
41870 /**
41871diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41872index dcfea4e..f4226b2 100644
41873--- a/drivers/iommu/irq_remapping.c
41874+++ b/drivers/iommu/irq_remapping.c
41875@@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41876 void panic_if_irq_remap(const char *msg)
41877 {
41878 if (irq_remapping_enabled)
41879- panic(msg);
41880+ panic("%s", msg);
41881 }
41882
41883 static void ir_ack_apic_edge(struct irq_data *data)
41884@@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41885
41886 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41887 {
41888- chip->irq_print_chip = ir_print_prefix;
41889- chip->irq_ack = ir_ack_apic_edge;
41890- chip->irq_eoi = ir_ack_apic_level;
41891- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41892+ pax_open_kernel();
41893+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41894+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41895+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41896+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41897+ pax_close_kernel();
41898 }
41899
41900 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41901diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41902index 19ceaa6..3625818 100644
41903--- a/drivers/irqchip/irq-gic.c
41904+++ b/drivers/irqchip/irq-gic.c
41905@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41906 * Supported arch specific GIC irq extension.
41907 * Default make them NULL.
41908 */
41909-struct irq_chip gic_arch_extn = {
41910+irq_chip_no_const gic_arch_extn = {
41911 .irq_eoi = NULL,
41912 .irq_mask = NULL,
41913 .irq_unmask = NULL,
41914@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41915 chained_irq_exit(chip, desc);
41916 }
41917
41918-static struct irq_chip gic_chip = {
41919+static irq_chip_no_const gic_chip __read_only = {
41920 .name = "GIC",
41921 .irq_mask = gic_mask_irq,
41922 .irq_unmask = gic_unmask_irq,
41923diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41924index ac6f72b..81150f2 100644
41925--- a/drivers/isdn/capi/capi.c
41926+++ b/drivers/isdn/capi/capi.c
41927@@ -81,8 +81,8 @@ struct capiminor {
41928
41929 struct capi20_appl *ap;
41930 u32 ncci;
41931- atomic_t datahandle;
41932- atomic_t msgid;
41933+ atomic_unchecked_t datahandle;
41934+ atomic_unchecked_t msgid;
41935
41936 struct tty_port port;
41937 int ttyinstop;
41938@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41939 capimsg_setu16(s, 2, mp->ap->applid);
41940 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41941 capimsg_setu8 (s, 5, CAPI_RESP);
41942- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41943+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41944 capimsg_setu32(s, 8, mp->ncci);
41945 capimsg_setu16(s, 12, datahandle);
41946 }
41947@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41948 mp->outbytes -= len;
41949 spin_unlock_bh(&mp->outlock);
41950
41951- datahandle = atomic_inc_return(&mp->datahandle);
41952+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41953 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41954 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41955 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41956 capimsg_setu16(skb->data, 2, mp->ap->applid);
41957 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41958 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41959- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41960+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41961 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41962 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41963 capimsg_setu16(skb->data, 16, len); /* Data length */
41964diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41965index 600c79b..3752bab 100644
41966--- a/drivers/isdn/gigaset/interface.c
41967+++ b/drivers/isdn/gigaset/interface.c
41968@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41969 }
41970 tty->driver_data = cs;
41971
41972- ++cs->port.count;
41973+ atomic_inc(&cs->port.count);
41974
41975- if (cs->port.count == 1) {
41976+ if (atomic_read(&cs->port.count) == 1) {
41977 tty_port_tty_set(&cs->port, tty);
41978 cs->port.low_latency = 1;
41979 }
41980@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41981
41982 if (!cs->connected)
41983 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41984- else if (!cs->port.count)
41985+ else if (!atomic_read(&cs->port.count))
41986 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41987- else if (!--cs->port.count)
41988+ else if (!atomic_dec_return(&cs->port.count))
41989 tty_port_tty_set(&cs->port, NULL);
41990
41991 mutex_unlock(&cs->mutex);
41992diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41993index d0a41cb..f0cdb8c 100644
41994--- a/drivers/isdn/gigaset/usb-gigaset.c
41995+++ b/drivers/isdn/gigaset/usb-gigaset.c
41996@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41997 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41998 memcpy(cs->hw.usb->bchars, buf, 6);
41999 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
42000- 0, 0, &buf, 6, 2000);
42001+ 0, 0, buf, 6, 2000);
42002 }
42003
42004 static void gigaset_freebcshw(struct bc_state *bcs)
42005diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
42006index 4d9b195..455075c 100644
42007--- a/drivers/isdn/hardware/avm/b1.c
42008+++ b/drivers/isdn/hardware/avm/b1.c
42009@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
42010 }
42011 if (left) {
42012 if (t4file->user) {
42013- if (copy_from_user(buf, dp, left))
42014+ if (left > sizeof buf || copy_from_user(buf, dp, left))
42015 return -EFAULT;
42016 } else {
42017 memcpy(buf, dp, left);
42018@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
42019 }
42020 if (left) {
42021 if (config->user) {
42022- if (copy_from_user(buf, dp, left))
42023+ if (left > sizeof buf || copy_from_user(buf, dp, left))
42024 return -EFAULT;
42025 } else {
42026 memcpy(buf, dp, left);
42027diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
42028index 9bb12ba..d4262f7 100644
42029--- a/drivers/isdn/i4l/isdn_common.c
42030+++ b/drivers/isdn/i4l/isdn_common.c
42031@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42032 } else
42033 return -EINVAL;
42034 case IIOCDBGVAR:
42035+ if (!capable(CAP_SYS_RAWIO))
42036+ return -EPERM;
42037 if (arg) {
42038 if (copy_to_user(argp, &dev, sizeof(ulong)))
42039 return -EFAULT;
42040diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42041index 3c5f249..5fac4d0 100644
42042--- a/drivers/isdn/i4l/isdn_tty.c
42043+++ b/drivers/isdn/i4l/isdn_tty.c
42044@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42045
42046 #ifdef ISDN_DEBUG_MODEM_OPEN
42047 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42048- port->count);
42049+ atomic_read(&port->count));
42050 #endif
42051- port->count++;
42052+ atomic_inc(&port->count);
42053 port->tty = tty;
42054 /*
42055 * Start up serial port
42056@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42057 #endif
42058 return;
42059 }
42060- if ((tty->count == 1) && (port->count != 1)) {
42061+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42062 /*
42063 * Uh, oh. tty->count is 1, which means that the tty
42064 * structure will be freed. Info->count should always
42065@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42066 * serial port won't be shutdown.
42067 */
42068 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42069- "info->count is %d\n", port->count);
42070- port->count = 1;
42071+ "info->count is %d\n", atomic_read(&port->count));
42072+ atomic_set(&port->count, 1);
42073 }
42074- if (--port->count < 0) {
42075+ if (atomic_dec_return(&port->count) < 0) {
42076 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42077- info->line, port->count);
42078- port->count = 0;
42079+ info->line, atomic_read(&port->count));
42080+ atomic_set(&port->count, 0);
42081 }
42082- if (port->count) {
42083+ if (atomic_read(&port->count)) {
42084 #ifdef ISDN_DEBUG_MODEM_OPEN
42085 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42086 #endif
42087@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42088 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42089 return;
42090 isdn_tty_shutdown(info);
42091- port->count = 0;
42092+ atomic_set(&port->count, 0);
42093 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42094 port->tty = NULL;
42095 wake_up_interruptible(&port->open_wait);
42096@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42097 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42098 modem_info *info = &dev->mdm.info[i];
42099
42100- if (info->port.count == 0)
42101+ if (atomic_read(&info->port.count) == 0)
42102 continue;
42103 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42104 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42105diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42106index e74df7c..03a03ba 100644
42107--- a/drivers/isdn/icn/icn.c
42108+++ b/drivers/isdn/icn/icn.c
42109@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42110 if (count > len)
42111 count = len;
42112 if (user) {
42113- if (copy_from_user(msg, buf, count))
42114+ if (count > sizeof msg || copy_from_user(msg, buf, count))
42115 return -EFAULT;
42116 } else
42117 memcpy(msg, buf, count);
42118diff --git a/drivers/isdn/mISDN/dsp_core.c b/drivers/isdn/mISDN/dsp_core.c
42119index 22b720e..77025f5 100644
42120--- a/drivers/isdn/mISDN/dsp_core.c
42121+++ b/drivers/isdn/mISDN/dsp_core.c
42122@@ -288,8 +288,10 @@ dsp_control_req(struct dsp *dsp, struct mISDNhead *hh, struct sk_buff *skb)
42123 u8 *data;
42124 int len;
42125
42126- if (skb->len < sizeof(int))
42127+ if (skb->len < sizeof(int)) {
42128 printk(KERN_ERR "%s: PH_CONTROL message too short\n", __func__);
42129+ return -EINVAL;
42130+ }
42131 cont = *((int *)skb->data);
42132 len = skb->len - sizeof(int);
42133 data = skb->data + sizeof(int);
42134diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42135index 6a8405d..0bd1c7e 100644
42136--- a/drivers/leds/leds-clevo-mail.c
42137+++ b/drivers/leds/leds-clevo-mail.c
42138@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42139 * detected as working, but in reality it is not) as low as
42140 * possible.
42141 */
42142-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
42143+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
42144 {
42145 .callback = clevo_mail_led_dmi_callback,
42146 .ident = "Clevo D410J",
42147diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42148index 64e204e..c6bf189 100644
42149--- a/drivers/leds/leds-ss4200.c
42150+++ b/drivers/leds/leds-ss4200.c
42151@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42152 * detected as working, but in reality it is not) as low as
42153 * possible.
42154 */
42155-static struct dmi_system_id __initdata nas_led_whitelist[] = {
42156+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
42157 {
42158 .callback = ss4200_led_dmi_callback,
42159 .ident = "Intel SS4200-E",
42160diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42161index 0bf1e4e..b4bf44e 100644
42162--- a/drivers/lguest/core.c
42163+++ b/drivers/lguest/core.c
42164@@ -97,9 +97,17 @@ static __init int map_switcher(void)
42165 * The end address needs +1 because __get_vm_area allocates an
42166 * extra guard page, so we need space for that.
42167 */
42168+
42169+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42170+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42171+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42172+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42173+#else
42174 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42175 VM_ALLOC, switcher_addr, switcher_addr
42176 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42177+#endif
42178+
42179 if (!switcher_vma) {
42180 err = -ENOMEM;
42181 printk("lguest: could not map switcher pages high\n");
42182@@ -124,7 +132,7 @@ static __init int map_switcher(void)
42183 * Now the Switcher is mapped at the right address, we can't fail!
42184 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42185 */
42186- memcpy(switcher_vma->addr, start_switcher_text,
42187+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42188 end_switcher_text - start_switcher_text);
42189
42190 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42191diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42192index 5b9ac32..2ef4f26 100644
42193--- a/drivers/lguest/page_tables.c
42194+++ b/drivers/lguest/page_tables.c
42195@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42196 /*:*/
42197
42198 #ifdef CONFIG_X86_PAE
42199-static void release_pmd(pmd_t *spmd)
42200+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42201 {
42202 /* If the entry's not present, there's nothing to release. */
42203 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42204diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42205index f0a3347..f6608b2 100644
42206--- a/drivers/lguest/x86/core.c
42207+++ b/drivers/lguest/x86/core.c
42208@@ -59,7 +59,7 @@ static struct {
42209 /* Offset from where switcher.S was compiled to where we've copied it */
42210 static unsigned long switcher_offset(void)
42211 {
42212- return switcher_addr - (unsigned long)start_switcher_text;
42213+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42214 }
42215
42216 /* This cpu's struct lguest_pages (after the Switcher text page) */
42217@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42218 * These copies are pretty cheap, so we do them unconditionally: */
42219 /* Save the current Host top-level page directory.
42220 */
42221+
42222+#ifdef CONFIG_PAX_PER_CPU_PGD
42223+ pages->state.host_cr3 = read_cr3();
42224+#else
42225 pages->state.host_cr3 = __pa(current->mm->pgd);
42226+#endif
42227+
42228 /*
42229 * Set up the Guest's page tables to see this CPU's pages (and no
42230 * other CPU's pages).
42231@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
42232 * compiled-in switcher code and the high-mapped copy we just made.
42233 */
42234 for (i = 0; i < IDT_ENTRIES; i++)
42235- default_idt_entries[i] += switcher_offset();
42236+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42237
42238 /*
42239 * Set up the Switcher's per-cpu areas.
42240@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
42241 * it will be undisturbed when we switch. To change %cs and jump we
42242 * need this structure to feed to Intel's "lcall" instruction.
42243 */
42244- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42245+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42246 lguest_entry.segment = LGUEST_CS;
42247
42248 /*
42249diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42250index 40634b0..4f5855e 100644
42251--- a/drivers/lguest/x86/switcher_32.S
42252+++ b/drivers/lguest/x86/switcher_32.S
42253@@ -87,6 +87,7 @@
42254 #include <asm/page.h>
42255 #include <asm/segment.h>
42256 #include <asm/lguest.h>
42257+#include <asm/processor-flags.h>
42258
42259 // We mark the start of the code to copy
42260 // It's placed in .text tho it's never run here
42261@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42262 // Changes type when we load it: damn Intel!
42263 // For after we switch over our page tables
42264 // That entry will be read-only: we'd crash.
42265+
42266+#ifdef CONFIG_PAX_KERNEXEC
42267+ mov %cr0, %edx
42268+ xor $X86_CR0_WP, %edx
42269+ mov %edx, %cr0
42270+#endif
42271+
42272 movl $(GDT_ENTRY_TSS*8), %edx
42273 ltr %dx
42274
42275@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42276 // Let's clear it again for our return.
42277 // The GDT descriptor of the Host
42278 // Points to the table after two "size" bytes
42279- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42280+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42281 // Clear "used" from type field (byte 5, bit 2)
42282- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42283+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42284+
42285+#ifdef CONFIG_PAX_KERNEXEC
42286+ mov %cr0, %eax
42287+ xor $X86_CR0_WP, %eax
42288+ mov %eax, %cr0
42289+#endif
42290
42291 // Once our page table's switched, the Guest is live!
42292 // The Host fades as we run this final step.
42293@@ -295,13 +309,12 @@ deliver_to_host:
42294 // I consulted gcc, and it gave
42295 // These instructions, which I gladly credit:
42296 leal (%edx,%ebx,8), %eax
42297- movzwl (%eax),%edx
42298- movl 4(%eax), %eax
42299- xorw %ax, %ax
42300- orl %eax, %edx
42301+ movl 4(%eax), %edx
42302+ movw (%eax), %dx
42303 // Now the address of the handler's in %edx
42304 // We call it now: its "iret" drops us home.
42305- jmp *%edx
42306+ ljmp $__KERNEL_CS, $1f
42307+1: jmp *%edx
42308
42309 // Every interrupt can come to us here
42310 // But we must truly tell each apart.
42311diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42312index 0003992..854bbce 100644
42313--- a/drivers/md/bcache/closure.h
42314+++ b/drivers/md/bcache/closure.h
42315@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42316 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42317 struct workqueue_struct *wq)
42318 {
42319- BUG_ON(object_is_on_stack(cl));
42320+ BUG_ON(object_starts_on_stack(cl));
42321 closure_set_ip(cl);
42322 cl->fn = fn;
42323 cl->wq = wq;
42324diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42325index b4713ce..b30139b 100644
42326--- a/drivers/md/bcache/super.c
42327+++ b/drivers/md/bcache/super.c
42328@@ -1603,7 +1603,7 @@ err_unlock_gc:
42329 err:
42330 closure_sync(&op.cl);
42331 /* XXX: test this, it's broken */
42332- bch_cache_set_error(c, err);
42333+ bch_cache_set_error(c, "%s", err);
42334 }
42335
42336 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42337diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42338index 5a2c754..0fa55db 100644
42339--- a/drivers/md/bitmap.c
42340+++ b/drivers/md/bitmap.c
42341@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42342 chunk_kb ? "KB" : "B");
42343 if (bitmap->storage.file) {
42344 seq_printf(seq, ", file: ");
42345- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42346+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42347 }
42348
42349 seq_printf(seq, "\n");
42350diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42351index 81a79b7..87a0f73 100644
42352--- a/drivers/md/dm-ioctl.c
42353+++ b/drivers/md/dm-ioctl.c
42354@@ -1697,7 +1697,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42355 cmd == DM_LIST_VERSIONS_CMD)
42356 return 0;
42357
42358- if ((cmd == DM_DEV_CREATE_CMD)) {
42359+ if (cmd == DM_DEV_CREATE_CMD) {
42360 if (!*param->name) {
42361 DMWARN("name not supplied when creating device");
42362 return -EINVAL;
42363diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42364index 699b5be..eac0a15 100644
42365--- a/drivers/md/dm-raid1.c
42366+++ b/drivers/md/dm-raid1.c
42367@@ -40,7 +40,7 @@ enum dm_raid1_error {
42368
42369 struct mirror {
42370 struct mirror_set *ms;
42371- atomic_t error_count;
42372+ atomic_unchecked_t error_count;
42373 unsigned long error_type;
42374 struct dm_dev *dev;
42375 sector_t offset;
42376@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42377 struct mirror *m;
42378
42379 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42380- if (!atomic_read(&m->error_count))
42381+ if (!atomic_read_unchecked(&m->error_count))
42382 return m;
42383
42384 return NULL;
42385@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42386 * simple way to tell if a device has encountered
42387 * errors.
42388 */
42389- atomic_inc(&m->error_count);
42390+ atomic_inc_unchecked(&m->error_count);
42391
42392 if (test_and_set_bit(error_type, &m->error_type))
42393 return;
42394@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42395 struct mirror *m = get_default_mirror(ms);
42396
42397 do {
42398- if (likely(!atomic_read(&m->error_count)))
42399+ if (likely(!atomic_read_unchecked(&m->error_count)))
42400 return m;
42401
42402 if (m-- == ms->mirror)
42403@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42404 {
42405 struct mirror *default_mirror = get_default_mirror(m->ms);
42406
42407- return !atomic_read(&default_mirror->error_count);
42408+ return !atomic_read_unchecked(&default_mirror->error_count);
42409 }
42410
42411 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42412@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42413 */
42414 if (likely(region_in_sync(ms, region, 1)))
42415 m = choose_mirror(ms, bio->bi_sector);
42416- else if (m && atomic_read(&m->error_count))
42417+ else if (m && atomic_read_unchecked(&m->error_count))
42418 m = NULL;
42419
42420 if (likely(m))
42421@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42422 }
42423
42424 ms->mirror[mirror].ms = ms;
42425- atomic_set(&(ms->mirror[mirror].error_count), 0);
42426+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42427 ms->mirror[mirror].error_type = 0;
42428 ms->mirror[mirror].offset = offset;
42429
42430@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
42431 */
42432 static char device_status_char(struct mirror *m)
42433 {
42434- if (!atomic_read(&(m->error_count)))
42435+ if (!atomic_read_unchecked(&(m->error_count)))
42436 return 'A';
42437
42438 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42439diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42440index d907ca6..cfb8384 100644
42441--- a/drivers/md/dm-stripe.c
42442+++ b/drivers/md/dm-stripe.c
42443@@ -20,7 +20,7 @@ struct stripe {
42444 struct dm_dev *dev;
42445 sector_t physical_start;
42446
42447- atomic_t error_count;
42448+ atomic_unchecked_t error_count;
42449 };
42450
42451 struct stripe_c {
42452@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42453 kfree(sc);
42454 return r;
42455 }
42456- atomic_set(&(sc->stripe[i].error_count), 0);
42457+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42458 }
42459
42460 ti->private = sc;
42461@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42462 DMEMIT("%d ", sc->stripes);
42463 for (i = 0; i < sc->stripes; i++) {
42464 DMEMIT("%s ", sc->stripe[i].dev->name);
42465- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42466+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42467 'D' : 'A';
42468 }
42469 buffer[i] = '\0';
42470@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42471 */
42472 for (i = 0; i < sc->stripes; i++)
42473 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42474- atomic_inc(&(sc->stripe[i].error_count));
42475- if (atomic_read(&(sc->stripe[i].error_count)) <
42476+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42477+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42478 DM_IO_ERROR_THRESHOLD)
42479 schedule_work(&sc->trigger_event);
42480 }
42481diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42482index 1ff252a..ee384c1 100644
42483--- a/drivers/md/dm-table.c
42484+++ b/drivers/md/dm-table.c
42485@@ -389,7 +389,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42486 if (!dev_size)
42487 return 0;
42488
42489- if ((start >= dev_size) || (start + len > dev_size)) {
42490+ if ((start >= dev_size) || (len > dev_size - start)) {
42491 DMWARN("%s: %s too small for target: "
42492 "start=%llu, len=%llu, dev_size=%llu",
42493 dm_device_name(ti->table->md), bdevname(bdev, b),
42494diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42495index 60bce43..9b997d0 100644
42496--- a/drivers/md/dm-thin-metadata.c
42497+++ b/drivers/md/dm-thin-metadata.c
42498@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42499 {
42500 pmd->info.tm = pmd->tm;
42501 pmd->info.levels = 2;
42502- pmd->info.value_type.context = pmd->data_sm;
42503+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42504 pmd->info.value_type.size = sizeof(__le64);
42505 pmd->info.value_type.inc = data_block_inc;
42506 pmd->info.value_type.dec = data_block_dec;
42507@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42508
42509 pmd->bl_info.tm = pmd->tm;
42510 pmd->bl_info.levels = 1;
42511- pmd->bl_info.value_type.context = pmd->data_sm;
42512+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42513 pmd->bl_info.value_type.size = sizeof(__le64);
42514 pmd->bl_info.value_type.inc = data_block_inc;
42515 pmd->bl_info.value_type.dec = data_block_dec;
42516diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42517index 33f2010..23fb84c 100644
42518--- a/drivers/md/dm.c
42519+++ b/drivers/md/dm.c
42520@@ -169,9 +169,9 @@ struct mapped_device {
42521 /*
42522 * Event handling.
42523 */
42524- atomic_t event_nr;
42525+ atomic_unchecked_t event_nr;
42526 wait_queue_head_t eventq;
42527- atomic_t uevent_seq;
42528+ atomic_unchecked_t uevent_seq;
42529 struct list_head uevent_list;
42530 spinlock_t uevent_lock; /* Protect access to uevent_list */
42531
42532@@ -1884,8 +1884,8 @@ static struct mapped_device *alloc_dev(int minor)
42533 rwlock_init(&md->map_lock);
42534 atomic_set(&md->holders, 1);
42535 atomic_set(&md->open_count, 0);
42536- atomic_set(&md->event_nr, 0);
42537- atomic_set(&md->uevent_seq, 0);
42538+ atomic_set_unchecked(&md->event_nr, 0);
42539+ atomic_set_unchecked(&md->uevent_seq, 0);
42540 INIT_LIST_HEAD(&md->uevent_list);
42541 spin_lock_init(&md->uevent_lock);
42542
42543@@ -2033,7 +2033,7 @@ static void event_callback(void *context)
42544
42545 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42546
42547- atomic_inc(&md->event_nr);
42548+ atomic_inc_unchecked(&md->event_nr);
42549 wake_up(&md->eventq);
42550 }
42551
42552@@ -2690,18 +2690,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42553
42554 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42555 {
42556- return atomic_add_return(1, &md->uevent_seq);
42557+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42558 }
42559
42560 uint32_t dm_get_event_nr(struct mapped_device *md)
42561 {
42562- return atomic_read(&md->event_nr);
42563+ return atomic_read_unchecked(&md->event_nr);
42564 }
42565
42566 int dm_wait_event(struct mapped_device *md, int event_nr)
42567 {
42568 return wait_event_interruptible(md->eventq,
42569- (event_nr != atomic_read(&md->event_nr)));
42570+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42571 }
42572
42573 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42574diff --git a/drivers/md/md.c b/drivers/md/md.c
42575index 51f0345..c77810e 100644
42576--- a/drivers/md/md.c
42577+++ b/drivers/md/md.c
42578@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42579 * start build, activate spare
42580 */
42581 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42582-static atomic_t md_event_count;
42583+static atomic_unchecked_t md_event_count;
42584 void md_new_event(struct mddev *mddev)
42585 {
42586- atomic_inc(&md_event_count);
42587+ atomic_inc_unchecked(&md_event_count);
42588 wake_up(&md_event_waiters);
42589 }
42590 EXPORT_SYMBOL_GPL(md_new_event);
42591@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42592 */
42593 static void md_new_event_inintr(struct mddev *mddev)
42594 {
42595- atomic_inc(&md_event_count);
42596+ atomic_inc_unchecked(&md_event_count);
42597 wake_up(&md_event_waiters);
42598 }
42599
42600@@ -1501,7 +1501,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42601 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42602 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42603 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42604- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42605+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42606
42607 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42608 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42609@@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42610 else
42611 sb->resync_offset = cpu_to_le64(0);
42612
42613- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42614+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42615
42616 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42617 sb->size = cpu_to_le64(mddev->dev_sectors);
42618@@ -2750,7 +2750,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42619 static ssize_t
42620 errors_show(struct md_rdev *rdev, char *page)
42621 {
42622- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42623+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42624 }
42625
42626 static ssize_t
42627@@ -2759,7 +2759,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42628 char *e;
42629 unsigned long n = simple_strtoul(buf, &e, 10);
42630 if (*buf && (*e == 0 || *e == '\n')) {
42631- atomic_set(&rdev->corrected_errors, n);
42632+ atomic_set_unchecked(&rdev->corrected_errors, n);
42633 return len;
42634 }
42635 return -EINVAL;
42636@@ -3207,8 +3207,8 @@ int md_rdev_init(struct md_rdev *rdev)
42637 rdev->sb_loaded = 0;
42638 rdev->bb_page = NULL;
42639 atomic_set(&rdev->nr_pending, 0);
42640- atomic_set(&rdev->read_errors, 0);
42641- atomic_set(&rdev->corrected_errors, 0);
42642+ atomic_set_unchecked(&rdev->read_errors, 0);
42643+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42644
42645 INIT_LIST_HEAD(&rdev->same_set);
42646 init_waitqueue_head(&rdev->blocked_wait);
42647@@ -7009,7 +7009,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42648
42649 spin_unlock(&pers_lock);
42650 seq_printf(seq, "\n");
42651- seq->poll_event = atomic_read(&md_event_count);
42652+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42653 return 0;
42654 }
42655 if (v == (void*)2) {
42656@@ -7112,7 +7112,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42657 return error;
42658
42659 seq = file->private_data;
42660- seq->poll_event = atomic_read(&md_event_count);
42661+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42662 return error;
42663 }
42664
42665@@ -7126,7 +7126,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42666 /* always allow read */
42667 mask = POLLIN | POLLRDNORM;
42668
42669- if (seq->poll_event != atomic_read(&md_event_count))
42670+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42671 mask |= POLLERR | POLLPRI;
42672 return mask;
42673 }
42674@@ -7170,7 +7170,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42675 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42676 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42677 (int)part_stat_read(&disk->part0, sectors[1]) -
42678- atomic_read(&disk->sync_io);
42679+ atomic_read_unchecked(&disk->sync_io);
42680 /* sync IO will cause sync_io to increase before the disk_stats
42681 * as sync_io is counted when a request starts, and
42682 * disk_stats is counted when it completes.
42683diff --git a/drivers/md/md.h b/drivers/md/md.h
42684index 653f992b6..6af6c40 100644
42685--- a/drivers/md/md.h
42686+++ b/drivers/md/md.h
42687@@ -94,13 +94,13 @@ struct md_rdev {
42688 * only maintained for arrays that
42689 * support hot removal
42690 */
42691- atomic_t read_errors; /* number of consecutive read errors that
42692+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42693 * we have tried to ignore.
42694 */
42695 struct timespec last_read_error; /* monotonic time since our
42696 * last read error
42697 */
42698- atomic_t corrected_errors; /* number of corrected read errors,
42699+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42700 * for reporting to userspace and storing
42701 * in superblock.
42702 */
42703@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42704
42705 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42706 {
42707- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42708+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42709 }
42710
42711 struct md_personality
42712diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42713index 3e6d115..ffecdeb 100644
42714--- a/drivers/md/persistent-data/dm-space-map.h
42715+++ b/drivers/md/persistent-data/dm-space-map.h
42716@@ -71,6 +71,7 @@ struct dm_space_map {
42717 dm_sm_threshold_fn fn,
42718 void *context);
42719 };
42720+typedef struct dm_space_map __no_const dm_space_map_no_const;
42721
42722 /*----------------------------------------------------------------*/
42723
42724diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42725index 6f48244..7d29145 100644
42726--- a/drivers/md/raid1.c
42727+++ b/drivers/md/raid1.c
42728@@ -1822,7 +1822,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42729 if (r1_sync_page_io(rdev, sect, s,
42730 bio->bi_io_vec[idx].bv_page,
42731 READ) != 0)
42732- atomic_add(s, &rdev->corrected_errors);
42733+ atomic_add_unchecked(s, &rdev->corrected_errors);
42734 }
42735 sectors -= s;
42736 sect += s;
42737@@ -2049,7 +2049,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42738 test_bit(In_sync, &rdev->flags)) {
42739 if (r1_sync_page_io(rdev, sect, s,
42740 conf->tmppage, READ)) {
42741- atomic_add(s, &rdev->corrected_errors);
42742+ atomic_add_unchecked(s, &rdev->corrected_errors);
42743 printk(KERN_INFO
42744 "md/raid1:%s: read error corrected "
42745 "(%d sectors at %llu on %s)\n",
42746diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42747index 081bb33..3c4b287 100644
42748--- a/drivers/md/raid10.c
42749+++ b/drivers/md/raid10.c
42750@@ -1940,7 +1940,7 @@ static void end_sync_read(struct bio *bio, int error)
42751 /* The write handler will notice the lack of
42752 * R10BIO_Uptodate and record any errors etc
42753 */
42754- atomic_add(r10_bio->sectors,
42755+ atomic_add_unchecked(r10_bio->sectors,
42756 &conf->mirrors[d].rdev->corrected_errors);
42757
42758 /* for reconstruct, we always reschedule after a read.
42759@@ -2298,7 +2298,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42760 {
42761 struct timespec cur_time_mon;
42762 unsigned long hours_since_last;
42763- unsigned int read_errors = atomic_read(&rdev->read_errors);
42764+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42765
42766 ktime_get_ts(&cur_time_mon);
42767
42768@@ -2320,9 +2320,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42769 * overflowing the shift of read_errors by hours_since_last.
42770 */
42771 if (hours_since_last >= 8 * sizeof(read_errors))
42772- atomic_set(&rdev->read_errors, 0);
42773+ atomic_set_unchecked(&rdev->read_errors, 0);
42774 else
42775- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42776+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42777 }
42778
42779 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42780@@ -2376,8 +2376,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42781 return;
42782
42783 check_decay_read_errors(mddev, rdev);
42784- atomic_inc(&rdev->read_errors);
42785- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42786+ atomic_inc_unchecked(&rdev->read_errors);
42787+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42788 char b[BDEVNAME_SIZE];
42789 bdevname(rdev->bdev, b);
42790
42791@@ -2385,7 +2385,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42792 "md/raid10:%s: %s: Raid device exceeded "
42793 "read_error threshold [cur %d:max %d]\n",
42794 mdname(mddev), b,
42795- atomic_read(&rdev->read_errors), max_read_errors);
42796+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42797 printk(KERN_NOTICE
42798 "md/raid10:%s: %s: Failing raid device\n",
42799 mdname(mddev), b);
42800@@ -2540,7 +2540,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42801 sect +
42802 choose_data_offset(r10_bio, rdev)),
42803 bdevname(rdev->bdev, b));
42804- atomic_add(s, &rdev->corrected_errors);
42805+ atomic_add_unchecked(s, &rdev->corrected_errors);
42806 }
42807
42808 rdev_dec_pending(rdev, mddev);
42809diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42810index a35b846..e295c6d 100644
42811--- a/drivers/md/raid5.c
42812+++ b/drivers/md/raid5.c
42813@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42814 mdname(conf->mddev), STRIPE_SECTORS,
42815 (unsigned long long)s,
42816 bdevname(rdev->bdev, b));
42817- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42818+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42819 clear_bit(R5_ReadError, &sh->dev[i].flags);
42820 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42821 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42822 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42823
42824- if (atomic_read(&rdev->read_errors))
42825- atomic_set(&rdev->read_errors, 0);
42826+ if (atomic_read_unchecked(&rdev->read_errors))
42827+ atomic_set_unchecked(&rdev->read_errors, 0);
42828 } else {
42829 const char *bdn = bdevname(rdev->bdev, b);
42830 int retry = 0;
42831 int set_bad = 0;
42832
42833 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42834- atomic_inc(&rdev->read_errors);
42835+ atomic_inc_unchecked(&rdev->read_errors);
42836 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42837 printk_ratelimited(
42838 KERN_WARNING
42839@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42840 mdname(conf->mddev),
42841 (unsigned long long)s,
42842 bdn);
42843- } else if (atomic_read(&rdev->read_errors)
42844+ } else if (atomic_read_unchecked(&rdev->read_errors)
42845 > conf->max_nr_stripes)
42846 printk(KERN_WARNING
42847 "md/raid:%s: Too many read errors, failing device %s.\n",
42848diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42849index 401ef64..836e563 100644
42850--- a/drivers/media/dvb-core/dvbdev.c
42851+++ b/drivers/media/dvb-core/dvbdev.c
42852@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42853 const struct dvb_device *template, void *priv, int type)
42854 {
42855 struct dvb_device *dvbdev;
42856- struct file_operations *dvbdevfops;
42857+ file_operations_no_const *dvbdevfops;
42858 struct device *clsdev;
42859 int minor;
42860 int id;
42861diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42862index 9b6c3bb..baeb5c7 100644
42863--- a/drivers/media/dvb-frontends/dib3000.h
42864+++ b/drivers/media/dvb-frontends/dib3000.h
42865@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42866 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42867 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42868 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42869-};
42870+} __no_const;
42871
42872 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42873 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42874diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42875index c7a9be1..683f6f8 100644
42876--- a/drivers/media/pci/cx88/cx88-video.c
42877+++ b/drivers/media/pci/cx88/cx88-video.c
42878@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42879
42880 /* ------------------------------------------------------------------ */
42881
42882-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42883-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42884-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42885+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42886+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42887+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42888
42889 module_param_array(video_nr, int, NULL, 0444);
42890 module_param_array(vbi_nr, int, NULL, 0444);
42891diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42892index 07b8460..e6d7265 100644
42893--- a/drivers/media/pci/ivtv/ivtv-driver.c
42894+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42895@@ -84,7 +84,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42896 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42897
42898 /* ivtv instance counter */
42899-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42900+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42901
42902 /* Parameter declarations */
42903 static int cardtype[IVTV_MAX_CARDS];
42904diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42905index d338b19..aae4f9e 100644
42906--- a/drivers/media/platform/omap/omap_vout.c
42907+++ b/drivers/media/platform/omap/omap_vout.c
42908@@ -63,7 +63,6 @@ enum omap_vout_channels {
42909 OMAP_VIDEO2,
42910 };
42911
42912-static struct videobuf_queue_ops video_vbq_ops;
42913 /* Variables configurable through module params*/
42914 static u32 video1_numbuffers = 3;
42915 static u32 video2_numbuffers = 3;
42916@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
42917 {
42918 struct videobuf_queue *q;
42919 struct omap_vout_device *vout = NULL;
42920+ static struct videobuf_queue_ops video_vbq_ops = {
42921+ .buf_setup = omap_vout_buffer_setup,
42922+ .buf_prepare = omap_vout_buffer_prepare,
42923+ .buf_release = omap_vout_buffer_release,
42924+ .buf_queue = omap_vout_buffer_queue,
42925+ };
42926
42927 vout = video_drvdata(file);
42928 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42929@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
42930 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42931
42932 q = &vout->vbq;
42933- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42934- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42935- video_vbq_ops.buf_release = omap_vout_buffer_release;
42936- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42937 spin_lock_init(&vout->vbq_lock);
42938
42939 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42940diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42941index 04e6490..2df65bf 100644
42942--- a/drivers/media/platform/s5p-tv/mixer.h
42943+++ b/drivers/media/platform/s5p-tv/mixer.h
42944@@ -156,7 +156,7 @@ struct mxr_layer {
42945 /** layer index (unique identifier) */
42946 int idx;
42947 /** callbacks for layer methods */
42948- struct mxr_layer_ops ops;
42949+ struct mxr_layer_ops *ops;
42950 /** format array */
42951 const struct mxr_format **fmt_array;
42952 /** size of format array */
42953diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42954index b93a21f..2535195 100644
42955--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42956+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42957@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42958 {
42959 struct mxr_layer *layer;
42960 int ret;
42961- struct mxr_layer_ops ops = {
42962+ static struct mxr_layer_ops ops = {
42963 .release = mxr_graph_layer_release,
42964 .buffer_set = mxr_graph_buffer_set,
42965 .stream_set = mxr_graph_stream_set,
42966diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42967index b713403..53cb5ad 100644
42968--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42969+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42970@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42971 layer->update_buf = next;
42972 }
42973
42974- layer->ops.buffer_set(layer, layer->update_buf);
42975+ layer->ops->buffer_set(layer, layer->update_buf);
42976
42977 if (done && done != layer->shadow_buf)
42978 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42979diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42980index ef0efdf..8c78eb6 100644
42981--- a/drivers/media/platform/s5p-tv/mixer_video.c
42982+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42983@@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42984 layer->geo.src.height = layer->geo.src.full_height;
42985
42986 mxr_geometry_dump(mdev, &layer->geo);
42987- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42988+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42989 mxr_geometry_dump(mdev, &layer->geo);
42990 }
42991
42992@@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42993 layer->geo.dst.full_width = mbus_fmt.width;
42994 layer->geo.dst.full_height = mbus_fmt.height;
42995 layer->geo.dst.field = mbus_fmt.field;
42996- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42997+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42998
42999 mxr_geometry_dump(mdev, &layer->geo);
43000 }
43001@@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
43002 /* set source size to highest accepted value */
43003 geo->src.full_width = max(geo->dst.full_width, pix->width);
43004 geo->src.full_height = max(geo->dst.full_height, pix->height);
43005- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43006+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43007 mxr_geometry_dump(mdev, &layer->geo);
43008 /* set cropping to total visible screen */
43009 geo->src.width = pix->width;
43010@@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
43011 geo->src.x_offset = 0;
43012 geo->src.y_offset = 0;
43013 /* assure consistency of geometry */
43014- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43015+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43016 mxr_geometry_dump(mdev, &layer->geo);
43017 /* set full size to lowest possible value */
43018 geo->src.full_width = 0;
43019 geo->src.full_height = 0;
43020- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43021+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43022 mxr_geometry_dump(mdev, &layer->geo);
43023
43024 /* returning results */
43025@@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43026 target->width = s->r.width;
43027 target->height = s->r.height;
43028
43029- layer->ops.fix_geometry(layer, stage, s->flags);
43030+ layer->ops->fix_geometry(layer, stage, s->flags);
43031
43032 /* retrieve update selection rectangle */
43033 res.left = target->x_offset;
43034@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43035 mxr_output_get(mdev);
43036
43037 mxr_layer_update_output(layer);
43038- layer->ops.format_set(layer);
43039+ layer->ops->format_set(layer);
43040 /* enabling layer in hardware */
43041 spin_lock_irqsave(&layer->enq_slock, flags);
43042 layer->state = MXR_LAYER_STREAMING;
43043 spin_unlock_irqrestore(&layer->enq_slock, flags);
43044
43045- layer->ops.stream_set(layer, MXR_ENABLE);
43046+ layer->ops->stream_set(layer, MXR_ENABLE);
43047 mxr_streamer_get(mdev);
43048
43049 return 0;
43050@@ -1030,7 +1030,7 @@ static int stop_streaming(struct vb2_queue *vq)
43051 spin_unlock_irqrestore(&layer->enq_slock, flags);
43052
43053 /* disabling layer in hardware */
43054- layer->ops.stream_set(layer, MXR_DISABLE);
43055+ layer->ops->stream_set(layer, MXR_DISABLE);
43056 /* remove one streamer */
43057 mxr_streamer_put(mdev);
43058 /* allow changes in output configuration */
43059@@ -1069,8 +1069,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43060
43061 void mxr_layer_release(struct mxr_layer *layer)
43062 {
43063- if (layer->ops.release)
43064- layer->ops.release(layer);
43065+ if (layer->ops->release)
43066+ layer->ops->release(layer);
43067 }
43068
43069 void mxr_base_layer_release(struct mxr_layer *layer)
43070@@ -1096,7 +1096,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43071
43072 layer->mdev = mdev;
43073 layer->idx = idx;
43074- layer->ops = *ops;
43075+ layer->ops = ops;
43076
43077 spin_lock_init(&layer->enq_slock);
43078 INIT_LIST_HEAD(&layer->enq_list);
43079diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43080index 3d13a63..da31bf1 100644
43081--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43082+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43083@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43084 {
43085 struct mxr_layer *layer;
43086 int ret;
43087- struct mxr_layer_ops ops = {
43088+ static struct mxr_layer_ops ops = {
43089 .release = mxr_vp_layer_release,
43090 .buffer_set = mxr_vp_buffer_set,
43091 .stream_set = mxr_vp_stream_set,
43092diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43093index 545c04c..a14bded 100644
43094--- a/drivers/media/radio/radio-cadet.c
43095+++ b/drivers/media/radio/radio-cadet.c
43096@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43097 unsigned char readbuf[RDS_BUFFER];
43098 int i = 0;
43099
43100+ if (count > RDS_BUFFER)
43101+ return -EFAULT;
43102 mutex_lock(&dev->lock);
43103 if (dev->rdsstat == 0)
43104 cadet_start_rds(dev);
43105@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43106 while (i < count && dev->rdsin != dev->rdsout)
43107 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43108
43109- if (i && copy_to_user(data, readbuf, i))
43110+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43111 i = -EFAULT;
43112 unlock:
43113 mutex_unlock(&dev->lock);
43114diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43115index bd4d3a7..ffc0b9d 100644
43116--- a/drivers/media/radio/radio-maxiradio.c
43117+++ b/drivers/media/radio/radio-maxiradio.c
43118@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43119 /* TEA5757 pin mappings */
43120 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43121
43122-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43123+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43124
43125 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43126 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43127diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43128index 8fa18ab..caee70f 100644
43129--- a/drivers/media/radio/radio-shark.c
43130+++ b/drivers/media/radio/radio-shark.c
43131@@ -79,7 +79,7 @@ struct shark_device {
43132 u32 last_val;
43133 };
43134
43135-static atomic_t shark_instance = ATOMIC_INIT(0);
43136+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43137
43138 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43139 {
43140diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43141index 9fb6697..f167415 100644
43142--- a/drivers/media/radio/radio-shark2.c
43143+++ b/drivers/media/radio/radio-shark2.c
43144@@ -74,7 +74,7 @@ struct shark_device {
43145 u8 *transfer_buffer;
43146 };
43147
43148-static atomic_t shark_instance = ATOMIC_INIT(0);
43149+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43150
43151 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43152 {
43153diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43154index 9dc8baf..796d52f 100644
43155--- a/drivers/media/radio/radio-si476x.c
43156+++ b/drivers/media/radio/radio-si476x.c
43157@@ -1456,7 +1456,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43158 struct si476x_radio *radio;
43159 struct v4l2_ctrl *ctrl;
43160
43161- static atomic_t instance = ATOMIC_INIT(0);
43162+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
43163
43164 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43165 if (!radio)
43166diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43167index 1cf382a..c22998c 100644
43168--- a/drivers/media/rc/rc-main.c
43169+++ b/drivers/media/rc/rc-main.c
43170@@ -1030,7 +1030,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43171 int rc_register_device(struct rc_dev *dev)
43172 {
43173 static bool raw_init = false; /* raw decoders loaded? */
43174- static atomic_t devno = ATOMIC_INIT(0);
43175+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
43176 struct rc_map *rc_map;
43177 const char *path;
43178 int rc;
43179@@ -1061,7 +1061,7 @@ int rc_register_device(struct rc_dev *dev)
43180 */
43181 mutex_lock(&dev->lock);
43182
43183- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43184+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43185 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43186 dev_set_drvdata(&dev->dev, dev);
43187 rc = device_add(&dev->dev);
43188diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43189index 3940bb0..fb3952a 100644
43190--- a/drivers/media/usb/dvb-usb/cxusb.c
43191+++ b/drivers/media/usb/dvb-usb/cxusb.c
43192@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43193
43194 struct dib0700_adapter_state {
43195 int (*set_param_save) (struct dvb_frontend *);
43196-};
43197+} __no_const;
43198
43199 static int dib7070_set_param_override(struct dvb_frontend *fe)
43200 {
43201diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43202index 6e237b6..dc25556 100644
43203--- a/drivers/media/usb/dvb-usb/dw2102.c
43204+++ b/drivers/media/usb/dvb-usb/dw2102.c
43205@@ -118,7 +118,7 @@ struct su3000_state {
43206
43207 struct s6x0_state {
43208 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43209-};
43210+} __no_const;
43211
43212 /* debug */
43213 static int dvb_usb_dw2102_debug;
43214diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43215index f129551..ecf6514 100644
43216--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43217+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43218@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43219 __u32 reserved;
43220 };
43221
43222-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43223+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43224 enum v4l2_memory memory)
43225 {
43226 void __user *up_pln;
43227@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43228 return 0;
43229 }
43230
43231-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43232+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43233 enum v4l2_memory memory)
43234 {
43235 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43236@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43237 put_user(kp->start_block, &up->start_block) ||
43238 put_user(kp->blocks, &up->blocks) ||
43239 put_user(tmp, &up->edid) ||
43240- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43241+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43242 return -EFAULT;
43243 return 0;
43244 }
43245diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43246index 8ed5da2..47fee46 100644
43247--- a/drivers/media/v4l2-core/v4l2-device.c
43248+++ b/drivers/media/v4l2-core/v4l2-device.c
43249@@ -74,9 +74,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43250 EXPORT_SYMBOL_GPL(v4l2_device_put);
43251
43252 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43253- atomic_t *instance)
43254+ atomic_unchecked_t *instance)
43255 {
43256- int num = atomic_inc_return(instance) - 1;
43257+ int num = atomic_inc_return_unchecked(instance) - 1;
43258 int len = strlen(basename);
43259
43260 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43261diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43262index 7658586..1079260 100644
43263--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43264+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43265@@ -1995,7 +1995,8 @@ struct v4l2_ioctl_info {
43266 struct file *file, void *fh, void *p);
43267 } u;
43268 void (*debug)(const void *arg, bool write_only);
43269-};
43270+} __do_const;
43271+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43272
43273 /* This control needs a priority check */
43274 #define INFO_FL_PRIO (1 << 0)
43275@@ -2177,7 +2178,7 @@ static long __video_do_ioctl(struct file *file,
43276 struct video_device *vfd = video_devdata(file);
43277 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43278 bool write_only = false;
43279- struct v4l2_ioctl_info default_info;
43280+ v4l2_ioctl_info_no_const default_info;
43281 const struct v4l2_ioctl_info *info;
43282 void *fh = file->private_data;
43283 struct v4l2_fh *vfh = NULL;
43284@@ -2251,7 +2252,7 @@ done:
43285 }
43286
43287 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43288- void * __user *user_ptr, void ***kernel_ptr)
43289+ void __user **user_ptr, void ***kernel_ptr)
43290 {
43291 int ret = 0;
43292
43293@@ -2267,7 +2268,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43294 ret = -EINVAL;
43295 break;
43296 }
43297- *user_ptr = (void __user *)buf->m.planes;
43298+ *user_ptr = (void __force_user *)buf->m.planes;
43299 *kernel_ptr = (void *)&buf->m.planes;
43300 *array_size = sizeof(struct v4l2_plane) * buf->length;
43301 ret = 1;
43302@@ -2302,7 +2303,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43303 ret = -EINVAL;
43304 break;
43305 }
43306- *user_ptr = (void __user *)ctrls->controls;
43307+ *user_ptr = (void __force_user *)ctrls->controls;
43308 *kernel_ptr = (void *)&ctrls->controls;
43309 *array_size = sizeof(struct v4l2_ext_control)
43310 * ctrls->count;
43311diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43312index 767ff4d..c69d259 100644
43313--- a/drivers/message/fusion/mptbase.c
43314+++ b/drivers/message/fusion/mptbase.c
43315@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43316 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43317 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43318
43319+#ifdef CONFIG_GRKERNSEC_HIDESYM
43320+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43321+#else
43322 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43323 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43324+#endif
43325+
43326 /*
43327 * Rounding UP to nearest 4-kB boundary here...
43328 */
43329@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43330 ioc->facts.GlobalCredits);
43331
43332 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43333+#ifdef CONFIG_GRKERNSEC_HIDESYM
43334+ NULL, NULL);
43335+#else
43336 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43337+#endif
43338 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43339 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43340 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43341diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43342index dd239bd..689c4f7 100644
43343--- a/drivers/message/fusion/mptsas.c
43344+++ b/drivers/message/fusion/mptsas.c
43345@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43346 return 0;
43347 }
43348
43349+static inline void
43350+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43351+{
43352+ if (phy_info->port_details) {
43353+ phy_info->port_details->rphy = rphy;
43354+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43355+ ioc->name, rphy));
43356+ }
43357+
43358+ if (rphy) {
43359+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43360+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43361+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43362+ ioc->name, rphy, rphy->dev.release));
43363+ }
43364+}
43365+
43366 /* no mutex */
43367 static void
43368 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43369@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43370 return NULL;
43371 }
43372
43373-static inline void
43374-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43375-{
43376- if (phy_info->port_details) {
43377- phy_info->port_details->rphy = rphy;
43378- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43379- ioc->name, rphy));
43380- }
43381-
43382- if (rphy) {
43383- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43384- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43385- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43386- ioc->name, rphy, rphy->dev.release));
43387- }
43388-}
43389-
43390 static inline struct sas_port *
43391 mptsas_get_port(struct mptsas_phyinfo *phy_info)
43392 {
43393diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
43394index 727819c..ad74694 100644
43395--- a/drivers/message/fusion/mptscsih.c
43396+++ b/drivers/message/fusion/mptscsih.c
43397@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
43398
43399 h = shost_priv(SChost);
43400
43401- if (h) {
43402- if (h->info_kbuf == NULL)
43403- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43404- return h->info_kbuf;
43405- h->info_kbuf[0] = '\0';
43406+ if (!h)
43407+ return NULL;
43408
43409- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43410- h->info_kbuf[size-1] = '\0';
43411- }
43412+ if (h->info_kbuf == NULL)
43413+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43414+ return h->info_kbuf;
43415+ h->info_kbuf[0] = '\0';
43416+
43417+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43418+ h->info_kbuf[size-1] = '\0';
43419
43420 return h->info_kbuf;
43421 }
43422diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43423index b7d87cd..9890039 100644
43424--- a/drivers/message/i2o/i2o_proc.c
43425+++ b/drivers/message/i2o/i2o_proc.c
43426@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43427 "Array Controller Device"
43428 };
43429
43430-static char *chtostr(char *tmp, u8 *chars, int n)
43431-{
43432- tmp[0] = 0;
43433- return strncat(tmp, (char *)chars, n);
43434-}
43435-
43436 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43437 char *group)
43438 {
43439@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43440 } *result;
43441
43442 i2o_exec_execute_ddm_table ddm_table;
43443- char tmp[28 + 1];
43444
43445 result = kmalloc(sizeof(*result), GFP_KERNEL);
43446 if (!result)
43447@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43448
43449 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43450 seq_printf(seq, "%-#8x", ddm_table.module_id);
43451- seq_printf(seq, "%-29s",
43452- chtostr(tmp, ddm_table.module_name_version, 28));
43453+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43454 seq_printf(seq, "%9d ", ddm_table.data_size);
43455 seq_printf(seq, "%8d", ddm_table.code_size);
43456
43457@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43458
43459 i2o_driver_result_table *result;
43460 i2o_driver_store_table *dst;
43461- char tmp[28 + 1];
43462
43463 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43464 if (result == NULL)
43465@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43466
43467 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43468 seq_printf(seq, "%-#8x", dst->module_id);
43469- seq_printf(seq, "%-29s",
43470- chtostr(tmp, dst->module_name_version, 28));
43471- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43472+ seq_printf(seq, "%-.28s", dst->module_name_version);
43473+ seq_printf(seq, "%-.8s", dst->date);
43474 seq_printf(seq, "%8d ", dst->module_size);
43475 seq_printf(seq, "%8d ", dst->mpb_size);
43476 seq_printf(seq, "0x%04x", dst->module_flags);
43477@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43478 // == (allow) 512d bytes (max)
43479 static u16 *work16 = (u16 *) work32;
43480 int token;
43481- char tmp[16 + 1];
43482
43483 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43484
43485@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43486 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43487 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43488 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43489- seq_printf(seq, "Vendor info : %s\n",
43490- chtostr(tmp, (u8 *) (work32 + 2), 16));
43491- seq_printf(seq, "Product info : %s\n",
43492- chtostr(tmp, (u8 *) (work32 + 6), 16));
43493- seq_printf(seq, "Description : %s\n",
43494- chtostr(tmp, (u8 *) (work32 + 10), 16));
43495- seq_printf(seq, "Product rev. : %s\n",
43496- chtostr(tmp, (u8 *) (work32 + 14), 8));
43497+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43498+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43499+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43500+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43501
43502 seq_printf(seq, "Serial number : ");
43503 print_serial_number(seq, (u8 *) (work32 + 16),
43504@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43505 u8 pad[256]; // allow up to 256 byte (max) serial number
43506 } result;
43507
43508- char tmp[24 + 1];
43509-
43510 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43511
43512 if (token < 0) {
43513@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43514 }
43515
43516 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43517- seq_printf(seq, "Module name : %s\n",
43518- chtostr(tmp, result.module_name, 24));
43519- seq_printf(seq, "Module revision : %s\n",
43520- chtostr(tmp, result.module_rev, 8));
43521+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43522+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43523
43524 seq_printf(seq, "Serial number : ");
43525 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43526@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43527 u8 instance_number[4];
43528 } result;
43529
43530- char tmp[64 + 1];
43531-
43532 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43533
43534 if (token < 0) {
43535@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43536 return 0;
43537 }
43538
43539- seq_printf(seq, "Device name : %s\n",
43540- chtostr(tmp, result.device_name, 64));
43541- seq_printf(seq, "Service name : %s\n",
43542- chtostr(tmp, result.service_name, 64));
43543- seq_printf(seq, "Physical name : %s\n",
43544- chtostr(tmp, result.physical_location, 64));
43545- seq_printf(seq, "Instance number : %s\n",
43546- chtostr(tmp, result.instance_number, 4));
43547+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43548+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43549+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43550+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43551
43552 return 0;
43553 }
43554diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43555index a8c08f3..155fe3d 100644
43556--- a/drivers/message/i2o/iop.c
43557+++ b/drivers/message/i2o/iop.c
43558@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43559
43560 spin_lock_irqsave(&c->context_list_lock, flags);
43561
43562- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43563- atomic_inc(&c->context_list_counter);
43564+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43565+ atomic_inc_unchecked(&c->context_list_counter);
43566
43567- entry->context = atomic_read(&c->context_list_counter);
43568+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43569
43570 list_add(&entry->list, &c->context_list);
43571
43572@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43573
43574 #if BITS_PER_LONG == 64
43575 spin_lock_init(&c->context_list_lock);
43576- atomic_set(&c->context_list_counter, 0);
43577+ atomic_set_unchecked(&c->context_list_counter, 0);
43578 INIT_LIST_HEAD(&c->context_list);
43579 #endif
43580
43581diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43582index 45ece11..8efa218 100644
43583--- a/drivers/mfd/janz-cmodio.c
43584+++ b/drivers/mfd/janz-cmodio.c
43585@@ -13,6 +13,7 @@
43586
43587 #include <linux/kernel.h>
43588 #include <linux/module.h>
43589+#include <linux/slab.h>
43590 #include <linux/init.h>
43591 #include <linux/pci.h>
43592 #include <linux/interrupt.h>
43593diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43594index a5f9888..1c0ed56 100644
43595--- a/drivers/mfd/twl4030-irq.c
43596+++ b/drivers/mfd/twl4030-irq.c
43597@@ -35,6 +35,7 @@
43598 #include <linux/of.h>
43599 #include <linux/irqdomain.h>
43600 #include <linux/i2c/twl.h>
43601+#include <asm/pgtable.h>
43602
43603 #include "twl-core.h"
43604
43605@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43606 * Install an irq handler for each of the SIH modules;
43607 * clone dummy irq_chip since PIH can't *do* anything
43608 */
43609- twl4030_irq_chip = dummy_irq_chip;
43610- twl4030_irq_chip.name = "twl4030";
43611+ pax_open_kernel();
43612+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43613+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43614
43615- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43616+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43617+ pax_close_kernel();
43618
43619 for (i = irq_base; i < irq_end; i++) {
43620 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43621diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
43622index 277a8db..0e0b754 100644
43623--- a/drivers/mfd/twl6030-irq.c
43624+++ b/drivers/mfd/twl6030-irq.c
43625@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
43626 * install an irq handler for each of the modules;
43627 * clone dummy irq_chip since PIH can't *do* anything
43628 */
43629- twl6030_irq_chip = dummy_irq_chip;
43630- twl6030_irq_chip.name = "twl6030";
43631- twl6030_irq_chip.irq_set_type = NULL;
43632- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43633+ pax_open_kernel();
43634+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
43635+ *(const char **)&twl6030_irq_chip.name = "twl6030";
43636+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
43637+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43638+ pax_close_kernel();
43639
43640 for (i = irq_base; i < irq_end; i++) {
43641 irq_set_chip_and_handler(i, &twl6030_irq_chip,
43642diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43643index f32550a..e3e52a2 100644
43644--- a/drivers/misc/c2port/core.c
43645+++ b/drivers/misc/c2port/core.c
43646@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
43647 mutex_init(&c2dev->mutex);
43648
43649 /* Create binary file */
43650- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43651+ pax_open_kernel();
43652+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43653+ pax_close_kernel();
43654 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
43655 if (unlikely(ret))
43656 goto error_device_create_bin_file;
43657diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43658index 36f5d52..32311c3 100644
43659--- a/drivers/misc/kgdbts.c
43660+++ b/drivers/misc/kgdbts.c
43661@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43662 char before[BREAK_INSTR_SIZE];
43663 char after[BREAK_INSTR_SIZE];
43664
43665- probe_kernel_read(before, (char *)kgdbts_break_test,
43666+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43667 BREAK_INSTR_SIZE);
43668 init_simple_test();
43669 ts.tst = plant_and_detach_test;
43670@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43671 /* Activate test with initial breakpoint */
43672 if (!is_early)
43673 kgdb_breakpoint();
43674- probe_kernel_read(after, (char *)kgdbts_break_test,
43675+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43676 BREAK_INSTR_SIZE);
43677 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43678 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43679diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43680index 4cd4a3d..b48cbc7 100644
43681--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43682+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43683@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43684 * the lid is closed. This leads to interrupts as soon as a little move
43685 * is done.
43686 */
43687- atomic_inc(&lis3->count);
43688+ atomic_inc_unchecked(&lis3->count);
43689
43690 wake_up_interruptible(&lis3->misc_wait);
43691 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43692@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43693 if (lis3->pm_dev)
43694 pm_runtime_get_sync(lis3->pm_dev);
43695
43696- atomic_set(&lis3->count, 0);
43697+ atomic_set_unchecked(&lis3->count, 0);
43698 return 0;
43699 }
43700
43701@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43702 add_wait_queue(&lis3->misc_wait, &wait);
43703 while (true) {
43704 set_current_state(TASK_INTERRUPTIBLE);
43705- data = atomic_xchg(&lis3->count, 0);
43706+ data = atomic_xchg_unchecked(&lis3->count, 0);
43707 if (data)
43708 break;
43709
43710@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43711 struct lis3lv02d, miscdev);
43712
43713 poll_wait(file, &lis3->misc_wait, wait);
43714- if (atomic_read(&lis3->count))
43715+ if (atomic_read_unchecked(&lis3->count))
43716 return POLLIN | POLLRDNORM;
43717 return 0;
43718 }
43719diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43720index c439c82..1f20f57 100644
43721--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43722+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43723@@ -297,7 +297,7 @@ struct lis3lv02d {
43724 struct input_polled_dev *idev; /* input device */
43725 struct platform_device *pdev; /* platform device */
43726 struct regulator_bulk_data regulators[2];
43727- atomic_t count; /* interrupt count after last read */
43728+ atomic_unchecked_t count; /* interrupt count after last read */
43729 union axis_conversion ac; /* hw -> logical axis */
43730 int mapped_btns[3];
43731
43732diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43733index 2f30bad..c4c13d0 100644
43734--- a/drivers/misc/sgi-gru/gruhandles.c
43735+++ b/drivers/misc/sgi-gru/gruhandles.c
43736@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43737 unsigned long nsec;
43738
43739 nsec = CLKS2NSEC(clks);
43740- atomic_long_inc(&mcs_op_statistics[op].count);
43741- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43742+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43743+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43744 if (mcs_op_statistics[op].max < nsec)
43745 mcs_op_statistics[op].max = nsec;
43746 }
43747diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43748index 797d796..ae8f01e 100644
43749--- a/drivers/misc/sgi-gru/gruprocfs.c
43750+++ b/drivers/misc/sgi-gru/gruprocfs.c
43751@@ -32,9 +32,9 @@
43752
43753 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43754
43755-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43756+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43757 {
43758- unsigned long val = atomic_long_read(v);
43759+ unsigned long val = atomic_long_read_unchecked(v);
43760
43761 seq_printf(s, "%16lu %s\n", val, id);
43762 }
43763@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43764
43765 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43766 for (op = 0; op < mcsop_last; op++) {
43767- count = atomic_long_read(&mcs_op_statistics[op].count);
43768- total = atomic_long_read(&mcs_op_statistics[op].total);
43769+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43770+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43771 max = mcs_op_statistics[op].max;
43772 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43773 count ? total / count : 0, max);
43774diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43775index 5c3ce24..4915ccb 100644
43776--- a/drivers/misc/sgi-gru/grutables.h
43777+++ b/drivers/misc/sgi-gru/grutables.h
43778@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43779 * GRU statistics.
43780 */
43781 struct gru_stats_s {
43782- atomic_long_t vdata_alloc;
43783- atomic_long_t vdata_free;
43784- atomic_long_t gts_alloc;
43785- atomic_long_t gts_free;
43786- atomic_long_t gms_alloc;
43787- atomic_long_t gms_free;
43788- atomic_long_t gts_double_allocate;
43789- atomic_long_t assign_context;
43790- atomic_long_t assign_context_failed;
43791- atomic_long_t free_context;
43792- atomic_long_t load_user_context;
43793- atomic_long_t load_kernel_context;
43794- atomic_long_t lock_kernel_context;
43795- atomic_long_t unlock_kernel_context;
43796- atomic_long_t steal_user_context;
43797- atomic_long_t steal_kernel_context;
43798- atomic_long_t steal_context_failed;
43799- atomic_long_t nopfn;
43800- atomic_long_t asid_new;
43801- atomic_long_t asid_next;
43802- atomic_long_t asid_wrap;
43803- atomic_long_t asid_reuse;
43804- atomic_long_t intr;
43805- atomic_long_t intr_cbr;
43806- atomic_long_t intr_tfh;
43807- atomic_long_t intr_spurious;
43808- atomic_long_t intr_mm_lock_failed;
43809- atomic_long_t call_os;
43810- atomic_long_t call_os_wait_queue;
43811- atomic_long_t user_flush_tlb;
43812- atomic_long_t user_unload_context;
43813- atomic_long_t user_exception;
43814- atomic_long_t set_context_option;
43815- atomic_long_t check_context_retarget_intr;
43816- atomic_long_t check_context_unload;
43817- atomic_long_t tlb_dropin;
43818- atomic_long_t tlb_preload_page;
43819- atomic_long_t tlb_dropin_fail_no_asid;
43820- atomic_long_t tlb_dropin_fail_upm;
43821- atomic_long_t tlb_dropin_fail_invalid;
43822- atomic_long_t tlb_dropin_fail_range_active;
43823- atomic_long_t tlb_dropin_fail_idle;
43824- atomic_long_t tlb_dropin_fail_fmm;
43825- atomic_long_t tlb_dropin_fail_no_exception;
43826- atomic_long_t tfh_stale_on_fault;
43827- atomic_long_t mmu_invalidate_range;
43828- atomic_long_t mmu_invalidate_page;
43829- atomic_long_t flush_tlb;
43830- atomic_long_t flush_tlb_gru;
43831- atomic_long_t flush_tlb_gru_tgh;
43832- atomic_long_t flush_tlb_gru_zero_asid;
43833+ atomic_long_unchecked_t vdata_alloc;
43834+ atomic_long_unchecked_t vdata_free;
43835+ atomic_long_unchecked_t gts_alloc;
43836+ atomic_long_unchecked_t gts_free;
43837+ atomic_long_unchecked_t gms_alloc;
43838+ atomic_long_unchecked_t gms_free;
43839+ atomic_long_unchecked_t gts_double_allocate;
43840+ atomic_long_unchecked_t assign_context;
43841+ atomic_long_unchecked_t assign_context_failed;
43842+ atomic_long_unchecked_t free_context;
43843+ atomic_long_unchecked_t load_user_context;
43844+ atomic_long_unchecked_t load_kernel_context;
43845+ atomic_long_unchecked_t lock_kernel_context;
43846+ atomic_long_unchecked_t unlock_kernel_context;
43847+ atomic_long_unchecked_t steal_user_context;
43848+ atomic_long_unchecked_t steal_kernel_context;
43849+ atomic_long_unchecked_t steal_context_failed;
43850+ atomic_long_unchecked_t nopfn;
43851+ atomic_long_unchecked_t asid_new;
43852+ atomic_long_unchecked_t asid_next;
43853+ atomic_long_unchecked_t asid_wrap;
43854+ atomic_long_unchecked_t asid_reuse;
43855+ atomic_long_unchecked_t intr;
43856+ atomic_long_unchecked_t intr_cbr;
43857+ atomic_long_unchecked_t intr_tfh;
43858+ atomic_long_unchecked_t intr_spurious;
43859+ atomic_long_unchecked_t intr_mm_lock_failed;
43860+ atomic_long_unchecked_t call_os;
43861+ atomic_long_unchecked_t call_os_wait_queue;
43862+ atomic_long_unchecked_t user_flush_tlb;
43863+ atomic_long_unchecked_t user_unload_context;
43864+ atomic_long_unchecked_t user_exception;
43865+ atomic_long_unchecked_t set_context_option;
43866+ atomic_long_unchecked_t check_context_retarget_intr;
43867+ atomic_long_unchecked_t check_context_unload;
43868+ atomic_long_unchecked_t tlb_dropin;
43869+ atomic_long_unchecked_t tlb_preload_page;
43870+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43871+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43872+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43873+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43874+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43875+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43876+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43877+ atomic_long_unchecked_t tfh_stale_on_fault;
43878+ atomic_long_unchecked_t mmu_invalidate_range;
43879+ atomic_long_unchecked_t mmu_invalidate_page;
43880+ atomic_long_unchecked_t flush_tlb;
43881+ atomic_long_unchecked_t flush_tlb_gru;
43882+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43883+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43884
43885- atomic_long_t copy_gpa;
43886- atomic_long_t read_gpa;
43887+ atomic_long_unchecked_t copy_gpa;
43888+ atomic_long_unchecked_t read_gpa;
43889
43890- atomic_long_t mesq_receive;
43891- atomic_long_t mesq_receive_none;
43892- atomic_long_t mesq_send;
43893- atomic_long_t mesq_send_failed;
43894- atomic_long_t mesq_noop;
43895- atomic_long_t mesq_send_unexpected_error;
43896- atomic_long_t mesq_send_lb_overflow;
43897- atomic_long_t mesq_send_qlimit_reached;
43898- atomic_long_t mesq_send_amo_nacked;
43899- atomic_long_t mesq_send_put_nacked;
43900- atomic_long_t mesq_page_overflow;
43901- atomic_long_t mesq_qf_locked;
43902- atomic_long_t mesq_qf_noop_not_full;
43903- atomic_long_t mesq_qf_switch_head_failed;
43904- atomic_long_t mesq_qf_unexpected_error;
43905- atomic_long_t mesq_noop_unexpected_error;
43906- atomic_long_t mesq_noop_lb_overflow;
43907- atomic_long_t mesq_noop_qlimit_reached;
43908- atomic_long_t mesq_noop_amo_nacked;
43909- atomic_long_t mesq_noop_put_nacked;
43910- atomic_long_t mesq_noop_page_overflow;
43911+ atomic_long_unchecked_t mesq_receive;
43912+ atomic_long_unchecked_t mesq_receive_none;
43913+ atomic_long_unchecked_t mesq_send;
43914+ atomic_long_unchecked_t mesq_send_failed;
43915+ atomic_long_unchecked_t mesq_noop;
43916+ atomic_long_unchecked_t mesq_send_unexpected_error;
43917+ atomic_long_unchecked_t mesq_send_lb_overflow;
43918+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43919+ atomic_long_unchecked_t mesq_send_amo_nacked;
43920+ atomic_long_unchecked_t mesq_send_put_nacked;
43921+ atomic_long_unchecked_t mesq_page_overflow;
43922+ atomic_long_unchecked_t mesq_qf_locked;
43923+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43924+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43925+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43926+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43927+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43928+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43929+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43930+ atomic_long_unchecked_t mesq_noop_put_nacked;
43931+ atomic_long_unchecked_t mesq_noop_page_overflow;
43932
43933 };
43934
43935@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43936 tghop_invalidate, mcsop_last};
43937
43938 struct mcs_op_statistic {
43939- atomic_long_t count;
43940- atomic_long_t total;
43941+ atomic_long_unchecked_t count;
43942+ atomic_long_unchecked_t total;
43943 unsigned long max;
43944 };
43945
43946@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43947
43948 #define STAT(id) do { \
43949 if (gru_options & OPT_STATS) \
43950- atomic_long_inc(&gru_stats.id); \
43951+ atomic_long_inc_unchecked(&gru_stats.id); \
43952 } while (0)
43953
43954 #ifdef CONFIG_SGI_GRU_DEBUG
43955diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43956index c862cd4..0d176fe 100644
43957--- a/drivers/misc/sgi-xp/xp.h
43958+++ b/drivers/misc/sgi-xp/xp.h
43959@@ -288,7 +288,7 @@ struct xpc_interface {
43960 xpc_notify_func, void *);
43961 void (*received) (short, int, void *);
43962 enum xp_retval (*partid_to_nasids) (short, void *);
43963-};
43964+} __no_const;
43965
43966 extern struct xpc_interface xpc_interface;
43967
43968diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43969index b94d5f7..7f494c5 100644
43970--- a/drivers/misc/sgi-xp/xpc.h
43971+++ b/drivers/misc/sgi-xp/xpc.h
43972@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43973 void (*received_payload) (struct xpc_channel *, void *);
43974 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43975 };
43976+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43977
43978 /* struct xpc_partition act_state values (for XPC HB) */
43979
43980@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43981 /* found in xpc_main.c */
43982 extern struct device *xpc_part;
43983 extern struct device *xpc_chan;
43984-extern struct xpc_arch_operations xpc_arch_ops;
43985+extern xpc_arch_operations_no_const xpc_arch_ops;
43986 extern int xpc_disengage_timelimit;
43987 extern int xpc_disengage_timedout;
43988 extern int xpc_activate_IRQ_rcvd;
43989diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43990index d971817..33bdca5 100644
43991--- a/drivers/misc/sgi-xp/xpc_main.c
43992+++ b/drivers/misc/sgi-xp/xpc_main.c
43993@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
43994 .notifier_call = xpc_system_die,
43995 };
43996
43997-struct xpc_arch_operations xpc_arch_ops;
43998+xpc_arch_operations_no_const xpc_arch_ops;
43999
44000 /*
44001 * Timer function to enforce the timelimit on the partition disengage.
44002@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
44003
44004 if (((die_args->trapnr == X86_TRAP_MF) ||
44005 (die_args->trapnr == X86_TRAP_XF)) &&
44006- !user_mode_vm(die_args->regs))
44007+ !user_mode(die_args->regs))
44008 xpc_die_deactivate();
44009
44010 break;
44011diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
44012index 49f04bc..65660c2 100644
44013--- a/drivers/mmc/core/mmc_ops.c
44014+++ b/drivers/mmc/core/mmc_ops.c
44015@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
44016 void *data_buf;
44017 int is_on_stack;
44018
44019- is_on_stack = object_is_on_stack(buf);
44020+ is_on_stack = object_starts_on_stack(buf);
44021 if (is_on_stack) {
44022 /*
44023 * dma onto stack is unsafe/nonportable, but callers to this
44024diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44025index 0b74189..818358f 100644
44026--- a/drivers/mmc/host/dw_mmc.h
44027+++ b/drivers/mmc/host/dw_mmc.h
44028@@ -202,5 +202,5 @@ struct dw_mci_drv_data {
44029 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
44030 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
44031 int (*parse_dt)(struct dw_mci *host);
44032-};
44033+} __do_const;
44034 #endif /* _DW_MMC_H_ */
44035diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44036index c6f6246..60760a8 100644
44037--- a/drivers/mmc/host/sdhci-s3c.c
44038+++ b/drivers/mmc/host/sdhci-s3c.c
44039@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44040 * we can use overriding functions instead of default.
44041 */
44042 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44043- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44044- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44045- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44046+ pax_open_kernel();
44047+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44048+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44049+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44050+ pax_close_kernel();
44051 }
44052
44053 /* It supports additional host capabilities if needed */
44054diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44055index 0c8bb6b..6f35deb 100644
44056--- a/drivers/mtd/nand/denali.c
44057+++ b/drivers/mtd/nand/denali.c
44058@@ -24,6 +24,7 @@
44059 #include <linux/slab.h>
44060 #include <linux/mtd/mtd.h>
44061 #include <linux/module.h>
44062+#include <linux/slab.h>
44063
44064 #include "denali.h"
44065
44066diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44067index 51b9d6a..52af9a7 100644
44068--- a/drivers/mtd/nftlmount.c
44069+++ b/drivers/mtd/nftlmount.c
44070@@ -24,6 +24,7 @@
44071 #include <asm/errno.h>
44072 #include <linux/delay.h>
44073 #include <linux/slab.h>
44074+#include <linux/sched.h>
44075 #include <linux/mtd/mtd.h>
44076 #include <linux/mtd/nand.h>
44077 #include <linux/mtd/nftl.h>
44078diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44079index f9d5615..99dd95f 100644
44080--- a/drivers/mtd/sm_ftl.c
44081+++ b/drivers/mtd/sm_ftl.c
44082@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
44083 #define SM_CIS_VENDOR_OFFSET 0x59
44084 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
44085 {
44086- struct attribute_group *attr_group;
44087+ attribute_group_no_const *attr_group;
44088 struct attribute **attributes;
44089 struct sm_sysfs_attribute *vendor_attribute;
44090
44091diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
44092index f975696..4597e21 100644
44093--- a/drivers/net/bonding/bond_main.c
44094+++ b/drivers/net/bonding/bond_main.c
44095@@ -4870,7 +4870,7 @@ static unsigned int bond_get_num_tx_queues(void)
44096 return tx_queues;
44097 }
44098
44099-static struct rtnl_link_ops bond_link_ops __read_mostly = {
44100+static struct rtnl_link_ops bond_link_ops = {
44101 .kind = "bond",
44102 .priv_size = sizeof(struct bonding),
44103 .setup = bond_setup,
44104@@ -4995,8 +4995,8 @@ static void __exit bonding_exit(void)
44105
44106 bond_destroy_debugfs();
44107
44108- rtnl_link_unregister(&bond_link_ops);
44109 unregister_pernet_subsys(&bond_net_ops);
44110+ rtnl_link_unregister(&bond_link_ops);
44111
44112 #ifdef CONFIG_NET_POLL_CONTROLLER
44113 /*
44114diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
44115index e1d2643..7f4133b 100644
44116--- a/drivers/net/ethernet/8390/ax88796.c
44117+++ b/drivers/net/ethernet/8390/ax88796.c
44118@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
44119 if (ax->plat->reg_offsets)
44120 ei_local->reg_offset = ax->plat->reg_offsets;
44121 else {
44122+ resource_size_t _mem_size = mem_size;
44123+ do_div(_mem_size, 0x18);
44124 ei_local->reg_offset = ax->reg_offsets;
44125 for (ret = 0; ret < 0x18; ret++)
44126- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
44127+ ax->reg_offsets[ret] = _mem_size * ret;
44128 }
44129
44130 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
44131diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44132index 151675d..0139a9d 100644
44133--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44134+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44135@@ -1112,7 +1112,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
44136 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
44137 {
44138 /* RX_MODE controlling object */
44139- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
44140+ bnx2x_init_rx_mode_obj(bp);
44141
44142 /* multicast configuration controlling object */
44143 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
44144diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
44145index ce1a916..10b52b0 100644
44146--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
44147+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
44148@@ -960,6 +960,9 @@ static int bnx2x_set_dump(struct net_device *dev, struct ethtool_dump *val)
44149 struct bnx2x *bp = netdev_priv(dev);
44150
44151 /* Use the ethtool_dump "flag" field as the dump preset index */
44152+ if (val->flag < 1 || val->flag > DUMP_MAX_PRESETS)
44153+ return -EINVAL;
44154+
44155 bp->dump_preset_idx = val->flag;
44156 return 0;
44157 }
44158@@ -986,8 +989,6 @@ static int bnx2x_get_dump_data(struct net_device *dev,
44159 struct bnx2x *bp = netdev_priv(dev);
44160 struct dump_header dump_hdr = {0};
44161
44162- memset(p, 0, dump->len);
44163-
44164 /* Disable parity attentions as long as following dump may
44165 * cause false alarms by reading never written registers. We
44166 * will re-enable parity attentions right after the dump.
44167diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
44168index b4c9dea..2a9927f 100644
44169--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
44170+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
44171@@ -11497,6 +11497,8 @@ static int bnx2x_init_bp(struct bnx2x *bp)
44172 bp->min_msix_vec_cnt = 2;
44173 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
44174
44175+ bp->dump_preset_idx = 1;
44176+
44177 return rc;
44178 }
44179
44180diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44181index 32a9609..0b1c53a 100644
44182--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44183+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44184@@ -2387,15 +2387,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
44185 return rc;
44186 }
44187
44188-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44189- struct bnx2x_rx_mode_obj *o)
44190+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
44191 {
44192 if (CHIP_IS_E1x(bp)) {
44193- o->wait_comp = bnx2x_empty_rx_mode_wait;
44194- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
44195+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
44196+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
44197 } else {
44198- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
44199- o->config_rx_mode = bnx2x_set_rx_mode_e2;
44200+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
44201+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
44202 }
44203 }
44204
44205diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44206index 43c00bc..dd1d03d 100644
44207--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44208+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44209@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
44210
44211 /********************* RX MODE ****************/
44212
44213-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44214- struct bnx2x_rx_mode_obj *o);
44215+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
44216
44217 /**
44218 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
44219diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
44220index ff6e30e..87e8452 100644
44221--- a/drivers/net/ethernet/broadcom/tg3.h
44222+++ b/drivers/net/ethernet/broadcom/tg3.h
44223@@ -147,6 +147,7 @@
44224 #define CHIPREV_ID_5750_A0 0x4000
44225 #define CHIPREV_ID_5750_A1 0x4001
44226 #define CHIPREV_ID_5750_A3 0x4003
44227+#define CHIPREV_ID_5750_C1 0x4201
44228 #define CHIPREV_ID_5750_C2 0x4202
44229 #define CHIPREV_ID_5752_A0_HW 0x5000
44230 #define CHIPREV_ID_5752_A0 0x6000
44231diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
44232index 71497e8..b650951 100644
44233--- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
44234+++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
44235@@ -3037,7 +3037,9 @@ static void t3_io_resume(struct pci_dev *pdev)
44236 CH_ALERT(adapter, "adapter recovering, PEX ERR 0x%x\n",
44237 t3_read_reg(adapter, A_PCIE_PEX_ERR));
44238
44239+ rtnl_lock();
44240 t3_resume_ports(adapter);
44241+ rtnl_unlock();
44242 }
44243
44244 static const struct pci_error_handlers t3_err_handler = {
44245diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44246index 8cffcdf..aadf043 100644
44247--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44248+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44249@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
44250 */
44251 struct l2t_skb_cb {
44252 arp_failure_handler_func arp_failure_handler;
44253-};
44254+} __no_const;
44255
44256 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
44257
44258diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
44259index 4c83003..2a2a5b9 100644
44260--- a/drivers/net/ethernet/dec/tulip/de4x5.c
44261+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
44262@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44263 for (i=0; i<ETH_ALEN; i++) {
44264 tmp.addr[i] = dev->dev_addr[i];
44265 }
44266- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44267+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44268 break;
44269
44270 case DE4X5_SET_HWADDR: /* Set the hardware address */
44271@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44272 spin_lock_irqsave(&lp->lock, flags);
44273 memcpy(&statbuf, &lp->pktStats, ioc->len);
44274 spin_unlock_irqrestore(&lp->lock, flags);
44275- if (copy_to_user(ioc->data, &statbuf, ioc->len))
44276+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
44277 return -EFAULT;
44278 break;
44279 }
44280diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44281index 6e43426..1bd8365 100644
44282--- a/drivers/net/ethernet/emulex/benet/be_main.c
44283+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44284@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44285
44286 if (wrapped)
44287 newacc += 65536;
44288- ACCESS_ONCE(*acc) = newacc;
44289+ ACCESS_ONCE_RW(*acc) = newacc;
44290 }
44291
44292 void populate_erx_stats(struct be_adapter *adapter,
44293diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44294index 21b85fb..b49e5fc 100644
44295--- a/drivers/net/ethernet/faraday/ftgmac100.c
44296+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44297@@ -31,6 +31,8 @@
44298 #include <linux/netdevice.h>
44299 #include <linux/phy.h>
44300 #include <linux/platform_device.h>
44301+#include <linux/interrupt.h>
44302+#include <linux/irqreturn.h>
44303 #include <net/ip.h>
44304
44305 #include "ftgmac100.h"
44306diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
44307index a6eda8d..935d273 100644
44308--- a/drivers/net/ethernet/faraday/ftmac100.c
44309+++ b/drivers/net/ethernet/faraday/ftmac100.c
44310@@ -31,6 +31,8 @@
44311 #include <linux/module.h>
44312 #include <linux/netdevice.h>
44313 #include <linux/platform_device.h>
44314+#include <linux/interrupt.h>
44315+#include <linux/irqreturn.h>
44316
44317 #include "ftmac100.h"
44318
44319diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44320index 331987d..3be1135 100644
44321--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44322+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44323@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44324 }
44325
44326 /* update the base incval used to calculate frequency adjustment */
44327- ACCESS_ONCE(adapter->base_incval) = incval;
44328+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44329 smp_mb();
44330
44331 /* need lock to prevent incorrect read while modifying cyclecounter */
44332diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44333index fbe5363..266b4e3 100644
44334--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44335+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44336@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44337 struct __vxge_hw_fifo *fifo;
44338 struct vxge_hw_fifo_config *config;
44339 u32 txdl_size, txdl_per_memblock;
44340- struct vxge_hw_mempool_cbs fifo_mp_callback;
44341+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44342+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44343+ };
44344+
44345 struct __vxge_hw_virtualpath *vpath;
44346
44347 if ((vp == NULL) || (attr == NULL)) {
44348@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44349 goto exit;
44350 }
44351
44352- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44353-
44354 fifo->mempool =
44355 __vxge_hw_mempool_create(vpath->hldev,
44356 fifo->config->memblock_size,
44357diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44358index 5e7fb1d..f8d1810 100644
44359--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44360+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44361@@ -1948,7 +1948,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
44362 op_mode = QLC_83XX_DEFAULT_OPMODE;
44363
44364 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
44365- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44366+ pax_open_kernel();
44367+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44368+ pax_close_kernel();
44369 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44370 } else {
44371 return -EIO;
44372diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44373index b0c3de9..fc5857e 100644
44374--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44375+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44376@@ -200,15 +200,21 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44377 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
44378 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44379 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44380- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44381+ pax_open_kernel();
44382+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44383+ pax_close_kernel();
44384 } else if (priv_level == QLCNIC_PRIV_FUNC) {
44385 ahw->op_mode = QLCNIC_PRIV_FUNC;
44386 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44387- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44388+ pax_open_kernel();
44389+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44390+ pax_close_kernel();
44391 } else if (priv_level == QLCNIC_MGMT_FUNC) {
44392 ahw->op_mode = QLCNIC_MGMT_FUNC;
44393 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44394- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44395+ pax_open_kernel();
44396+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44397+ pax_close_kernel();
44398 } else {
44399 return -EIO;
44400 }
44401diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
44402index 6acf82b..14b097e 100644
44403--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
44404+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
44405@@ -206,10 +206,10 @@ int qlcnic_fw_cmd_set_drv_version(struct qlcnic_adapter *adapter)
44406 if (err) {
44407 dev_info(&adapter->pdev->dev,
44408 "Failed to set driver version in firmware\n");
44409- return -EIO;
44410+ err = -EIO;
44411 }
44412-
44413- return 0;
44414+ qlcnic_free_mbx_args(&cmd);
44415+ return err;
44416 }
44417
44418 int
44419diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
44420index d3f8797..82a03d3 100644
44421--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
44422+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
44423@@ -262,7 +262,7 @@ void qlcnic_82xx_change_filter(struct qlcnic_adapter *adapter, u64 *uaddr,
44424
44425 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
44426 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
44427- memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN);
44428+ memcpy(mac_req->mac_addr, uaddr, ETH_ALEN);
44429
44430 vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
44431 vlan_req->vlan_id = cpu_to_le16(vlan_id);
44432diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/realtek/8139cp.c
44433index 887aebe..9095ff9 100644
44434--- a/drivers/net/ethernet/realtek/8139cp.c
44435+++ b/drivers/net/ethernet/realtek/8139cp.c
44436@@ -524,6 +524,7 @@ rx_status_loop:
44437 PCI_DMA_FROMDEVICE);
44438 if (dma_mapping_error(&cp->pdev->dev, new_mapping)) {
44439 dev->stats.rx_dropped++;
44440+ kfree_skb(new_skb);
44441 goto rx_next;
44442 }
44443
44444diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44445index 393f961..d343034 100644
44446--- a/drivers/net/ethernet/realtek/r8169.c
44447+++ b/drivers/net/ethernet/realtek/r8169.c
44448@@ -753,22 +753,22 @@ struct rtl8169_private {
44449 struct mdio_ops {
44450 void (*write)(struct rtl8169_private *, int, int);
44451 int (*read)(struct rtl8169_private *, int);
44452- } mdio_ops;
44453+ } __no_const mdio_ops;
44454
44455 struct pll_power_ops {
44456 void (*down)(struct rtl8169_private *);
44457 void (*up)(struct rtl8169_private *);
44458- } pll_power_ops;
44459+ } __no_const pll_power_ops;
44460
44461 struct jumbo_ops {
44462 void (*enable)(struct rtl8169_private *);
44463 void (*disable)(struct rtl8169_private *);
44464- } jumbo_ops;
44465+ } __no_const jumbo_ops;
44466
44467 struct csi_ops {
44468 void (*write)(struct rtl8169_private *, int, int);
44469 u32 (*read)(struct rtl8169_private *, int);
44470- } csi_ops;
44471+ } __no_const csi_ops;
44472
44473 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44474 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44475diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44476index 9a95abf..36df7f9 100644
44477--- a/drivers/net/ethernet/sfc/ptp.c
44478+++ b/drivers/net/ethernet/sfc/ptp.c
44479@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44480 (u32)((u64)ptp->start.dma_addr >> 32));
44481
44482 /* Clear flag that signals MC ready */
44483- ACCESS_ONCE(*start) = 0;
44484+ ACCESS_ONCE_RW(*start) = 0;
44485 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44486 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44487
44488diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44489index 50617c5..b13724c 100644
44490--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44491+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44492@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44493
44494 writel(value, ioaddr + MMC_CNTRL);
44495
44496- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44497- MMC_CNTRL, value);
44498+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44499+// MMC_CNTRL, value);
44500 }
44501
44502 /* To mask all all interrupts.*/
44503diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44504index e6fe0d8..2b7d752 100644
44505--- a/drivers/net/hyperv/hyperv_net.h
44506+++ b/drivers/net/hyperv/hyperv_net.h
44507@@ -101,7 +101,7 @@ struct rndis_device {
44508
44509 enum rndis_device_state state;
44510 bool link_state;
44511- atomic_t new_req_id;
44512+ atomic_unchecked_t new_req_id;
44513
44514 spinlock_t request_lock;
44515 struct list_head req_list;
44516diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44517index 0775f0a..d4fb316 100644
44518--- a/drivers/net/hyperv/rndis_filter.c
44519+++ b/drivers/net/hyperv/rndis_filter.c
44520@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44521 * template
44522 */
44523 set = &rndis_msg->msg.set_req;
44524- set->req_id = atomic_inc_return(&dev->new_req_id);
44525+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44526
44527 /* Add to the request list */
44528 spin_lock_irqsave(&dev->request_lock, flags);
44529@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44530
44531 /* Setup the rndis set */
44532 halt = &request->request_msg.msg.halt_req;
44533- halt->req_id = atomic_inc_return(&dev->new_req_id);
44534+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44535
44536 /* Ignore return since this msg is optional. */
44537 rndis_filter_send_request(dev, request);
44538diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44539index bf0d55e..82bcfbd1 100644
44540--- a/drivers/net/ieee802154/fakehard.c
44541+++ b/drivers/net/ieee802154/fakehard.c
44542@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44543 phy->transmit_power = 0xbf;
44544
44545 dev->netdev_ops = &fake_ops;
44546- dev->ml_priv = &fake_mlme;
44547+ dev->ml_priv = (void *)&fake_mlme;
44548
44549 priv = netdev_priv(dev);
44550 priv->phy = phy;
44551diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44552index 6e91931..2b0ebe7 100644
44553--- a/drivers/net/macvlan.c
44554+++ b/drivers/net/macvlan.c
44555@@ -905,13 +905,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44556 int macvlan_link_register(struct rtnl_link_ops *ops)
44557 {
44558 /* common fields */
44559- ops->priv_size = sizeof(struct macvlan_dev);
44560- ops->validate = macvlan_validate;
44561- ops->maxtype = IFLA_MACVLAN_MAX;
44562- ops->policy = macvlan_policy;
44563- ops->changelink = macvlan_changelink;
44564- ops->get_size = macvlan_get_size;
44565- ops->fill_info = macvlan_fill_info;
44566+ pax_open_kernel();
44567+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44568+ *(void **)&ops->validate = macvlan_validate;
44569+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44570+ *(const void **)&ops->policy = macvlan_policy;
44571+ *(void **)&ops->changelink = macvlan_changelink;
44572+ *(void **)&ops->get_size = macvlan_get_size;
44573+ *(void **)&ops->fill_info = macvlan_fill_info;
44574+ pax_close_kernel();
44575
44576 return rtnl_link_register(ops);
44577 };
44578@@ -967,7 +969,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44579 return NOTIFY_DONE;
44580 }
44581
44582-static struct notifier_block macvlan_notifier_block __read_mostly = {
44583+static struct notifier_block macvlan_notifier_block = {
44584 .notifier_call = macvlan_device_event,
44585 };
44586
44587diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44588index 523d6b2..5e16aa1 100644
44589--- a/drivers/net/macvtap.c
44590+++ b/drivers/net/macvtap.c
44591@@ -1110,7 +1110,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44592 return NOTIFY_DONE;
44593 }
44594
44595-static struct notifier_block macvtap_notifier_block __read_mostly = {
44596+static struct notifier_block macvtap_notifier_block = {
44597 .notifier_call = macvtap_device_event,
44598 };
44599
44600diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44601index daec9b0..6428fcb 100644
44602--- a/drivers/net/phy/mdio-bitbang.c
44603+++ b/drivers/net/phy/mdio-bitbang.c
44604@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44605 struct mdiobb_ctrl *ctrl = bus->priv;
44606
44607 module_put(ctrl->ops->owner);
44608+ mdiobus_unregister(bus);
44609 mdiobus_free(bus);
44610 }
44611 EXPORT_SYMBOL(free_mdio_bitbang);
44612diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44613index 72ff14b..11d442d 100644
44614--- a/drivers/net/ppp/ppp_generic.c
44615+++ b/drivers/net/ppp/ppp_generic.c
44616@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44617 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44618 struct ppp_stats stats;
44619 struct ppp_comp_stats cstats;
44620- char *vers;
44621
44622 switch (cmd) {
44623 case SIOCGPPPSTATS:
44624@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44625 break;
44626
44627 case SIOCGPPPVER:
44628- vers = PPP_VERSION;
44629- if (copy_to_user(addr, vers, strlen(vers) + 1))
44630+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44631 break;
44632 err = 0;
44633 break;
44634diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44635index 1252d9c..80e660b 100644
44636--- a/drivers/net/slip/slhc.c
44637+++ b/drivers/net/slip/slhc.c
44638@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44639 register struct tcphdr *thp;
44640 register struct iphdr *ip;
44641 register struct cstate *cs;
44642- int len, hdrlen;
44643+ long len, hdrlen;
44644 unsigned char *cp = icp;
44645
44646 /* We've got a compressed packet; read the change byte */
44647diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44648index b305105..8ead6df 100644
44649--- a/drivers/net/team/team.c
44650+++ b/drivers/net/team/team.c
44651@@ -2682,7 +2682,7 @@ static int team_device_event(struct notifier_block *unused,
44652 return NOTIFY_DONE;
44653 }
44654
44655-static struct notifier_block team_notifier_block __read_mostly = {
44656+static struct notifier_block team_notifier_block = {
44657 .notifier_call = team_device_event,
44658 };
44659
44660diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44661index 2491eb2..1a453eb 100644
44662--- a/drivers/net/tun.c
44663+++ b/drivers/net/tun.c
44664@@ -1076,8 +1076,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
44665 u32 rxhash;
44666
44667 if (!(tun->flags & TUN_NO_PI)) {
44668- if ((len -= sizeof(pi)) > total_len)
44669+ if (len < sizeof(pi))
44670 return -EINVAL;
44671+ len -= sizeof(pi);
44672
44673 if (memcpy_fromiovecend((void *)&pi, iv, 0, sizeof(pi)))
44674 return -EFAULT;
44675@@ -1085,8 +1086,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
44676 }
44677
44678 if (tun->flags & TUN_VNET_HDR) {
44679- if ((len -= tun->vnet_hdr_sz) > total_len)
44680+ if (len < tun->vnet_hdr_sz)
44681 return -EINVAL;
44682+ len -= tun->vnet_hdr_sz;
44683
44684 if (memcpy_fromiovecend((void *)&gso, iv, offset, sizeof(gso)))
44685 return -EFAULT;
44686@@ -1869,7 +1871,7 @@ unlock:
44687 }
44688
44689 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44690- unsigned long arg, int ifreq_len)
44691+ unsigned long arg, size_t ifreq_len)
44692 {
44693 struct tun_file *tfile = file->private_data;
44694 struct tun_struct *tun;
44695@@ -1881,6 +1883,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44696 int vnet_hdr_sz;
44697 int ret;
44698
44699+ if (ifreq_len > sizeof ifr)
44700+ return -EFAULT;
44701+
44702 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44703 if (copy_from_user(&ifr, argp, ifreq_len))
44704 return -EFAULT;
44705diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44706index cba1d46..f703766 100644
44707--- a/drivers/net/usb/hso.c
44708+++ b/drivers/net/usb/hso.c
44709@@ -71,7 +71,7 @@
44710 #include <asm/byteorder.h>
44711 #include <linux/serial_core.h>
44712 #include <linux/serial.h>
44713-
44714+#include <asm/local.h>
44715
44716 #define MOD_AUTHOR "Option Wireless"
44717 #define MOD_DESCRIPTION "USB High Speed Option driver"
44718@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44719 struct urb *urb;
44720
44721 urb = serial->rx_urb[0];
44722- if (serial->port.count > 0) {
44723+ if (atomic_read(&serial->port.count) > 0) {
44724 count = put_rxbuf_data(urb, serial);
44725 if (count == -1)
44726 return;
44727@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44728 DUMP1(urb->transfer_buffer, urb->actual_length);
44729
44730 /* Anyone listening? */
44731- if (serial->port.count == 0)
44732+ if (atomic_read(&serial->port.count) == 0)
44733 return;
44734
44735 if (status == 0) {
44736@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44737 tty_port_tty_set(&serial->port, tty);
44738
44739 /* check for port already opened, if not set the termios */
44740- serial->port.count++;
44741- if (serial->port.count == 1) {
44742+ if (atomic_inc_return(&serial->port.count) == 1) {
44743 serial->rx_state = RX_IDLE;
44744 /* Force default termio settings */
44745 _hso_serial_set_termios(tty, NULL);
44746@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44747 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44748 if (result) {
44749 hso_stop_serial_device(serial->parent);
44750- serial->port.count--;
44751+ atomic_dec(&serial->port.count);
44752 kref_put(&serial->parent->ref, hso_serial_ref_free);
44753 }
44754 } else {
44755@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44756
44757 /* reset the rts and dtr */
44758 /* do the actual close */
44759- serial->port.count--;
44760+ atomic_dec(&serial->port.count);
44761
44762- if (serial->port.count <= 0) {
44763- serial->port.count = 0;
44764+ if (atomic_read(&serial->port.count) <= 0) {
44765+ atomic_set(&serial->port.count, 0);
44766 tty_port_tty_set(&serial->port, NULL);
44767 if (!usb_gone)
44768 hso_stop_serial_device(serial->parent);
44769@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44770
44771 /* the actual setup */
44772 spin_lock_irqsave(&serial->serial_lock, flags);
44773- if (serial->port.count)
44774+ if (atomic_read(&serial->port.count))
44775 _hso_serial_set_termios(tty, old);
44776 else
44777 tty->termios = *old;
44778@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44779 D1("Pending read interrupt on port %d\n", i);
44780 spin_lock(&serial->serial_lock);
44781 if (serial->rx_state == RX_IDLE &&
44782- serial->port.count > 0) {
44783+ atomic_read(&serial->port.count) > 0) {
44784 /* Setup and send a ctrl req read on
44785 * port i */
44786 if (!serial->rx_urb_filled[0]) {
44787@@ -3057,7 +3056,7 @@ static int hso_resume(struct usb_interface *iface)
44788 /* Start all serial ports */
44789 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44790 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44791- if (dev2ser(serial_table[i])->port.count) {
44792+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44793 result =
44794 hso_start_serial_device(serial_table[i], GFP_NOIO);
44795 hso_kick_transmit(dev2ser(serial_table[i]));
44796diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44797index a79e9d3..78cd4fa 100644
44798--- a/drivers/net/usb/sierra_net.c
44799+++ b/drivers/net/usb/sierra_net.c
44800@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44801 /* atomic counter partially included in MAC address to make sure 2 devices
44802 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44803 */
44804-static atomic_t iface_counter = ATOMIC_INIT(0);
44805+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44806
44807 /*
44808 * SYNC Timer Delay definition used to set the expiry time
44809@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44810 dev->net->netdev_ops = &sierra_net_device_ops;
44811
44812 /* change MAC addr to include, ifacenum, and to be unique */
44813- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44814+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44815 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44816
44817 /* we will have to manufacture ethernet headers, prepare template */
44818diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44819index 57325f3..36b181f 100644
44820--- a/drivers/net/vxlan.c
44821+++ b/drivers/net/vxlan.c
44822@@ -1579,7 +1579,7 @@ nla_put_failure:
44823 return -EMSGSIZE;
44824 }
44825
44826-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44827+static struct rtnl_link_ops vxlan_link_ops = {
44828 .kind = "vxlan",
44829 .maxtype = IFLA_VXLAN_MAX,
44830 .policy = vxlan_policy,
44831diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44832index 34c8a33..3261fdc 100644
44833--- a/drivers/net/wireless/at76c50x-usb.c
44834+++ b/drivers/net/wireless/at76c50x-usb.c
44835@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44836 }
44837
44838 /* Convert timeout from the DFU status to jiffies */
44839-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44840+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44841 {
44842 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44843 | (s->poll_timeout[1] << 8)
44844diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44845index 8d78253..bebbb68 100644
44846--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44847+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44848@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44849 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44850 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44851
44852- ACCESS_ONCE(ads->ds_link) = i->link;
44853- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44854+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44855+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44856
44857 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44858 ctl6 = SM(i->keytype, AR_EncrType);
44859@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44860
44861 if ((i->is_first || i->is_last) &&
44862 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44863- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44864+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44865 | set11nTries(i->rates, 1)
44866 | set11nTries(i->rates, 2)
44867 | set11nTries(i->rates, 3)
44868 | (i->dur_update ? AR_DurUpdateEna : 0)
44869 | SM(0, AR_BurstDur);
44870
44871- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44872+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44873 | set11nRate(i->rates, 1)
44874 | set11nRate(i->rates, 2)
44875 | set11nRate(i->rates, 3);
44876 } else {
44877- ACCESS_ONCE(ads->ds_ctl2) = 0;
44878- ACCESS_ONCE(ads->ds_ctl3) = 0;
44879+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44880+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44881 }
44882
44883 if (!i->is_first) {
44884- ACCESS_ONCE(ads->ds_ctl0) = 0;
44885- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44886- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44887+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44888+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44889+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44890 return;
44891 }
44892
44893@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44894 break;
44895 }
44896
44897- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44898+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44899 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44900 | SM(i->txpower, AR_XmitPower)
44901 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44902@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44903 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44904 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44905
44906- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44907- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44908+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44909+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44910
44911 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44912 return;
44913
44914- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44915+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44916 | set11nPktDurRTSCTS(i->rates, 1);
44917
44918- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44919+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44920 | set11nPktDurRTSCTS(i->rates, 3);
44921
44922- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44923+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44924 | set11nRateFlags(i->rates, 1)
44925 | set11nRateFlags(i->rates, 2)
44926 | set11nRateFlags(i->rates, 3)
44927diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44928index 301bf72..3f5654f 100644
44929--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44930+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44931@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44932 (i->qcu << AR_TxQcuNum_S) | desc_len;
44933
44934 checksum += val;
44935- ACCESS_ONCE(ads->info) = val;
44936+ ACCESS_ONCE_RW(ads->info) = val;
44937
44938 checksum += i->link;
44939- ACCESS_ONCE(ads->link) = i->link;
44940+ ACCESS_ONCE_RW(ads->link) = i->link;
44941
44942 checksum += i->buf_addr[0];
44943- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44944+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44945 checksum += i->buf_addr[1];
44946- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44947+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44948 checksum += i->buf_addr[2];
44949- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44950+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44951 checksum += i->buf_addr[3];
44952- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44953+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44954
44955 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44956- ACCESS_ONCE(ads->ctl3) = val;
44957+ ACCESS_ONCE_RW(ads->ctl3) = val;
44958 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44959- ACCESS_ONCE(ads->ctl5) = val;
44960+ ACCESS_ONCE_RW(ads->ctl5) = val;
44961 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44962- ACCESS_ONCE(ads->ctl7) = val;
44963+ ACCESS_ONCE_RW(ads->ctl7) = val;
44964 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44965- ACCESS_ONCE(ads->ctl9) = val;
44966+ ACCESS_ONCE_RW(ads->ctl9) = val;
44967
44968 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44969- ACCESS_ONCE(ads->ctl10) = checksum;
44970+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44971
44972 if (i->is_first || i->is_last) {
44973- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44974+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44975 | set11nTries(i->rates, 1)
44976 | set11nTries(i->rates, 2)
44977 | set11nTries(i->rates, 3)
44978 | (i->dur_update ? AR_DurUpdateEna : 0)
44979 | SM(0, AR_BurstDur);
44980
44981- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44982+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44983 | set11nRate(i->rates, 1)
44984 | set11nRate(i->rates, 2)
44985 | set11nRate(i->rates, 3);
44986 } else {
44987- ACCESS_ONCE(ads->ctl13) = 0;
44988- ACCESS_ONCE(ads->ctl14) = 0;
44989+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44990+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44991 }
44992
44993 ads->ctl20 = 0;
44994@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44995
44996 ctl17 = SM(i->keytype, AR_EncrType);
44997 if (!i->is_first) {
44998- ACCESS_ONCE(ads->ctl11) = 0;
44999- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45000- ACCESS_ONCE(ads->ctl15) = 0;
45001- ACCESS_ONCE(ads->ctl16) = 0;
45002- ACCESS_ONCE(ads->ctl17) = ctl17;
45003- ACCESS_ONCE(ads->ctl18) = 0;
45004- ACCESS_ONCE(ads->ctl19) = 0;
45005+ ACCESS_ONCE_RW(ads->ctl11) = 0;
45006+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45007+ ACCESS_ONCE_RW(ads->ctl15) = 0;
45008+ ACCESS_ONCE_RW(ads->ctl16) = 0;
45009+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45010+ ACCESS_ONCE_RW(ads->ctl18) = 0;
45011+ ACCESS_ONCE_RW(ads->ctl19) = 0;
45012 return;
45013 }
45014
45015- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45016+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45017 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45018 | SM(i->txpower, AR_XmitPower)
45019 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45020@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45021 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
45022 ctl12 |= SM(val, AR_PAPRDChainMask);
45023
45024- ACCESS_ONCE(ads->ctl12) = ctl12;
45025- ACCESS_ONCE(ads->ctl17) = ctl17;
45026+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
45027+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45028
45029- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45030+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45031 | set11nPktDurRTSCTS(i->rates, 1);
45032
45033- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45034+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45035 | set11nPktDurRTSCTS(i->rates, 3);
45036
45037- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
45038+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
45039 | set11nRateFlags(i->rates, 1)
45040 | set11nRateFlags(i->rates, 2)
45041 | set11nRateFlags(i->rates, 3)
45042 | SM(i->rtscts_rate, AR_RTSCTSRate);
45043
45044- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
45045+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
45046 }
45047
45048 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
45049diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
45050index ae30343..a117806 100644
45051--- a/drivers/net/wireless/ath/ath9k/hw.h
45052+++ b/drivers/net/wireless/ath/ath9k/hw.h
45053@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
45054
45055 /* ANI */
45056 void (*ani_cache_ini_regs)(struct ath_hw *ah);
45057-};
45058+} __no_const;
45059
45060 /**
45061 * struct ath_spec_scan - parameters for Atheros spectral scan
45062@@ -721,7 +721,7 @@ struct ath_hw_ops {
45063 struct ath_spec_scan *param);
45064 void (*spectral_scan_trigger)(struct ath_hw *ah);
45065 void (*spectral_scan_wait)(struct ath_hw *ah);
45066-};
45067+} __no_const;
45068
45069 struct ath_nf_limits {
45070 s16 max;
45071diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
45072index b37a582..680835d 100644
45073--- a/drivers/net/wireless/iwlegacy/3945-mac.c
45074+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
45075@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
45076 */
45077 if (il3945_mod_params.disable_hw_scan) {
45078 D_INFO("Disabling hw_scan\n");
45079- il3945_mac_ops.hw_scan = NULL;
45080+ pax_open_kernel();
45081+ *(void **)&il3945_mac_ops.hw_scan = NULL;
45082+ pax_close_kernel();
45083 }
45084
45085 D_INFO("*** LOAD DRIVER ***\n");
45086diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45087index d532948..e0d8bb1 100644
45088--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45089+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45090@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
45091 {
45092 struct iwl_priv *priv = file->private_data;
45093 char buf[64];
45094- int buf_size;
45095+ size_t buf_size;
45096 u32 offset, len;
45097
45098 memset(buf, 0, sizeof(buf));
45099@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
45100 struct iwl_priv *priv = file->private_data;
45101
45102 char buf[8];
45103- int buf_size;
45104+ size_t buf_size;
45105 u32 reset_flag;
45106
45107 memset(buf, 0, sizeof(buf));
45108@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
45109 {
45110 struct iwl_priv *priv = file->private_data;
45111 char buf[8];
45112- int buf_size;
45113+ size_t buf_size;
45114 int ht40;
45115
45116 memset(buf, 0, sizeof(buf));
45117@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
45118 {
45119 struct iwl_priv *priv = file->private_data;
45120 char buf[8];
45121- int buf_size;
45122+ size_t buf_size;
45123 int value;
45124
45125 memset(buf, 0, sizeof(buf));
45126@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
45127 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
45128 DEBUGFS_READ_FILE_OPS(current_sleep_command);
45129
45130-static const char *fmt_value = " %-30s %10u\n";
45131-static const char *fmt_hex = " %-30s 0x%02X\n";
45132-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
45133-static const char *fmt_header =
45134+static const char fmt_value[] = " %-30s %10u\n";
45135+static const char fmt_hex[] = " %-30s 0x%02X\n";
45136+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
45137+static const char fmt_header[] =
45138 "%-32s current cumulative delta max\n";
45139
45140 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
45141@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
45142 {
45143 struct iwl_priv *priv = file->private_data;
45144 char buf[8];
45145- int buf_size;
45146+ size_t buf_size;
45147 int clear;
45148
45149 memset(buf, 0, sizeof(buf));
45150@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
45151 {
45152 struct iwl_priv *priv = file->private_data;
45153 char buf[8];
45154- int buf_size;
45155+ size_t buf_size;
45156 int trace;
45157
45158 memset(buf, 0, sizeof(buf));
45159@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
45160 {
45161 struct iwl_priv *priv = file->private_data;
45162 char buf[8];
45163- int buf_size;
45164+ size_t buf_size;
45165 int missed;
45166
45167 memset(buf, 0, sizeof(buf));
45168@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
45169
45170 struct iwl_priv *priv = file->private_data;
45171 char buf[8];
45172- int buf_size;
45173+ size_t buf_size;
45174 int plcp;
45175
45176 memset(buf, 0, sizeof(buf));
45177@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
45178
45179 struct iwl_priv *priv = file->private_data;
45180 char buf[8];
45181- int buf_size;
45182+ size_t buf_size;
45183 int flush;
45184
45185 memset(buf, 0, sizeof(buf));
45186@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_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 rts;
45193
45194 if (!priv->cfg->ht_params)
45195@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_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
45202 memset(buf, 0, sizeof(buf));
45203 buf_size = min(count, sizeof(buf) - 1);
45204@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
45205 struct iwl_priv *priv = file->private_data;
45206 u32 event_log_flag;
45207 char buf[8];
45208- int buf_size;
45209+ size_t buf_size;
45210
45211 /* check that the interface is up */
45212 if (!iwl_is_ready(priv))
45213@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
45214 struct iwl_priv *priv = file->private_data;
45215 char buf[8];
45216 u32 calib_disabled;
45217- int buf_size;
45218+ size_t buf_size;
45219
45220 memset(buf, 0, sizeof(buf));
45221 buf_size = min(count, sizeof(buf) - 1);
45222diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
45223index a8afc7b..de058b2 100644
45224--- a/drivers/net/wireless/iwlwifi/dvm/main.c
45225+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
45226@@ -1189,7 +1189,7 @@ static void iwl_option_config(struct iwl_priv *priv)
45227 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45228 {
45229 struct iwl_nvm_data *data = priv->nvm_data;
45230- char *debug_msg;
45231+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45232
45233 if (data->sku_cap_11n_enable &&
45234 !priv->cfg->ht_params) {
45235@@ -1203,7 +1203,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45236 return -EINVAL;
45237 }
45238
45239- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45240 IWL_DEBUG_INFO(priv, debug_msg,
45241 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
45242 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
45243diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
45244index aeb70e1..d7b5bb5 100644
45245--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
45246+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
45247@@ -1329,7 +1329,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
45248 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
45249
45250 char buf[8];
45251- int buf_size;
45252+ size_t buf_size;
45253 u32 reset_flag;
45254
45255 memset(buf, 0, sizeof(buf));
45256@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
45257 {
45258 struct iwl_trans *trans = file->private_data;
45259 char buf[8];
45260- int buf_size;
45261+ size_t buf_size;
45262 int csr;
45263
45264 memset(buf, 0, sizeof(buf));
45265diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
45266index cb34c78..9fec0dc 100644
45267--- a/drivers/net/wireless/mac80211_hwsim.c
45268+++ b/drivers/net/wireless/mac80211_hwsim.c
45269@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
45270
45271 if (channels > 1) {
45272 hwsim_if_comb.num_different_channels = channels;
45273- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45274- mac80211_hwsim_ops.cancel_hw_scan =
45275- mac80211_hwsim_cancel_hw_scan;
45276- mac80211_hwsim_ops.sw_scan_start = NULL;
45277- mac80211_hwsim_ops.sw_scan_complete = NULL;
45278- mac80211_hwsim_ops.remain_on_channel =
45279- mac80211_hwsim_roc;
45280- mac80211_hwsim_ops.cancel_remain_on_channel =
45281- mac80211_hwsim_croc;
45282- mac80211_hwsim_ops.add_chanctx =
45283- mac80211_hwsim_add_chanctx;
45284- mac80211_hwsim_ops.remove_chanctx =
45285- mac80211_hwsim_remove_chanctx;
45286- mac80211_hwsim_ops.change_chanctx =
45287- mac80211_hwsim_change_chanctx;
45288- mac80211_hwsim_ops.assign_vif_chanctx =
45289- mac80211_hwsim_assign_vif_chanctx;
45290- mac80211_hwsim_ops.unassign_vif_chanctx =
45291- mac80211_hwsim_unassign_vif_chanctx;
45292+ pax_open_kernel();
45293+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45294+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45295+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45296+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45297+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45298+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45299+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45300+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45301+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45302+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45303+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45304+ pax_close_kernel();
45305 }
45306
45307 spin_lock_init(&hwsim_radio_lock);
45308diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45309index 8169a85..7fa3b47 100644
45310--- a/drivers/net/wireless/rndis_wlan.c
45311+++ b/drivers/net/wireless/rndis_wlan.c
45312@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45313
45314 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45315
45316- if (rts_threshold < 0 || rts_threshold > 2347)
45317+ if (rts_threshold > 2347)
45318 rts_threshold = 2347;
45319
45320 tmp = cpu_to_le32(rts_threshold);
45321diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45322index 7510723..5ba37f5 100644
45323--- a/drivers/net/wireless/rt2x00/rt2x00.h
45324+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45325@@ -386,7 +386,7 @@ struct rt2x00_intf {
45326 * for hardware which doesn't support hardware
45327 * sequence counting.
45328 */
45329- atomic_t seqno;
45330+ atomic_unchecked_t seqno;
45331 };
45332
45333 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45334diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45335index d955741..8730748 100644
45336--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45337+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45338@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45339 * sequence counter given by mac80211.
45340 */
45341 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45342- seqno = atomic_add_return(0x10, &intf->seqno);
45343+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45344 else
45345- seqno = atomic_read(&intf->seqno);
45346+ seqno = atomic_read_unchecked(&intf->seqno);
45347
45348 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45349 hdr->seq_ctrl |= cpu_to_le16(seqno);
45350diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45351index e2b3d9c..67a5184 100644
45352--- a/drivers/net/wireless/ti/wl1251/sdio.c
45353+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45354@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45355
45356 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45357
45358- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45359- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45360+ pax_open_kernel();
45361+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45362+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45363+ pax_close_kernel();
45364
45365 wl1251_info("using dedicated interrupt line");
45366 } else {
45367- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45368- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45369+ pax_open_kernel();
45370+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45371+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45372+ pax_close_kernel();
45373
45374 wl1251_info("using SDIO interrupt");
45375 }
45376diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45377index 1c627da..69f7d17 100644
45378--- a/drivers/net/wireless/ti/wl12xx/main.c
45379+++ b/drivers/net/wireless/ti/wl12xx/main.c
45380@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45381 sizeof(wl->conf.mem));
45382
45383 /* read data preparation is only needed by wl127x */
45384- wl->ops->prepare_read = wl127x_prepare_read;
45385+ pax_open_kernel();
45386+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45387+ pax_close_kernel();
45388
45389 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45390 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45391@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45392 sizeof(wl->conf.mem));
45393
45394 /* read data preparation is only needed by wl127x */
45395- wl->ops->prepare_read = wl127x_prepare_read;
45396+ pax_open_kernel();
45397+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45398+ pax_close_kernel();
45399
45400 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45401 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45402diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45403index 9fa692d..b31fee0 100644
45404--- a/drivers/net/wireless/ti/wl18xx/main.c
45405+++ b/drivers/net/wireless/ti/wl18xx/main.c
45406@@ -1687,8 +1687,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45407 }
45408
45409 if (!checksum_param) {
45410- wl18xx_ops.set_rx_csum = NULL;
45411- wl18xx_ops.init_vif = NULL;
45412+ pax_open_kernel();
45413+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45414+ *(void **)&wl18xx_ops.init_vif = NULL;
45415+ pax_close_kernel();
45416 }
45417
45418 /* Enable 11a Band only if we have 5G antennas */
45419diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45420index 7ef0b4a..ff65c28 100644
45421--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45422+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45423@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45424 {
45425 struct zd_usb *usb = urb->context;
45426 struct zd_usb_interrupt *intr = &usb->intr;
45427- int len;
45428+ unsigned int len;
45429 u16 int_num;
45430
45431 ZD_ASSERT(in_interrupt());
45432diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45433index d93b2b6..ae50401 100644
45434--- a/drivers/oprofile/buffer_sync.c
45435+++ b/drivers/oprofile/buffer_sync.c
45436@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45437 if (cookie == NO_COOKIE)
45438 offset = pc;
45439 if (cookie == INVALID_COOKIE) {
45440- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45441+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45442 offset = pc;
45443 }
45444 if (cookie != last_cookie) {
45445@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45446 /* add userspace sample */
45447
45448 if (!mm) {
45449- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45450+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45451 return 0;
45452 }
45453
45454 cookie = lookup_dcookie(mm, s->eip, &offset);
45455
45456 if (cookie == INVALID_COOKIE) {
45457- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45458+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45459 return 0;
45460 }
45461
45462@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45463 /* ignore backtraces if failed to add a sample */
45464 if (state == sb_bt_start) {
45465 state = sb_bt_ignore;
45466- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45467+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45468 }
45469 }
45470 release_mm(mm);
45471diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45472index c0cc4e7..44d4e54 100644
45473--- a/drivers/oprofile/event_buffer.c
45474+++ b/drivers/oprofile/event_buffer.c
45475@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45476 }
45477
45478 if (buffer_pos == buffer_size) {
45479- atomic_inc(&oprofile_stats.event_lost_overflow);
45480+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45481 return;
45482 }
45483
45484diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45485index ed2c3ec..deda85a 100644
45486--- a/drivers/oprofile/oprof.c
45487+++ b/drivers/oprofile/oprof.c
45488@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45489 if (oprofile_ops.switch_events())
45490 return;
45491
45492- atomic_inc(&oprofile_stats.multiplex_counter);
45493+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45494 start_switch_worker();
45495 }
45496
45497diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45498index 84a208d..d61b0a1 100644
45499--- a/drivers/oprofile/oprofile_files.c
45500+++ b/drivers/oprofile/oprofile_files.c
45501@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45502
45503 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45504
45505-static ssize_t timeout_read(struct file *file, char __user *buf,
45506+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45507 size_t count, loff_t *offset)
45508 {
45509 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45510diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45511index 917d28e..d62d981 100644
45512--- a/drivers/oprofile/oprofile_stats.c
45513+++ b/drivers/oprofile/oprofile_stats.c
45514@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45515 cpu_buf->sample_invalid_eip = 0;
45516 }
45517
45518- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45519- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45520- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45521- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45522- atomic_set(&oprofile_stats.multiplex_counter, 0);
45523+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45524+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45525+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45526+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45527+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45528 }
45529
45530
45531diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45532index 38b6fc0..b5cbfce 100644
45533--- a/drivers/oprofile/oprofile_stats.h
45534+++ b/drivers/oprofile/oprofile_stats.h
45535@@ -13,11 +13,11 @@
45536 #include <linux/atomic.h>
45537
45538 struct oprofile_stat_struct {
45539- atomic_t sample_lost_no_mm;
45540- atomic_t sample_lost_no_mapping;
45541- atomic_t bt_lost_no_mapping;
45542- atomic_t event_lost_overflow;
45543- atomic_t multiplex_counter;
45544+ atomic_unchecked_t sample_lost_no_mm;
45545+ atomic_unchecked_t sample_lost_no_mapping;
45546+ atomic_unchecked_t bt_lost_no_mapping;
45547+ atomic_unchecked_t event_lost_overflow;
45548+ atomic_unchecked_t multiplex_counter;
45549 };
45550
45551 extern struct oprofile_stat_struct oprofile_stats;
45552diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45553index 7c12d9c..558bf3bb 100644
45554--- a/drivers/oprofile/oprofilefs.c
45555+++ b/drivers/oprofile/oprofilefs.c
45556@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45557
45558
45559 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45560- char const *name, atomic_t *val)
45561+ char const *name, atomic_unchecked_t *val)
45562 {
45563 return __oprofilefs_create_file(sb, root, name,
45564 &atomic_ro_fops, 0444, val);
45565diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45566index 93404f7..4a313d8 100644
45567--- a/drivers/oprofile/timer_int.c
45568+++ b/drivers/oprofile/timer_int.c
45569@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
45570 return NOTIFY_OK;
45571 }
45572
45573-static struct notifier_block __refdata oprofile_cpu_notifier = {
45574+static struct notifier_block oprofile_cpu_notifier = {
45575 .notifier_call = oprofile_cpu_notify,
45576 };
45577
45578diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45579index 92ed045..62d39bd7 100644
45580--- a/drivers/parport/procfs.c
45581+++ b/drivers/parport/procfs.c
45582@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45583
45584 *ppos += len;
45585
45586- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45587+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45588 }
45589
45590 #ifdef CONFIG_PARPORT_1284
45591@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45592
45593 *ppos += len;
45594
45595- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45596+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45597 }
45598 #endif /* IEEE1284.3 support. */
45599
45600diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45601index c35e8ad..fc33beb 100644
45602--- a/drivers/pci/hotplug/acpiphp_ibm.c
45603+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45604@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45605 goto init_cleanup;
45606 }
45607
45608- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45609+ pax_open_kernel();
45610+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45611+ pax_close_kernel();
45612 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45613
45614 return retval;
45615diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45616index a6a71c4..c91097b 100644
45617--- a/drivers/pci/hotplug/cpcihp_generic.c
45618+++ b/drivers/pci/hotplug/cpcihp_generic.c
45619@@ -73,7 +73,6 @@ static u16 port;
45620 static unsigned int enum_bit;
45621 static u8 enum_mask;
45622
45623-static struct cpci_hp_controller_ops generic_hpc_ops;
45624 static struct cpci_hp_controller generic_hpc;
45625
45626 static int __init validate_parameters(void)
45627@@ -139,6 +138,10 @@ static int query_enum(void)
45628 return ((value & enum_mask) == enum_mask);
45629 }
45630
45631+static struct cpci_hp_controller_ops generic_hpc_ops = {
45632+ .query_enum = query_enum,
45633+};
45634+
45635 static int __init cpcihp_generic_init(void)
45636 {
45637 int status;
45638@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45639 pci_dev_put(dev);
45640
45641 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45642- generic_hpc_ops.query_enum = query_enum;
45643 generic_hpc.ops = &generic_hpc_ops;
45644
45645 status = cpci_hp_register_controller(&generic_hpc);
45646diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45647index 449b4bb..257e2e8 100644
45648--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45649+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45650@@ -59,7 +59,6 @@
45651 /* local variables */
45652 static bool debug;
45653 static bool poll;
45654-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45655 static struct cpci_hp_controller zt5550_hpc;
45656
45657 /* Primary cPCI bus bridge device */
45658@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45659 return 0;
45660 }
45661
45662+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45663+ .query_enum = zt5550_hc_query_enum,
45664+};
45665+
45666 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45667 {
45668 int status;
45669@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45670 dbg("returned from zt5550_hc_config");
45671
45672 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45673- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45674 zt5550_hpc.ops = &zt5550_hpc_ops;
45675 if(!poll) {
45676 zt5550_hpc.irq = hc_dev->irq;
45677 zt5550_hpc.irq_flags = IRQF_SHARED;
45678 zt5550_hpc.dev_id = hc_dev;
45679
45680- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45681- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45682- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45683+ pax_open_kernel();
45684+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45685+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45686+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45687+ pax_open_kernel();
45688 } else {
45689 info("using ENUM# polling mode");
45690 }
45691diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45692index 76ba8a1..20ca857 100644
45693--- a/drivers/pci/hotplug/cpqphp_nvram.c
45694+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45695@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45696
45697 void compaq_nvram_init (void __iomem *rom_start)
45698 {
45699+
45700+#ifndef CONFIG_PAX_KERNEXEC
45701 if (rom_start) {
45702 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45703 }
45704+#endif
45705+
45706 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45707
45708 /* initialize our int15 lock */
45709diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45710index ec20f74..c1d961e 100644
45711--- a/drivers/pci/hotplug/pci_hotplug_core.c
45712+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45713@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45714 return -EINVAL;
45715 }
45716
45717- slot->ops->owner = owner;
45718- slot->ops->mod_name = mod_name;
45719+ pax_open_kernel();
45720+ *(struct module **)&slot->ops->owner = owner;
45721+ *(const char **)&slot->ops->mod_name = mod_name;
45722+ pax_close_kernel();
45723
45724 mutex_lock(&pci_hp_mutex);
45725 /*
45726diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45727index 7d72c5e..edce02c 100644
45728--- a/drivers/pci/hotplug/pciehp_core.c
45729+++ b/drivers/pci/hotplug/pciehp_core.c
45730@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45731 struct slot *slot = ctrl->slot;
45732 struct hotplug_slot *hotplug = NULL;
45733 struct hotplug_slot_info *info = NULL;
45734- struct hotplug_slot_ops *ops = NULL;
45735+ hotplug_slot_ops_no_const *ops = NULL;
45736 char name[SLOT_NAME_SIZE];
45737 int retval = -ENOMEM;
45738
45739diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
45740index 5127f3f..b225573 100644
45741--- a/drivers/pci/hotplug/pciehp_hpc.c
45742+++ b/drivers/pci/hotplug/pciehp_hpc.c
45743@@ -773,14 +773,12 @@ static void pcie_shutdown_notification(struct controller *ctrl)
45744 static int pcie_init_slot(struct controller *ctrl)
45745 {
45746 struct slot *slot;
45747- char name[32];
45748
45749 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
45750 if (!slot)
45751 return -ENOMEM;
45752
45753- snprintf(name, sizeof(name), "pciehp-%u", PSN(ctrl));
45754- slot->wq = alloc_workqueue(name, 0, 0);
45755+ slot->wq = alloc_workqueue("pciehp-%u", 0, 0, PSN(ctrl));
45756 if (!slot->wq)
45757 goto abort;
45758
45759diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45760index 5b4a9d9..cd5ac1f 100644
45761--- a/drivers/pci/pci-sysfs.c
45762+++ b/drivers/pci/pci-sysfs.c
45763@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45764 {
45765 /* allocate attribute structure, piggyback attribute name */
45766 int name_len = write_combine ? 13 : 10;
45767- struct bin_attribute *res_attr;
45768+ bin_attribute_no_const *res_attr;
45769 int retval;
45770
45771 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45772@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45773 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45774 {
45775 int retval;
45776- struct bin_attribute *attr;
45777+ bin_attribute_no_const *attr;
45778
45779 /* If the device has VPD, try to expose it in sysfs. */
45780 if (dev->vpd) {
45781@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45782 {
45783 int retval;
45784 int rom_size = 0;
45785- struct bin_attribute *attr;
45786+ bin_attribute_no_const *attr;
45787
45788 if (!sysfs_initialized)
45789 return -EACCES;
45790diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45791index d1182c4..2a138ec 100644
45792--- a/drivers/pci/pci.h
45793+++ b/drivers/pci/pci.h
45794@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45795 struct pci_vpd {
45796 unsigned int len;
45797 const struct pci_vpd_ops *ops;
45798- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45799+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45800 };
45801
45802 int pci_vpd_pci22_init(struct pci_dev *dev);
45803diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45804index d320df6..ca9a8f6 100644
45805--- a/drivers/pci/pcie/aspm.c
45806+++ b/drivers/pci/pcie/aspm.c
45807@@ -27,9 +27,9 @@
45808 #define MODULE_PARAM_PREFIX "pcie_aspm."
45809
45810 /* Note: those are not register definitions */
45811-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45812-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45813-#define ASPM_STATE_L1 (4) /* L1 state */
45814+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45815+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45816+#define ASPM_STATE_L1 (4U) /* L1 state */
45817 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45818 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45819
45820diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45821index ea37072..10e58e56 100644
45822--- a/drivers/pci/probe.c
45823+++ b/drivers/pci/probe.c
45824@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45825 struct pci_bus_region region;
45826 bool bar_too_big = false, bar_disabled = false;
45827
45828- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45829+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45830
45831 /* No printks while decoding is disabled! */
45832 if (!dev->mmio_always_on) {
45833diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45834index 0812608..b04018c4 100644
45835--- a/drivers/pci/proc.c
45836+++ b/drivers/pci/proc.c
45837@@ -453,7 +453,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45838 static int __init pci_proc_init(void)
45839 {
45840 struct pci_dev *dev = NULL;
45841+
45842+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45843+#ifdef CONFIG_GRKERNSEC_PROC_USER
45844+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45845+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45846+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45847+#endif
45848+#else
45849 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45850+#endif
45851 proc_create("devices", 0, proc_bus_pci_dir,
45852 &proc_bus_pci_dev_operations);
45853 proc_initialized = 1;
45854diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45855index 3e5b4497..dcdfb70 100644
45856--- a/drivers/platform/x86/chromeos_laptop.c
45857+++ b/drivers/platform/x86/chromeos_laptop.c
45858@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45859 return 0;
45860 }
45861
45862-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45863+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45864 {
45865 .ident = "Samsung Series 5 550 - Touchpad",
45866 .matches = {
45867diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45868index 6b22938..bc9700e 100644
45869--- a/drivers/platform/x86/msi-laptop.c
45870+++ b/drivers/platform/x86/msi-laptop.c
45871@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45872
45873 if (!quirks->ec_read_only) {
45874 /* allow userland write sysfs file */
45875- dev_attr_bluetooth.store = store_bluetooth;
45876- dev_attr_wlan.store = store_wlan;
45877- dev_attr_threeg.store = store_threeg;
45878- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45879- dev_attr_wlan.attr.mode |= S_IWUSR;
45880- dev_attr_threeg.attr.mode |= S_IWUSR;
45881+ pax_open_kernel();
45882+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45883+ *(void **)&dev_attr_wlan.store = store_wlan;
45884+ *(void **)&dev_attr_threeg.store = store_threeg;
45885+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45886+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45887+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45888+ pax_close_kernel();
45889 }
45890
45891 /* disable hardware control by fn key */
45892diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45893index 2ac045f..39c443d 100644
45894--- a/drivers/platform/x86/sony-laptop.c
45895+++ b/drivers/platform/x86/sony-laptop.c
45896@@ -2483,7 +2483,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45897 }
45898
45899 /* High speed charging function */
45900-static struct device_attribute *hsc_handle;
45901+static device_attribute_no_const *hsc_handle;
45902
45903 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45904 struct device_attribute *attr,
45905diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45906index 54d31c0..3f896d3 100644
45907--- a/drivers/platform/x86/thinkpad_acpi.c
45908+++ b/drivers/platform/x86/thinkpad_acpi.c
45909@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45910 return 0;
45911 }
45912
45913-void static hotkey_mask_warn_incomplete_mask(void)
45914+static void hotkey_mask_warn_incomplete_mask(void)
45915 {
45916 /* log only what the user can fix... */
45917 const u32 wantedmask = hotkey_driver_mask &
45918@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45919 }
45920 }
45921
45922-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45923- struct tp_nvram_state *newn,
45924- const u32 event_mask)
45925-{
45926-
45927 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45928 do { \
45929 if ((event_mask & (1 << __scancode)) && \
45930@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45931 tpacpi_hotkey_send_key(__scancode); \
45932 } while (0)
45933
45934- void issue_volchange(const unsigned int oldvol,
45935- const unsigned int newvol)
45936- {
45937- unsigned int i = oldvol;
45938+static void issue_volchange(const unsigned int oldvol,
45939+ const unsigned int newvol,
45940+ const u32 event_mask)
45941+{
45942+ unsigned int i = oldvol;
45943
45944- while (i > newvol) {
45945- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45946- i--;
45947- }
45948- while (i < newvol) {
45949- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45950- i++;
45951- }
45952+ while (i > newvol) {
45953+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45954+ i--;
45955 }
45956+ while (i < newvol) {
45957+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45958+ i++;
45959+ }
45960+}
45961
45962- void issue_brightnesschange(const unsigned int oldbrt,
45963- const unsigned int newbrt)
45964- {
45965- unsigned int i = oldbrt;
45966+static void issue_brightnesschange(const unsigned int oldbrt,
45967+ const unsigned int newbrt,
45968+ const u32 event_mask)
45969+{
45970+ unsigned int i = oldbrt;
45971
45972- while (i > newbrt) {
45973- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45974- i--;
45975- }
45976- while (i < newbrt) {
45977- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45978- i++;
45979- }
45980+ while (i > newbrt) {
45981+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45982+ i--;
45983+ }
45984+ while (i < newbrt) {
45985+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45986+ i++;
45987 }
45988+}
45989
45990+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45991+ struct tp_nvram_state *newn,
45992+ const u32 event_mask)
45993+{
45994 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45995 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45996 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45997@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45998 oldn->volume_level != newn->volume_level) {
45999 /* recently muted, or repeated mute keypress, or
46000 * multiple presses ending in mute */
46001- issue_volchange(oldn->volume_level, newn->volume_level);
46002+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
46003 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
46004 }
46005 } else {
46006@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46007 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46008 }
46009 if (oldn->volume_level != newn->volume_level) {
46010- issue_volchange(oldn->volume_level, newn->volume_level);
46011+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
46012 } else if (oldn->volume_toggle != newn->volume_toggle) {
46013 /* repeated vol up/down keypress at end of scale ? */
46014 if (newn->volume_level == 0)
46015@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46016 /* handle brightness */
46017 if (oldn->brightness_level != newn->brightness_level) {
46018 issue_brightnesschange(oldn->brightness_level,
46019- newn->brightness_level);
46020+ newn->brightness_level,
46021+ event_mask);
46022 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
46023 /* repeated key presses that didn't change state */
46024 if (newn->brightness_level == 0)
46025@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46026 && !tp_features.bright_unkfw)
46027 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46028 }
46029+}
46030
46031 #undef TPACPI_COMPARE_KEY
46032 #undef TPACPI_MAY_SEND_KEY
46033-}
46034
46035 /*
46036 * Polling driver
46037diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
46038index e4ac38a..b13344c 100644
46039--- a/drivers/platform/x86/wmi.c
46040+++ b/drivers/platform/x86/wmi.c
46041@@ -743,7 +743,7 @@ static int wmi_create_device(const struct guid_block *gblock,
46042 wblock->dev.class = &wmi_class;
46043
46044 wmi_gtoa(gblock->guid, guid_string);
46045- dev_set_name(&wblock->dev, guid_string);
46046+ dev_set_name(&wblock->dev, "%s", guid_string);
46047
46048 dev_set_drvdata(&wblock->dev, wblock);
46049
46050diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
46051index 769d265..a3a05ca 100644
46052--- a/drivers/pnp/pnpbios/bioscalls.c
46053+++ b/drivers/pnp/pnpbios/bioscalls.c
46054@@ -58,7 +58,7 @@ do { \
46055 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
46056 } while(0)
46057
46058-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
46059+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
46060 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
46061
46062 /*
46063@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46064
46065 cpu = get_cpu();
46066 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
46067+
46068+ pax_open_kernel();
46069 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
46070+ pax_close_kernel();
46071
46072 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
46073 spin_lock_irqsave(&pnp_bios_lock, flags);
46074@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46075 :"memory");
46076 spin_unlock_irqrestore(&pnp_bios_lock, flags);
46077
46078+ pax_open_kernel();
46079 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
46080+ pax_close_kernel();
46081+
46082 put_cpu();
46083
46084 /* If we get here and this is set then the PnP BIOS faulted on us. */
46085@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
46086 return status;
46087 }
46088
46089-void pnpbios_calls_init(union pnp_bios_install_struct *header)
46090+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
46091 {
46092 int i;
46093
46094@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46095 pnp_bios_callpoint.offset = header->fields.pm16offset;
46096 pnp_bios_callpoint.segment = PNP_CS16;
46097
46098+ pax_open_kernel();
46099+
46100 for_each_possible_cpu(i) {
46101 struct desc_struct *gdt = get_cpu_gdt_table(i);
46102 if (!gdt)
46103@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46104 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
46105 (unsigned long)__va(header->fields.pm16dseg));
46106 }
46107+
46108+ pax_close_kernel();
46109 }
46110diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
46111index 3e6db1c..1fbbdae 100644
46112--- a/drivers/pnp/resource.c
46113+++ b/drivers/pnp/resource.c
46114@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
46115 return 1;
46116
46117 /* check if the resource is valid */
46118- if (*irq < 0 || *irq > 15)
46119+ if (*irq > 15)
46120 return 0;
46121
46122 /* check if the resource is reserved */
46123@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
46124 return 1;
46125
46126 /* check if the resource is valid */
46127- if (*dma < 0 || *dma == 4 || *dma > 7)
46128+ if (*dma == 4 || *dma > 7)
46129 return 0;
46130
46131 /* check if the resource is reserved */
46132diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
46133index 0c52e2a..3421ab7 100644
46134--- a/drivers/power/pda_power.c
46135+++ b/drivers/power/pda_power.c
46136@@ -37,7 +37,11 @@ static int polling;
46137
46138 #if IS_ENABLED(CONFIG_USB_PHY)
46139 static struct usb_phy *transceiver;
46140-static struct notifier_block otg_nb;
46141+static int otg_handle_notification(struct notifier_block *nb,
46142+ unsigned long event, void *unused);
46143+static struct notifier_block otg_nb = {
46144+ .notifier_call = otg_handle_notification
46145+};
46146 #endif
46147
46148 static struct regulator *ac_draw;
46149@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
46150
46151 #if IS_ENABLED(CONFIG_USB_PHY)
46152 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
46153- otg_nb.notifier_call = otg_handle_notification;
46154 ret = usb_register_notifier(transceiver, &otg_nb);
46155 if (ret) {
46156 dev_err(dev, "failure to register otg notifier\n");
46157diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
46158index cc439fd..8fa30df 100644
46159--- a/drivers/power/power_supply.h
46160+++ b/drivers/power/power_supply.h
46161@@ -16,12 +16,12 @@ struct power_supply;
46162
46163 #ifdef CONFIG_SYSFS
46164
46165-extern void power_supply_init_attrs(struct device_type *dev_type);
46166+extern void power_supply_init_attrs(void);
46167 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
46168
46169 #else
46170
46171-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
46172+static inline void power_supply_init_attrs(void) {}
46173 #define power_supply_uevent NULL
46174
46175 #endif /* CONFIG_SYSFS */
46176diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
46177index 1c517c3..ffa2f17 100644
46178--- a/drivers/power/power_supply_core.c
46179+++ b/drivers/power/power_supply_core.c
46180@@ -24,7 +24,10 @@
46181 struct class *power_supply_class;
46182 EXPORT_SYMBOL_GPL(power_supply_class);
46183
46184-static struct device_type power_supply_dev_type;
46185+extern const struct attribute_group *power_supply_attr_groups[];
46186+static struct device_type power_supply_dev_type = {
46187+ .groups = power_supply_attr_groups,
46188+};
46189
46190 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
46191 struct power_supply *supply)
46192@@ -554,7 +557,7 @@ static int __init power_supply_class_init(void)
46193 return PTR_ERR(power_supply_class);
46194
46195 power_supply_class->dev_uevent = power_supply_uevent;
46196- power_supply_init_attrs(&power_supply_dev_type);
46197+ power_supply_init_attrs();
46198
46199 return 0;
46200 }
46201diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
46202index 29178f7..c65f324 100644
46203--- a/drivers/power/power_supply_sysfs.c
46204+++ b/drivers/power/power_supply_sysfs.c
46205@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
46206 .is_visible = power_supply_attr_is_visible,
46207 };
46208
46209-static const struct attribute_group *power_supply_attr_groups[] = {
46210+const struct attribute_group *power_supply_attr_groups[] = {
46211 &power_supply_attr_group,
46212 NULL,
46213 };
46214
46215-void power_supply_init_attrs(struct device_type *dev_type)
46216+void power_supply_init_attrs(void)
46217 {
46218 int i;
46219
46220- dev_type->groups = power_supply_attr_groups;
46221-
46222 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
46223 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
46224 }
46225diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
46226index 815d6df..811633a 100644
46227--- a/drivers/regulator/core.c
46228+++ b/drivers/regulator/core.c
46229@@ -3529,7 +3529,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46230 {
46231 const struct regulation_constraints *constraints = NULL;
46232 const struct regulator_init_data *init_data;
46233- static atomic_t regulator_no = ATOMIC_INIT(0);
46234+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
46235 struct regulator_dev *rdev;
46236 struct device *dev;
46237 int ret, i;
46238@@ -3599,7 +3599,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46239 rdev->dev.of_node = config->of_node;
46240 rdev->dev.parent = dev;
46241 dev_set_name(&rdev->dev, "regulator.%d",
46242- atomic_inc_return(&regulator_no) - 1);
46243+ atomic_inc_return_unchecked(&regulator_no) - 1);
46244 ret = device_register(&rdev->dev);
46245 if (ret != 0) {
46246 put_device(&rdev->dev);
46247diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
46248index d428ef9..fdc0357 100644
46249--- a/drivers/regulator/max8660.c
46250+++ b/drivers/regulator/max8660.c
46251@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
46252 max8660->shadow_regs[MAX8660_OVER1] = 5;
46253 } else {
46254 /* Otherwise devices can be toggled via software */
46255- max8660_dcdc_ops.enable = max8660_dcdc_enable;
46256- max8660_dcdc_ops.disable = max8660_dcdc_disable;
46257+ pax_open_kernel();
46258+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
46259+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
46260+ pax_close_kernel();
46261 }
46262
46263 /*
46264diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
46265index adb1414..c13e0ce 100644
46266--- a/drivers/regulator/max8973-regulator.c
46267+++ b/drivers/regulator/max8973-regulator.c
46268@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
46269 if (!pdata->enable_ext_control) {
46270 max->desc.enable_reg = MAX8973_VOUT;
46271 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
46272- max8973_dcdc_ops.enable = regulator_enable_regmap;
46273- max8973_dcdc_ops.disable = regulator_disable_regmap;
46274- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
46275+ pax_open_kernel();
46276+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
46277+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
46278+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
46279+ pax_close_kernel();
46280 }
46281
46282 max->enable_external_control = pdata->enable_ext_control;
46283diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
46284index b716283..3cc4349 100644
46285--- a/drivers/regulator/mc13892-regulator.c
46286+++ b/drivers/regulator/mc13892-regulator.c
46287@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
46288 }
46289 mc13xxx_unlock(mc13892);
46290
46291- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46292+ pax_open_kernel();
46293+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46294 = mc13892_vcam_set_mode;
46295- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46296+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46297 = mc13892_vcam_get_mode;
46298+ pax_close_kernel();
46299
46300 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46301 ARRAY_SIZE(mc13892_regulators));
46302diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46303index f1cb706..4c7832a 100644
46304--- a/drivers/rtc/rtc-cmos.c
46305+++ b/drivers/rtc/rtc-cmos.c
46306@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46307 hpet_rtc_timer_init();
46308
46309 /* export at least the first block of NVRAM */
46310- nvram.size = address_space - NVRAM_OFFSET;
46311+ pax_open_kernel();
46312+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46313+ pax_close_kernel();
46314 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46315 if (retval < 0) {
46316 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46317diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46318index d049393..bb20be0 100644
46319--- a/drivers/rtc/rtc-dev.c
46320+++ b/drivers/rtc/rtc-dev.c
46321@@ -16,6 +16,7 @@
46322 #include <linux/module.h>
46323 #include <linux/rtc.h>
46324 #include <linux/sched.h>
46325+#include <linux/grsecurity.h>
46326 #include "rtc-core.h"
46327
46328 static dev_t rtc_devt;
46329@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46330 if (copy_from_user(&tm, uarg, sizeof(tm)))
46331 return -EFAULT;
46332
46333+ gr_log_timechange();
46334+
46335 return rtc_set_time(rtc, &tm);
46336
46337 case RTC_PIE_ON:
46338diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46339index b53992a..776df84 100644
46340--- a/drivers/rtc/rtc-ds1307.c
46341+++ b/drivers/rtc/rtc-ds1307.c
46342@@ -107,7 +107,7 @@ struct ds1307 {
46343 u8 offset; /* register's offset */
46344 u8 regs[11];
46345 u16 nvram_offset;
46346- struct bin_attribute *nvram;
46347+ bin_attribute_no_const *nvram;
46348 enum ds_type type;
46349 unsigned long flags;
46350 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46351diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46352index 130f29a..6179d03 100644
46353--- a/drivers/rtc/rtc-m48t59.c
46354+++ b/drivers/rtc/rtc-m48t59.c
46355@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46356 goto out;
46357 }
46358
46359- m48t59_nvram_attr.size = pdata->offset;
46360+ pax_open_kernel();
46361+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46362+ pax_close_kernel();
46363
46364 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46365 if (ret) {
46366diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46367index e693af6..2e525b6 100644
46368--- a/drivers/scsi/bfa/bfa_fcpim.h
46369+++ b/drivers/scsi/bfa/bfa_fcpim.h
46370@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46371
46372 struct bfa_itn_s {
46373 bfa_isr_func_t isr;
46374-};
46375+} __no_const;
46376
46377 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46378 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46379diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46380index 23a90e7..9cf04ee 100644
46381--- a/drivers/scsi/bfa/bfa_ioc.h
46382+++ b/drivers/scsi/bfa/bfa_ioc.h
46383@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46384 bfa_ioc_disable_cbfn_t disable_cbfn;
46385 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46386 bfa_ioc_reset_cbfn_t reset_cbfn;
46387-};
46388+} __no_const;
46389
46390 /*
46391 * IOC event notification mechanism.
46392@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
46393 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
46394 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
46395 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
46396-};
46397+} __no_const;
46398
46399 /*
46400 * Queue element to wait for room in request queue. FIFO order is
46401diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46402index 8c05ae01..b2cf224 100644
46403--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46404+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46405@@ -33,8 +33,8 @@
46406 */
46407 #include "libfcoe.h"
46408
46409-static atomic_t ctlr_num;
46410-static atomic_t fcf_num;
46411+static atomic_unchecked_t ctlr_num;
46412+static atomic_unchecked_t fcf_num;
46413
46414 /*
46415 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46416@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46417 if (!ctlr)
46418 goto out;
46419
46420- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46421+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46422 ctlr->f = f;
46423 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46424 INIT_LIST_HEAD(&ctlr->fcfs);
46425@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46426 fcf->dev.parent = &ctlr->dev;
46427 fcf->dev.bus = &fcoe_bus_type;
46428 fcf->dev.type = &fcoe_fcf_device_type;
46429- fcf->id = atomic_inc_return(&fcf_num) - 1;
46430+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46431 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46432
46433 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46434@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46435 {
46436 int error;
46437
46438- atomic_set(&ctlr_num, 0);
46439- atomic_set(&fcf_num, 0);
46440+ atomic_set_unchecked(&ctlr_num, 0);
46441+ atomic_set_unchecked(&fcf_num, 0);
46442
46443 error = bus_register(&fcoe_bus_type);
46444 if (error)
46445diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46446index df0c3c7..b00e1d0 100644
46447--- a/drivers/scsi/hosts.c
46448+++ b/drivers/scsi/hosts.c
46449@@ -42,7 +42,7 @@
46450 #include "scsi_logging.h"
46451
46452
46453-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46454+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46455
46456
46457 static void scsi_host_cls_release(struct device *dev)
46458@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46459 * subtract one because we increment first then return, but we need to
46460 * know what the next host number was before increment
46461 */
46462- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46463+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46464 shost->dma_channel = 0xff;
46465
46466 /* These three are default values which can be overridden */
46467diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46468index 7f4f790..b75b92a 100644
46469--- a/drivers/scsi/hpsa.c
46470+++ b/drivers/scsi/hpsa.c
46471@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46472 unsigned long flags;
46473
46474 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46475- return h->access.command_completed(h, q);
46476+ return h->access->command_completed(h, q);
46477
46478 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46479 a = rq->head[rq->current_entry];
46480@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46481 while (!list_empty(&h->reqQ)) {
46482 c = list_entry(h->reqQ.next, struct CommandList, list);
46483 /* can't do anything if fifo is full */
46484- if ((h->access.fifo_full(h))) {
46485+ if ((h->access->fifo_full(h))) {
46486 dev_warn(&h->pdev->dev, "fifo full\n");
46487 break;
46488 }
46489@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46490
46491 /* Tell the controller execute command */
46492 spin_unlock_irqrestore(&h->lock, flags);
46493- h->access.submit_command(h, c);
46494+ h->access->submit_command(h, c);
46495 spin_lock_irqsave(&h->lock, flags);
46496 }
46497 spin_unlock_irqrestore(&h->lock, flags);
46498@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46499
46500 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46501 {
46502- return h->access.command_completed(h, q);
46503+ return h->access->command_completed(h, q);
46504 }
46505
46506 static inline bool interrupt_pending(struct ctlr_info *h)
46507 {
46508- return h->access.intr_pending(h);
46509+ return h->access->intr_pending(h);
46510 }
46511
46512 static inline long interrupt_not_for_us(struct ctlr_info *h)
46513 {
46514- return (h->access.intr_pending(h) == 0) ||
46515+ return (h->access->intr_pending(h) == 0) ||
46516 (h->interrupts_enabled == 0);
46517 }
46518
46519@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46520 if (prod_index < 0)
46521 return -ENODEV;
46522 h->product_name = products[prod_index].product_name;
46523- h->access = *(products[prod_index].access);
46524+ h->access = products[prod_index].access;
46525
46526 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46527 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46528@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46529
46530 assert_spin_locked(&lockup_detector_lock);
46531 remove_ctlr_from_lockup_detector_list(h);
46532- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46533+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46534 spin_lock_irqsave(&h->lock, flags);
46535 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46536 spin_unlock_irqrestore(&h->lock, flags);
46537@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46538 }
46539
46540 /* make sure the board interrupts are off */
46541- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46542+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46543
46544 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46545 goto clean2;
46546@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46547 * fake ones to scoop up any residual completions.
46548 */
46549 spin_lock_irqsave(&h->lock, flags);
46550- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46551+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46552 spin_unlock_irqrestore(&h->lock, flags);
46553 free_irqs(h);
46554 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46555@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46556 dev_info(&h->pdev->dev, "Board READY.\n");
46557 dev_info(&h->pdev->dev,
46558 "Waiting for stale completions to drain.\n");
46559- h->access.set_intr_mask(h, HPSA_INTR_ON);
46560+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46561 msleep(10000);
46562- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46563+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46564
46565 rc = controller_reset_failed(h->cfgtable);
46566 if (rc)
46567@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46568 }
46569
46570 /* Turn the interrupts on so we can service requests */
46571- h->access.set_intr_mask(h, HPSA_INTR_ON);
46572+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46573
46574 hpsa_hba_inquiry(h);
46575 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46576@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46577 * To write all data in the battery backed cache to disks
46578 */
46579 hpsa_flush_cache(h);
46580- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46581+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46582 hpsa_free_irqs_and_disable_msix(h);
46583 }
46584
46585@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46586 return;
46587 }
46588 /* Change the access methods to the performant access methods */
46589- h->access = SA5_performant_access;
46590+ h->access = &SA5_performant_access;
46591 h->transMethod = CFGTBL_Trans_Performant;
46592 }
46593
46594diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46595index 9816479..c5d4e97 100644
46596--- a/drivers/scsi/hpsa.h
46597+++ b/drivers/scsi/hpsa.h
46598@@ -79,7 +79,7 @@ struct ctlr_info {
46599 unsigned int msix_vector;
46600 unsigned int msi_vector;
46601 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46602- struct access_method access;
46603+ struct access_method *access;
46604
46605 /* queue and queue Info */
46606 struct list_head reqQ;
46607diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46608index 8b928c6..9c76300 100644
46609--- a/drivers/scsi/libfc/fc_exch.c
46610+++ b/drivers/scsi/libfc/fc_exch.c
46611@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46612 u16 pool_max_index;
46613
46614 struct {
46615- atomic_t no_free_exch;
46616- atomic_t no_free_exch_xid;
46617- atomic_t xid_not_found;
46618- atomic_t xid_busy;
46619- atomic_t seq_not_found;
46620- atomic_t non_bls_resp;
46621+ atomic_unchecked_t no_free_exch;
46622+ atomic_unchecked_t no_free_exch_xid;
46623+ atomic_unchecked_t xid_not_found;
46624+ atomic_unchecked_t xid_busy;
46625+ atomic_unchecked_t seq_not_found;
46626+ atomic_unchecked_t non_bls_resp;
46627 } stats;
46628 };
46629
46630@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46631 /* allocate memory for exchange */
46632 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46633 if (!ep) {
46634- atomic_inc(&mp->stats.no_free_exch);
46635+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46636 goto out;
46637 }
46638 memset(ep, 0, sizeof(*ep));
46639@@ -797,7 +797,7 @@ out:
46640 return ep;
46641 err:
46642 spin_unlock_bh(&pool->lock);
46643- atomic_inc(&mp->stats.no_free_exch_xid);
46644+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46645 mempool_free(ep, mp->ep_pool);
46646 return NULL;
46647 }
46648@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46649 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46650 ep = fc_exch_find(mp, xid);
46651 if (!ep) {
46652- atomic_inc(&mp->stats.xid_not_found);
46653+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46654 reject = FC_RJT_OX_ID;
46655 goto out;
46656 }
46657@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46658 ep = fc_exch_find(mp, xid);
46659 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46660 if (ep) {
46661- atomic_inc(&mp->stats.xid_busy);
46662+ atomic_inc_unchecked(&mp->stats.xid_busy);
46663 reject = FC_RJT_RX_ID;
46664 goto rel;
46665 }
46666@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46667 }
46668 xid = ep->xid; /* get our XID */
46669 } else if (!ep) {
46670- atomic_inc(&mp->stats.xid_not_found);
46671+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46672 reject = FC_RJT_RX_ID; /* XID not found */
46673 goto out;
46674 }
46675@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46676 } else {
46677 sp = &ep->seq;
46678 if (sp->id != fh->fh_seq_id) {
46679- atomic_inc(&mp->stats.seq_not_found);
46680+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46681 if (f_ctl & FC_FC_END_SEQ) {
46682 /*
46683 * Update sequence_id based on incoming last
46684@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46685
46686 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46687 if (!ep) {
46688- atomic_inc(&mp->stats.xid_not_found);
46689+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46690 goto out;
46691 }
46692 if (ep->esb_stat & ESB_ST_COMPLETE) {
46693- atomic_inc(&mp->stats.xid_not_found);
46694+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46695 goto rel;
46696 }
46697 if (ep->rxid == FC_XID_UNKNOWN)
46698 ep->rxid = ntohs(fh->fh_rx_id);
46699 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46700- atomic_inc(&mp->stats.xid_not_found);
46701+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46702 goto rel;
46703 }
46704 if (ep->did != ntoh24(fh->fh_s_id) &&
46705 ep->did != FC_FID_FLOGI) {
46706- atomic_inc(&mp->stats.xid_not_found);
46707+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46708 goto rel;
46709 }
46710 sof = fr_sof(fp);
46711@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46712 sp->ssb_stat |= SSB_ST_RESP;
46713 sp->id = fh->fh_seq_id;
46714 } else if (sp->id != fh->fh_seq_id) {
46715- atomic_inc(&mp->stats.seq_not_found);
46716+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46717 goto rel;
46718 }
46719
46720@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46721 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46722
46723 if (!sp)
46724- atomic_inc(&mp->stats.xid_not_found);
46725+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46726 else
46727- atomic_inc(&mp->stats.non_bls_resp);
46728+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46729
46730 fc_frame_free(fp);
46731 }
46732@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46733
46734 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46735 mp = ema->mp;
46736- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46737+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46738 st->fc_no_free_exch_xid +=
46739- atomic_read(&mp->stats.no_free_exch_xid);
46740- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46741- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46742- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46743- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46744+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46745+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46746+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46747+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46748+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46749 }
46750 }
46751 EXPORT_SYMBOL(fc_exch_update_stats);
46752diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46753index 161c98e..6d563b3 100644
46754--- a/drivers/scsi/libsas/sas_ata.c
46755+++ b/drivers/scsi/libsas/sas_ata.c
46756@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46757 .postreset = ata_std_postreset,
46758 .error_handler = ata_std_error_handler,
46759 .post_internal_cmd = sas_ata_post_internal,
46760- .qc_defer = ata_std_qc_defer,
46761+ .qc_defer = ata_std_qc_defer,
46762 .qc_prep = ata_noop_qc_prep,
46763 .qc_issue = sas_ata_qc_issue,
46764 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46765diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46766index bcc56ca..6f4174a 100644
46767--- a/drivers/scsi/lpfc/lpfc.h
46768+++ b/drivers/scsi/lpfc/lpfc.h
46769@@ -431,7 +431,7 @@ struct lpfc_vport {
46770 struct dentry *debug_nodelist;
46771 struct dentry *vport_debugfs_root;
46772 struct lpfc_debugfs_trc *disc_trc;
46773- atomic_t disc_trc_cnt;
46774+ atomic_unchecked_t disc_trc_cnt;
46775 #endif
46776 uint8_t stat_data_enabled;
46777 uint8_t stat_data_blocked;
46778@@ -865,8 +865,8 @@ struct lpfc_hba {
46779 struct timer_list fabric_block_timer;
46780 unsigned long bit_flags;
46781 #define FABRIC_COMANDS_BLOCKED 0
46782- atomic_t num_rsrc_err;
46783- atomic_t num_cmd_success;
46784+ atomic_unchecked_t num_rsrc_err;
46785+ atomic_unchecked_t num_cmd_success;
46786 unsigned long last_rsrc_error_time;
46787 unsigned long last_ramp_down_time;
46788 unsigned long last_ramp_up_time;
46789@@ -902,7 +902,7 @@ struct lpfc_hba {
46790
46791 struct dentry *debug_slow_ring_trc;
46792 struct lpfc_debugfs_trc *slow_ring_trc;
46793- atomic_t slow_ring_trc_cnt;
46794+ atomic_unchecked_t slow_ring_trc_cnt;
46795 /* iDiag debugfs sub-directory */
46796 struct dentry *idiag_root;
46797 struct dentry *idiag_pci_cfg;
46798diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46799index f525ecb..32549a4 100644
46800--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46801+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46802@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46803
46804 #include <linux/debugfs.h>
46805
46806-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46807+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46808 static unsigned long lpfc_debugfs_start_time = 0L;
46809
46810 /* iDiag */
46811@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46812 lpfc_debugfs_enable = 0;
46813
46814 len = 0;
46815- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46816+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46817 (lpfc_debugfs_max_disc_trc - 1);
46818 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46819 dtp = vport->disc_trc + i;
46820@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46821 lpfc_debugfs_enable = 0;
46822
46823 len = 0;
46824- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46825+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46826 (lpfc_debugfs_max_slow_ring_trc - 1);
46827 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46828 dtp = phba->slow_ring_trc + i;
46829@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46830 !vport || !vport->disc_trc)
46831 return;
46832
46833- index = atomic_inc_return(&vport->disc_trc_cnt) &
46834+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46835 (lpfc_debugfs_max_disc_trc - 1);
46836 dtp = vport->disc_trc + index;
46837 dtp->fmt = fmt;
46838 dtp->data1 = data1;
46839 dtp->data2 = data2;
46840 dtp->data3 = data3;
46841- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46842+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46843 dtp->jif = jiffies;
46844 #endif
46845 return;
46846@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46847 !phba || !phba->slow_ring_trc)
46848 return;
46849
46850- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46851+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46852 (lpfc_debugfs_max_slow_ring_trc - 1);
46853 dtp = phba->slow_ring_trc + index;
46854 dtp->fmt = fmt;
46855 dtp->data1 = data1;
46856 dtp->data2 = data2;
46857 dtp->data3 = data3;
46858- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46859+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46860 dtp->jif = jiffies;
46861 #endif
46862 return;
46863@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46864 "slow_ring buffer\n");
46865 goto debug_failed;
46866 }
46867- atomic_set(&phba->slow_ring_trc_cnt, 0);
46868+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46869 memset(phba->slow_ring_trc, 0,
46870 (sizeof(struct lpfc_debugfs_trc) *
46871 lpfc_debugfs_max_slow_ring_trc));
46872@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46873 "buffer\n");
46874 goto debug_failed;
46875 }
46876- atomic_set(&vport->disc_trc_cnt, 0);
46877+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46878
46879 snprintf(name, sizeof(name), "discovery_trace");
46880 vport->debug_disc_trc =
46881diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46882index cb465b2..2e7b25f 100644
46883--- a/drivers/scsi/lpfc/lpfc_init.c
46884+++ b/drivers/scsi/lpfc/lpfc_init.c
46885@@ -10950,8 +10950,10 @@ lpfc_init(void)
46886 "misc_register returned with status %d", error);
46887
46888 if (lpfc_enable_npiv) {
46889- lpfc_transport_functions.vport_create = lpfc_vport_create;
46890- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46891+ pax_open_kernel();
46892+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46893+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46894+ pax_close_kernel();
46895 }
46896 lpfc_transport_template =
46897 fc_attach_transport(&lpfc_transport_functions);
46898diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46899index 8523b278e..ce1d812 100644
46900--- a/drivers/scsi/lpfc/lpfc_scsi.c
46901+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46902@@ -331,7 +331,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46903 uint32_t evt_posted;
46904
46905 spin_lock_irqsave(&phba->hbalock, flags);
46906- atomic_inc(&phba->num_rsrc_err);
46907+ atomic_inc_unchecked(&phba->num_rsrc_err);
46908 phba->last_rsrc_error_time = jiffies;
46909
46910 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46911@@ -372,7 +372,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46912 unsigned long flags;
46913 struct lpfc_hba *phba = vport->phba;
46914 uint32_t evt_posted;
46915- atomic_inc(&phba->num_cmd_success);
46916+ atomic_inc_unchecked(&phba->num_cmd_success);
46917
46918 if (vport->cfg_lun_queue_depth <= queue_depth)
46919 return;
46920@@ -416,8 +416,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46921 unsigned long num_rsrc_err, num_cmd_success;
46922 int i;
46923
46924- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46925- num_cmd_success = atomic_read(&phba->num_cmd_success);
46926+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46927+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46928
46929 /*
46930 * The error and success command counters are global per
46931@@ -445,8 +445,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46932 }
46933 }
46934 lpfc_destroy_vport_work_array(phba, vports);
46935- atomic_set(&phba->num_rsrc_err, 0);
46936- atomic_set(&phba->num_cmd_success, 0);
46937+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46938+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46939 }
46940
46941 /**
46942@@ -480,8 +480,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46943 }
46944 }
46945 lpfc_destroy_vport_work_array(phba, vports);
46946- atomic_set(&phba->num_rsrc_err, 0);
46947- atomic_set(&phba->num_cmd_success, 0);
46948+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46949+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46950 }
46951
46952 /**
46953diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46954index 8e1b737..50ff510 100644
46955--- a/drivers/scsi/pmcraid.c
46956+++ b/drivers/scsi/pmcraid.c
46957@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46958 res->scsi_dev = scsi_dev;
46959 scsi_dev->hostdata = res;
46960 res->change_detected = 0;
46961- atomic_set(&res->read_failures, 0);
46962- atomic_set(&res->write_failures, 0);
46963+ atomic_set_unchecked(&res->read_failures, 0);
46964+ atomic_set_unchecked(&res->write_failures, 0);
46965 rc = 0;
46966 }
46967 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46968@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46969
46970 /* If this was a SCSI read/write command keep count of errors */
46971 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46972- atomic_inc(&res->read_failures);
46973+ atomic_inc_unchecked(&res->read_failures);
46974 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46975- atomic_inc(&res->write_failures);
46976+ atomic_inc_unchecked(&res->write_failures);
46977
46978 if (!RES_IS_GSCSI(res->cfg_entry) &&
46979 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46980@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46981 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46982 * hrrq_id assigned here in queuecommand
46983 */
46984- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46985+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46986 pinstance->num_hrrq;
46987 cmd->cmd_done = pmcraid_io_done;
46988
46989@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46990 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46991 * hrrq_id assigned here in queuecommand
46992 */
46993- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46994+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46995 pinstance->num_hrrq;
46996
46997 if (request_size) {
46998@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46999
47000 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
47001 /* add resources only after host is added into system */
47002- if (!atomic_read(&pinstance->expose_resources))
47003+ if (!atomic_read_unchecked(&pinstance->expose_resources))
47004 return;
47005
47006 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
47007@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
47008 init_waitqueue_head(&pinstance->reset_wait_q);
47009
47010 atomic_set(&pinstance->outstanding_cmds, 0);
47011- atomic_set(&pinstance->last_message_id, 0);
47012- atomic_set(&pinstance->expose_resources, 0);
47013+ atomic_set_unchecked(&pinstance->last_message_id, 0);
47014+ atomic_set_unchecked(&pinstance->expose_resources, 0);
47015
47016 INIT_LIST_HEAD(&pinstance->free_res_q);
47017 INIT_LIST_HEAD(&pinstance->used_res_q);
47018@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
47019 /* Schedule worker thread to handle CCN and take care of adding and
47020 * removing devices to OS
47021 */
47022- atomic_set(&pinstance->expose_resources, 1);
47023+ atomic_set_unchecked(&pinstance->expose_resources, 1);
47024 schedule_work(&pinstance->worker_q);
47025 return rc;
47026
47027diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
47028index e1d150f..6c6df44 100644
47029--- a/drivers/scsi/pmcraid.h
47030+++ b/drivers/scsi/pmcraid.h
47031@@ -748,7 +748,7 @@ struct pmcraid_instance {
47032 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
47033
47034 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
47035- atomic_t last_message_id;
47036+ atomic_unchecked_t last_message_id;
47037
47038 /* configuration table */
47039 struct pmcraid_config_table *cfg_table;
47040@@ -777,7 +777,7 @@ struct pmcraid_instance {
47041 atomic_t outstanding_cmds;
47042
47043 /* should add/delete resources to mid-layer now ?*/
47044- atomic_t expose_resources;
47045+ atomic_unchecked_t expose_resources;
47046
47047
47048
47049@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
47050 struct pmcraid_config_table_entry_ext cfg_entry_ext;
47051 };
47052 struct scsi_device *scsi_dev; /* Link scsi_device structure */
47053- atomic_t read_failures; /* count of failed READ commands */
47054- atomic_t write_failures; /* count of failed WRITE commands */
47055+ atomic_unchecked_t read_failures; /* count of failed READ commands */
47056+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
47057
47058 /* To indicate add/delete/modify during CCN */
47059 u8 change_detected;
47060diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
47061index bf60c63..74d4dce 100644
47062--- a/drivers/scsi/qla2xxx/qla_attr.c
47063+++ b/drivers/scsi/qla2xxx/qla_attr.c
47064@@ -2001,7 +2001,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
47065 return 0;
47066 }
47067
47068-struct fc_function_template qla2xxx_transport_functions = {
47069+fc_function_template_no_const qla2xxx_transport_functions = {
47070
47071 .show_host_node_name = 1,
47072 .show_host_port_name = 1,
47073@@ -2048,7 +2048,7 @@ struct fc_function_template qla2xxx_transport_functions = {
47074 .bsg_timeout = qla24xx_bsg_timeout,
47075 };
47076
47077-struct fc_function_template qla2xxx_transport_vport_functions = {
47078+fc_function_template_no_const qla2xxx_transport_vport_functions = {
47079
47080 .show_host_node_name = 1,
47081 .show_host_port_name = 1,
47082diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
47083index 026bfde..90c4018 100644
47084--- a/drivers/scsi/qla2xxx/qla_gbl.h
47085+++ b/drivers/scsi/qla2xxx/qla_gbl.h
47086@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
47087 struct device_attribute;
47088 extern struct device_attribute *qla2x00_host_attrs[];
47089 struct fc_function_template;
47090-extern struct fc_function_template qla2xxx_transport_functions;
47091-extern struct fc_function_template qla2xxx_transport_vport_functions;
47092+extern fc_function_template_no_const qla2xxx_transport_functions;
47093+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
47094 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
47095 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
47096 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
47097diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
47098index ad72c1d..afc9a98 100644
47099--- a/drivers/scsi/qla2xxx/qla_os.c
47100+++ b/drivers/scsi/qla2xxx/qla_os.c
47101@@ -1571,8 +1571,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
47102 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
47103 /* Ok, a 64bit DMA mask is applicable. */
47104 ha->flags.enable_64bit_addressing = 1;
47105- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47106- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47107+ pax_open_kernel();
47108+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47109+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47110+ pax_close_kernel();
47111 return;
47112 }
47113 }
47114diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
47115index ddf16a8..80f4dd0 100644
47116--- a/drivers/scsi/qla4xxx/ql4_def.h
47117+++ b/drivers/scsi/qla4xxx/ql4_def.h
47118@@ -291,7 +291,7 @@ struct ddb_entry {
47119 * (4000 only) */
47120 atomic_t relogin_timer; /* Max Time to wait for
47121 * relogin to complete */
47122- atomic_t relogin_retry_count; /* Num of times relogin has been
47123+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
47124 * retried */
47125 uint32_t default_time2wait; /* Default Min time between
47126 * relogins (+aens) */
47127diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
47128index 4d231c1..2892c37 100644
47129--- a/drivers/scsi/qla4xxx/ql4_os.c
47130+++ b/drivers/scsi/qla4xxx/ql4_os.c
47131@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
47132 */
47133 if (!iscsi_is_session_online(cls_sess)) {
47134 /* Reset retry relogin timer */
47135- atomic_inc(&ddb_entry->relogin_retry_count);
47136+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
47137 DEBUG2(ql4_printk(KERN_INFO, ha,
47138 "%s: index[%d] relogin timed out-retrying"
47139 " relogin (%d), retry (%d)\n", __func__,
47140 ddb_entry->fw_ddb_index,
47141- atomic_read(&ddb_entry->relogin_retry_count),
47142+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
47143 ddb_entry->default_time2wait + 4));
47144 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
47145 atomic_set(&ddb_entry->retry_relogin_timer,
47146@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
47147
47148 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
47149 atomic_set(&ddb_entry->relogin_timer, 0);
47150- atomic_set(&ddb_entry->relogin_retry_count, 0);
47151+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
47152 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
47153 ddb_entry->default_relogin_timeout =
47154 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
47155diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
47156index eaa808e..95f8841 100644
47157--- a/drivers/scsi/scsi.c
47158+++ b/drivers/scsi/scsi.c
47159@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
47160 unsigned long timeout;
47161 int rtn = 0;
47162
47163- atomic_inc(&cmd->device->iorequest_cnt);
47164+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47165
47166 /* check if the device is still usable */
47167 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
47168diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
47169index 86d5220..f22c51a 100644
47170--- a/drivers/scsi/scsi_lib.c
47171+++ b/drivers/scsi/scsi_lib.c
47172@@ -1458,7 +1458,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
47173 shost = sdev->host;
47174 scsi_init_cmd_errh(cmd);
47175 cmd->result = DID_NO_CONNECT << 16;
47176- atomic_inc(&cmd->device->iorequest_cnt);
47177+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47178
47179 /*
47180 * SCSI request completion path will do scsi_device_unbusy(),
47181@@ -1484,9 +1484,9 @@ static void scsi_softirq_done(struct request *rq)
47182
47183 INIT_LIST_HEAD(&cmd->eh_entry);
47184
47185- atomic_inc(&cmd->device->iodone_cnt);
47186+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
47187 if (cmd->result)
47188- atomic_inc(&cmd->device->ioerr_cnt);
47189+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
47190
47191 disposition = scsi_decide_disposition(cmd);
47192 if (disposition != SUCCESS &&
47193diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
47194index 931a7d9..0c2a754 100644
47195--- a/drivers/scsi/scsi_sysfs.c
47196+++ b/drivers/scsi/scsi_sysfs.c
47197@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
47198 char *buf) \
47199 { \
47200 struct scsi_device *sdev = to_scsi_device(dev); \
47201- unsigned long long count = atomic_read(&sdev->field); \
47202+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
47203 return snprintf(buf, 20, "0x%llx\n", count); \
47204 } \
47205 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
47206diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
47207index 84a1fdf..693b0d6 100644
47208--- a/drivers/scsi/scsi_tgt_lib.c
47209+++ b/drivers/scsi/scsi_tgt_lib.c
47210@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
47211 int err;
47212
47213 dprintk("%lx %u\n", uaddr, len);
47214- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
47215+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
47216 if (err) {
47217 /*
47218 * TODO: need to fixup sg_tablesize, max_segment_size,
47219diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
47220index e106c27..11a380e 100644
47221--- a/drivers/scsi/scsi_transport_fc.c
47222+++ b/drivers/scsi/scsi_transport_fc.c
47223@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
47224 * Netlink Infrastructure
47225 */
47226
47227-static atomic_t fc_event_seq;
47228+static atomic_unchecked_t fc_event_seq;
47229
47230 /**
47231 * fc_get_event_number - Obtain the next sequential FC event number
47232@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
47233 u32
47234 fc_get_event_number(void)
47235 {
47236- return atomic_add_return(1, &fc_event_seq);
47237+ return atomic_add_return_unchecked(1, &fc_event_seq);
47238 }
47239 EXPORT_SYMBOL(fc_get_event_number);
47240
47241@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
47242 {
47243 int error;
47244
47245- atomic_set(&fc_event_seq, 0);
47246+ atomic_set_unchecked(&fc_event_seq, 0);
47247
47248 error = transport_class_register(&fc_host_class);
47249 if (error)
47250@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
47251 char *cp;
47252
47253 *val = simple_strtoul(buf, &cp, 0);
47254- if ((*cp && (*cp != '\n')) || (*val < 0))
47255+ if (*cp && (*cp != '\n'))
47256 return -EINVAL;
47257 /*
47258 * Check for overflow; dev_loss_tmo is u32
47259diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
47260index 133926b..903000d 100644
47261--- a/drivers/scsi/scsi_transport_iscsi.c
47262+++ b/drivers/scsi/scsi_transport_iscsi.c
47263@@ -80,7 +80,7 @@ struct iscsi_internal {
47264 struct transport_container session_cont;
47265 };
47266
47267-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
47268+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
47269 static struct workqueue_struct *iscsi_eh_timer_workq;
47270
47271 static DEFINE_IDA(iscsi_sess_ida);
47272@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
47273 int err;
47274
47275 ihost = shost->shost_data;
47276- session->sid = atomic_add_return(1, &iscsi_session_nr);
47277+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
47278
47279 if (target_id == ISCSI_MAX_TARGET) {
47280 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
47281@@ -3944,7 +3944,7 @@ static __init int iscsi_transport_init(void)
47282 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
47283 ISCSI_TRANSPORT_VERSION);
47284
47285- atomic_set(&iscsi_session_nr, 0);
47286+ atomic_set_unchecked(&iscsi_session_nr, 0);
47287
47288 err = class_register(&iscsi_transport_class);
47289 if (err)
47290diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
47291index f379c7f..e8fc69c 100644
47292--- a/drivers/scsi/scsi_transport_srp.c
47293+++ b/drivers/scsi/scsi_transport_srp.c
47294@@ -33,7 +33,7 @@
47295 #include "scsi_transport_srp_internal.h"
47296
47297 struct srp_host_attrs {
47298- atomic_t next_port_id;
47299+ atomic_unchecked_t next_port_id;
47300 };
47301 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47302
47303@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47304 struct Scsi_Host *shost = dev_to_shost(dev);
47305 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47306
47307- atomic_set(&srp_host->next_port_id, 0);
47308+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47309 return 0;
47310 }
47311
47312@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47313 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47314 rport->roles = ids->roles;
47315
47316- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47317+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47318 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47319
47320 transport_setup_device(&rport->dev);
47321diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47322index 610417e..167c46c 100644
47323--- a/drivers/scsi/sd.c
47324+++ b/drivers/scsi/sd.c
47325@@ -2928,7 +2928,7 @@ static int sd_probe(struct device *dev)
47326 sdkp->disk = gd;
47327 sdkp->index = index;
47328 atomic_set(&sdkp->openers, 0);
47329- atomic_set(&sdkp->device->ioerr_cnt, 0);
47330+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47331
47332 if (!sdp->request_queue->rq_timeout) {
47333 if (sdp->type != TYPE_MOD)
47334@@ -2941,7 +2941,7 @@ static int sd_probe(struct device *dev)
47335 device_initialize(&sdkp->dev);
47336 sdkp->dev.parent = dev;
47337 sdkp->dev.class = &sd_disk_class;
47338- dev_set_name(&sdkp->dev, dev_name(dev));
47339+ dev_set_name(&sdkp->dev, "%s", dev_name(dev));
47340
47341 if (device_add(&sdkp->dev))
47342 goto out_free_index;
47343diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47344index df5e961..df6b97f 100644
47345--- a/drivers/scsi/sg.c
47346+++ b/drivers/scsi/sg.c
47347@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47348 sdp->disk->disk_name,
47349 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47350 NULL,
47351- (char *)arg);
47352+ (char __user *)arg);
47353 case BLKTRACESTART:
47354 return blk_trace_startstop(sdp->device->request_queue, 1);
47355 case BLKTRACESTOP:
47356diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47357index 32b7bb1..2f1c4bd 100644
47358--- a/drivers/spi/spi.c
47359+++ b/drivers/spi/spi.c
47360@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
47361 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47362
47363 /* portable code must never pass more than 32 bytes */
47364-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47365+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47366
47367 static u8 *buf;
47368
47369diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47370index ec9e2ae..cd15d67 100644
47371--- a/drivers/staging/android/timed_output.c
47372+++ b/drivers/staging/android/timed_output.c
47373@@ -25,7 +25,7 @@
47374 #include "timed_output.h"
47375
47376 static struct class *timed_output_class;
47377-static atomic_t device_count;
47378+static atomic_unchecked_t device_count;
47379
47380 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47381 char *buf)
47382@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
47383 timed_output_class = class_create(THIS_MODULE, "timed_output");
47384 if (IS_ERR(timed_output_class))
47385 return PTR_ERR(timed_output_class);
47386- atomic_set(&device_count, 0);
47387+ atomic_set_unchecked(&device_count, 0);
47388 }
47389
47390 return 0;
47391@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47392 if (ret < 0)
47393 return ret;
47394
47395- tdev->index = atomic_inc_return(&device_count);
47396+ tdev->index = atomic_inc_return_unchecked(&device_count);
47397 tdev->dev = device_create(timed_output_class, NULL,
47398 MKDEV(0, tdev->index), NULL, tdev->name);
47399 if (IS_ERR(tdev->dev))
47400diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47401index 3675020..e80d92c 100644
47402--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47403+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47404@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47405
47406 static int solo_sysfs_init(struct solo_dev *solo_dev)
47407 {
47408- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47409+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47410 struct device *dev = &solo_dev->dev;
47411 const char *driver;
47412 int i;
47413diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47414index 3335941..2b26186 100644
47415--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47416+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47417@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47418
47419 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47420 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47421- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47422+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47423 if (p2m_id < 0)
47424 p2m_id = -p2m_id;
47425 }
47426diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47427index 6f91d2e..3f011d2 100644
47428--- a/drivers/staging/media/solo6x10/solo6x10.h
47429+++ b/drivers/staging/media/solo6x10/solo6x10.h
47430@@ -238,7 +238,7 @@ struct solo_dev {
47431
47432 /* P2M DMA Engine */
47433 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47434- atomic_t p2m_count;
47435+ atomic_unchecked_t p2m_count;
47436 int p2m_jiffies;
47437 unsigned int p2m_timeouts;
47438
47439diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47440index 34afc16..ffe44dd 100644
47441--- a/drivers/staging/octeon/ethernet-rx.c
47442+++ b/drivers/staging/octeon/ethernet-rx.c
47443@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47444 /* Increment RX stats for virtual ports */
47445 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47446 #ifdef CONFIG_64BIT
47447- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47448- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47449+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47450+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47451 #else
47452- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47453- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47454+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47455+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47456 #endif
47457 }
47458 netif_receive_skb(skb);
47459@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47460 dev->name);
47461 */
47462 #ifdef CONFIG_64BIT
47463- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47464+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47465 #else
47466- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47467+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47468 #endif
47469 dev_kfree_skb_irq(skb);
47470 }
47471diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47472index c3a90e7..023619a 100644
47473--- a/drivers/staging/octeon/ethernet.c
47474+++ b/drivers/staging/octeon/ethernet.c
47475@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47476 * since the RX tasklet also increments it.
47477 */
47478 #ifdef CONFIG_64BIT
47479- atomic64_add(rx_status.dropped_packets,
47480- (atomic64_t *)&priv->stats.rx_dropped);
47481+ atomic64_add_unchecked(rx_status.dropped_packets,
47482+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47483 #else
47484- atomic_add(rx_status.dropped_packets,
47485- (atomic_t *)&priv->stats.rx_dropped);
47486+ atomic_add_unchecked(rx_status.dropped_packets,
47487+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47488 #endif
47489 }
47490
47491diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47492index dc23395..cf7e9b1 100644
47493--- a/drivers/staging/rtl8712/rtl871x_io.h
47494+++ b/drivers/staging/rtl8712/rtl871x_io.h
47495@@ -108,7 +108,7 @@ struct _io_ops {
47496 u8 *pmem);
47497 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47498 u8 *pmem);
47499-};
47500+} __no_const;
47501
47502 struct io_req {
47503 struct list_head list;
47504diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47505index 1f5088b..0e59820 100644
47506--- a/drivers/staging/sbe-2t3e3/netdev.c
47507+++ b/drivers/staging/sbe-2t3e3/netdev.c
47508@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47509 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47510
47511 if (rlen)
47512- if (copy_to_user(data, &resp, rlen))
47513+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47514 return -EFAULT;
47515
47516 return 0;
47517diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47518index a863a98..d272795 100644
47519--- a/drivers/staging/usbip/vhci.h
47520+++ b/drivers/staging/usbip/vhci.h
47521@@ -83,7 +83,7 @@ struct vhci_hcd {
47522 unsigned resuming:1;
47523 unsigned long re_timeout;
47524
47525- atomic_t seqnum;
47526+ atomic_unchecked_t seqnum;
47527
47528 /*
47529 * NOTE:
47530diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47531index d7974cb..d78076b 100644
47532--- a/drivers/staging/usbip/vhci_hcd.c
47533+++ b/drivers/staging/usbip/vhci_hcd.c
47534@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47535
47536 spin_lock(&vdev->priv_lock);
47537
47538- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47539+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47540 if (priv->seqnum == 0xffff)
47541 dev_info(&urb->dev->dev, "seqnum max\n");
47542
47543@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47544 return -ENOMEM;
47545 }
47546
47547- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47548+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47549 if (unlink->seqnum == 0xffff)
47550 pr_info("seqnum max\n");
47551
47552@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47553 vdev->rhport = rhport;
47554 }
47555
47556- atomic_set(&vhci->seqnum, 0);
47557+ atomic_set_unchecked(&vhci->seqnum, 0);
47558 spin_lock_init(&vhci->lock);
47559
47560 hcd->power_budget = 0; /* no limit */
47561diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47562index d07fcb5..358e1e1 100644
47563--- a/drivers/staging/usbip/vhci_rx.c
47564+++ b/drivers/staging/usbip/vhci_rx.c
47565@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47566 if (!urb) {
47567 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47568 pr_info("max seqnum %d\n",
47569- atomic_read(&the_controller->seqnum));
47570+ atomic_read_unchecked(&the_controller->seqnum));
47571 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47572 return;
47573 }
47574diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47575index 8417c2f..ef5ebd6 100644
47576--- a/drivers/staging/vt6655/hostap.c
47577+++ b/drivers/staging/vt6655/hostap.c
47578@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47579 *
47580 */
47581
47582+static net_device_ops_no_const apdev_netdev_ops;
47583+
47584 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47585 {
47586 PSDevice apdev_priv;
47587 struct net_device *dev = pDevice->dev;
47588 int ret;
47589- const struct net_device_ops apdev_netdev_ops = {
47590- .ndo_start_xmit = pDevice->tx_80211,
47591- };
47592
47593 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47594
47595@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47596 *apdev_priv = *pDevice;
47597 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47598
47599+ /* only half broken now */
47600+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47601 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47602
47603 pDevice->apdev->type = ARPHRD_IEEE80211;
47604diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47605index c699a30..b90a5fd 100644
47606--- a/drivers/staging/vt6656/hostap.c
47607+++ b/drivers/staging/vt6656/hostap.c
47608@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47609 *
47610 */
47611
47612+static net_device_ops_no_const apdev_netdev_ops;
47613+
47614 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47615 {
47616 struct vnt_private *apdev_priv;
47617 struct net_device *dev = pDevice->dev;
47618 int ret;
47619- const struct net_device_ops apdev_netdev_ops = {
47620- .ndo_start_xmit = pDevice->tx_80211,
47621- };
47622
47623 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47624
47625@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47626 *apdev_priv = *pDevice;
47627 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47628
47629+ /* only half broken now */
47630+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47631 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47632
47633 pDevice->apdev->type = ARPHRD_IEEE80211;
47634diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47635index d128ce2..fc1f9a1 100644
47636--- a/drivers/staging/zcache/tmem.h
47637+++ b/drivers/staging/zcache/tmem.h
47638@@ -225,7 +225,7 @@ struct tmem_pamops {
47639 bool (*is_remote)(void *);
47640 int (*replace_in_obj)(void *, struct tmem_obj *);
47641 #endif
47642-};
47643+} __no_const;
47644 extern void tmem_register_pamops(struct tmem_pamops *m);
47645
47646 /* memory allocation methods provided by the host implementation */
47647@@ -234,7 +234,7 @@ struct tmem_hostops {
47648 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47649 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47650 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47651-};
47652+} __no_const;
47653 extern void tmem_register_hostops(struct tmem_hostops *m);
47654
47655 /* core tmem accessor functions */
47656diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47657index d3536f5..a0c2ce9 100644
47658--- a/drivers/target/sbp/sbp_target.c
47659+++ b/drivers/target/sbp/sbp_target.c
47660@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47661
47662 #define SESSION_MAINTENANCE_INTERVAL HZ
47663
47664-static atomic_t login_id = ATOMIC_INIT(0);
47665+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47666
47667 static void session_maintenance_work(struct work_struct *);
47668 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47669@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47670 login->lun = se_lun;
47671 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47672 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47673- login->login_id = atomic_inc_return(&login_id);
47674+ login->login_id = atomic_inc_return_unchecked(&login_id);
47675
47676 login->tgt_agt = sbp_target_agent_register(login);
47677 if (IS_ERR(login->tgt_agt)) {
47678diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47679index 4630481..c26782a 100644
47680--- a/drivers/target/target_core_device.c
47681+++ b/drivers/target/target_core_device.c
47682@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47683 spin_lock_init(&dev->se_port_lock);
47684 spin_lock_init(&dev->se_tmr_lock);
47685 spin_lock_init(&dev->qf_cmd_lock);
47686- atomic_set(&dev->dev_ordered_id, 0);
47687+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47688 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47689 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47690 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47691diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47692index 21e3158..43c6004 100644
47693--- a/drivers/target/target_core_transport.c
47694+++ b/drivers/target/target_core_transport.c
47695@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47696 * Used to determine when ORDERED commands should go from
47697 * Dormant to Active status.
47698 */
47699- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47700+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47701 smp_mb__after_atomic_inc();
47702 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47703 cmd->se_ordered_id, cmd->sam_task_attr,
47704diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47705index 33f83fe..d80f8e1 100644
47706--- a/drivers/tty/cyclades.c
47707+++ b/drivers/tty/cyclades.c
47708@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47709 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47710 info->port.count);
47711 #endif
47712- info->port.count++;
47713+ atomic_inc(&info->port.count);
47714 #ifdef CY_DEBUG_COUNT
47715 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47716- current->pid, info->port.count);
47717+ current->pid, atomic_read(&info->port.count));
47718 #endif
47719
47720 /*
47721@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47722 for (j = 0; j < cy_card[i].nports; j++) {
47723 info = &cy_card[i].ports[j];
47724
47725- if (info->port.count) {
47726+ if (atomic_read(&info->port.count)) {
47727 /* XXX is the ldisc num worth this? */
47728 struct tty_struct *tty;
47729 struct tty_ldisc *ld;
47730diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47731index eb255e8..f637a57 100644
47732--- a/drivers/tty/hvc/hvc_console.c
47733+++ b/drivers/tty/hvc/hvc_console.c
47734@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47735
47736 spin_lock_irqsave(&hp->port.lock, flags);
47737 /* Check and then increment for fast path open. */
47738- if (hp->port.count++ > 0) {
47739+ if (atomic_inc_return(&hp->port.count) > 1) {
47740 spin_unlock_irqrestore(&hp->port.lock, flags);
47741 hvc_kick();
47742 return 0;
47743@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47744
47745 spin_lock_irqsave(&hp->port.lock, flags);
47746
47747- if (--hp->port.count == 0) {
47748+ if (atomic_dec_return(&hp->port.count) == 0) {
47749 spin_unlock_irqrestore(&hp->port.lock, flags);
47750 /* We are done with the tty pointer now. */
47751 tty_port_tty_set(&hp->port, NULL);
47752@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47753 */
47754 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47755 } else {
47756- if (hp->port.count < 0)
47757+ if (atomic_read(&hp->port.count) < 0)
47758 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47759- hp->vtermno, hp->port.count);
47760+ hp->vtermno, atomic_read(&hp->port.count));
47761 spin_unlock_irqrestore(&hp->port.lock, flags);
47762 }
47763 }
47764@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47765 * open->hangup case this can be called after the final close so prevent
47766 * that from happening for now.
47767 */
47768- if (hp->port.count <= 0) {
47769+ if (atomic_read(&hp->port.count) <= 0) {
47770 spin_unlock_irqrestore(&hp->port.lock, flags);
47771 return;
47772 }
47773
47774- hp->port.count = 0;
47775+ atomic_set(&hp->port.count, 0);
47776 spin_unlock_irqrestore(&hp->port.lock, flags);
47777 tty_port_tty_set(&hp->port, NULL);
47778
47779@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47780 return -EPIPE;
47781
47782 /* FIXME what's this (unprotected) check for? */
47783- if (hp->port.count <= 0)
47784+ if (atomic_read(&hp->port.count) <= 0)
47785 return -EIO;
47786
47787 spin_lock_irqsave(&hp->lock, flags);
47788diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47789index 81e939e..95ead10 100644
47790--- a/drivers/tty/hvc/hvcs.c
47791+++ b/drivers/tty/hvc/hvcs.c
47792@@ -83,6 +83,7 @@
47793 #include <asm/hvcserver.h>
47794 #include <asm/uaccess.h>
47795 #include <asm/vio.h>
47796+#include <asm/local.h>
47797
47798 /*
47799 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47800@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47801
47802 spin_lock_irqsave(&hvcsd->lock, flags);
47803
47804- if (hvcsd->port.count > 0) {
47805+ if (atomic_read(&hvcsd->port.count) > 0) {
47806 spin_unlock_irqrestore(&hvcsd->lock, flags);
47807 printk(KERN_INFO "HVCS: vterm state unchanged. "
47808 "The hvcs device node is still in use.\n");
47809@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47810 }
47811 }
47812
47813- hvcsd->port.count = 0;
47814+ atomic_set(&hvcsd->port.count, 0);
47815 hvcsd->port.tty = tty;
47816 tty->driver_data = hvcsd;
47817
47818@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47819 unsigned long flags;
47820
47821 spin_lock_irqsave(&hvcsd->lock, flags);
47822- hvcsd->port.count++;
47823+ atomic_inc(&hvcsd->port.count);
47824 hvcsd->todo_mask |= HVCS_SCHED_READ;
47825 spin_unlock_irqrestore(&hvcsd->lock, flags);
47826
47827@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47828 hvcsd = tty->driver_data;
47829
47830 spin_lock_irqsave(&hvcsd->lock, flags);
47831- if (--hvcsd->port.count == 0) {
47832+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47833
47834 vio_disable_interrupts(hvcsd->vdev);
47835
47836@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47837
47838 free_irq(irq, hvcsd);
47839 return;
47840- } else if (hvcsd->port.count < 0) {
47841+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47842 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47843 " is missmanaged.\n",
47844- hvcsd->vdev->unit_address, hvcsd->port.count);
47845+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47846 }
47847
47848 spin_unlock_irqrestore(&hvcsd->lock, flags);
47849@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47850
47851 spin_lock_irqsave(&hvcsd->lock, flags);
47852 /* Preserve this so that we know how many kref refs to put */
47853- temp_open_count = hvcsd->port.count;
47854+ temp_open_count = atomic_read(&hvcsd->port.count);
47855
47856 /*
47857 * Don't kref put inside the spinlock because the destruction
47858@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47859 tty->driver_data = NULL;
47860 hvcsd->port.tty = NULL;
47861
47862- hvcsd->port.count = 0;
47863+ atomic_set(&hvcsd->port.count, 0);
47864
47865 /* This will drop any buffered data on the floor which is OK in a hangup
47866 * scenario. */
47867@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47868 * the middle of a write operation? This is a crummy place to do this
47869 * but we want to keep it all in the spinlock.
47870 */
47871- if (hvcsd->port.count <= 0) {
47872+ if (atomic_read(&hvcsd->port.count) <= 0) {
47873 spin_unlock_irqrestore(&hvcsd->lock, flags);
47874 return -ENODEV;
47875 }
47876@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47877 {
47878 struct hvcs_struct *hvcsd = tty->driver_data;
47879
47880- if (!hvcsd || hvcsd->port.count <= 0)
47881+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47882 return 0;
47883
47884 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47885diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47886index 4190199..48f2920 100644
47887--- a/drivers/tty/hvc/hvsi.c
47888+++ b/drivers/tty/hvc/hvsi.c
47889@@ -85,7 +85,7 @@ struct hvsi_struct {
47890 int n_outbuf;
47891 uint32_t vtermno;
47892 uint32_t virq;
47893- atomic_t seqno; /* HVSI packet sequence number */
47894+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47895 uint16_t mctrl;
47896 uint8_t state; /* HVSI protocol state */
47897 uint8_t flags;
47898@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47899
47900 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47901 packet.hdr.len = sizeof(struct hvsi_query_response);
47902- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47903+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47904 packet.verb = VSV_SEND_VERSION_NUMBER;
47905 packet.u.version = HVSI_VERSION;
47906 packet.query_seqno = query_seqno+1;
47907@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47908
47909 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47910 packet.hdr.len = sizeof(struct hvsi_query);
47911- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47912+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47913 packet.verb = verb;
47914
47915 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47916@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47917 int wrote;
47918
47919 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47920- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47921+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47922 packet.hdr.len = sizeof(struct hvsi_control);
47923 packet.verb = VSV_SET_MODEM_CTL;
47924 packet.mask = HVSI_TSDTR;
47925@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47926 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47927
47928 packet.hdr.type = VS_DATA_PACKET_HEADER;
47929- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47930+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47931 packet.hdr.len = count + sizeof(struct hvsi_header);
47932 memcpy(&packet.data, buf, count);
47933
47934@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47935 struct hvsi_control packet __ALIGNED__;
47936
47937 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47938- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47939+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47940 packet.hdr.len = 6;
47941 packet.verb = VSV_CLOSE_PROTOCOL;
47942
47943diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47944index ac27671..0f627ee 100644
47945--- a/drivers/tty/hvc/hvsi_lib.c
47946+++ b/drivers/tty/hvc/hvsi_lib.c
47947@@ -9,7 +9,7 @@
47948
47949 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47950 {
47951- packet->seqno = atomic_inc_return(&pv->seqno);
47952+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47953
47954 /* Assumes that always succeeds, works in practice */
47955 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47956@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47957
47958 /* Reset state */
47959 pv->established = 0;
47960- atomic_set(&pv->seqno, 0);
47961+ atomic_set_unchecked(&pv->seqno, 0);
47962
47963 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47964
47965@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47966 pv->mctrl_update = 0;
47967 q.hdr.type = VS_QUERY_PACKET_HEADER;
47968 q.hdr.len = sizeof(struct hvsi_query);
47969- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47970+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47971 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47972 rc = hvsi_send_packet(pv, &q.hdr);
47973 if (rc <= 0) {
47974diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47975index 8fd72ff..34a0bed 100644
47976--- a/drivers/tty/ipwireless/tty.c
47977+++ b/drivers/tty/ipwireless/tty.c
47978@@ -29,6 +29,7 @@
47979 #include <linux/tty_driver.h>
47980 #include <linux/tty_flip.h>
47981 #include <linux/uaccess.h>
47982+#include <asm/local.h>
47983
47984 #include "tty.h"
47985 #include "network.h"
47986@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47987 mutex_unlock(&tty->ipw_tty_mutex);
47988 return -ENODEV;
47989 }
47990- if (tty->port.count == 0)
47991+ if (atomic_read(&tty->port.count) == 0)
47992 tty->tx_bytes_queued = 0;
47993
47994- tty->port.count++;
47995+ atomic_inc(&tty->port.count);
47996
47997 tty->port.tty = linux_tty;
47998 linux_tty->driver_data = tty;
47999@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
48000
48001 static void do_ipw_close(struct ipw_tty *tty)
48002 {
48003- tty->port.count--;
48004-
48005- if (tty->port.count == 0) {
48006+ if (atomic_dec_return(&tty->port.count) == 0) {
48007 struct tty_struct *linux_tty = tty->port.tty;
48008
48009 if (linux_tty != NULL) {
48010@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
48011 return;
48012
48013 mutex_lock(&tty->ipw_tty_mutex);
48014- if (tty->port.count == 0) {
48015+ if (atomic_read(&tty->port.count) == 0) {
48016 mutex_unlock(&tty->ipw_tty_mutex);
48017 return;
48018 }
48019@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
48020
48021 mutex_lock(&tty->ipw_tty_mutex);
48022
48023- if (!tty->port.count) {
48024+ if (!atomic_read(&tty->port.count)) {
48025 mutex_unlock(&tty->ipw_tty_mutex);
48026 return;
48027 }
48028@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
48029 return -ENODEV;
48030
48031 mutex_lock(&tty->ipw_tty_mutex);
48032- if (!tty->port.count) {
48033+ if (!atomic_read(&tty->port.count)) {
48034 mutex_unlock(&tty->ipw_tty_mutex);
48035 return -EINVAL;
48036 }
48037@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
48038 if (!tty)
48039 return -ENODEV;
48040
48041- if (!tty->port.count)
48042+ if (!atomic_read(&tty->port.count))
48043 return -EINVAL;
48044
48045 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
48046@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
48047 if (!tty)
48048 return 0;
48049
48050- if (!tty->port.count)
48051+ if (!atomic_read(&tty->port.count))
48052 return 0;
48053
48054 return tty->tx_bytes_queued;
48055@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
48056 if (!tty)
48057 return -ENODEV;
48058
48059- if (!tty->port.count)
48060+ if (!atomic_read(&tty->port.count))
48061 return -EINVAL;
48062
48063 return get_control_lines(tty);
48064@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
48065 if (!tty)
48066 return -ENODEV;
48067
48068- if (!tty->port.count)
48069+ if (!atomic_read(&tty->port.count))
48070 return -EINVAL;
48071
48072 return set_control_lines(tty, set, clear);
48073@@ -399,7 +398,7 @@ static int ipw_ioctl(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 /* FIXME: Exactly how is the tty object locked here .. */
48082@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
48083 * are gone */
48084 mutex_lock(&ttyj->ipw_tty_mutex);
48085 }
48086- while (ttyj->port.count)
48087+ while (atomic_read(&ttyj->port.count))
48088 do_ipw_close(ttyj);
48089 ipwireless_disassociate_network_ttys(network,
48090 ttyj->channel_idx);
48091diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
48092index 1deaca4..c8582d4 100644
48093--- a/drivers/tty/moxa.c
48094+++ b/drivers/tty/moxa.c
48095@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
48096 }
48097
48098 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
48099- ch->port.count++;
48100+ atomic_inc(&ch->port.count);
48101 tty->driver_data = ch;
48102 tty_port_tty_set(&ch->port, tty);
48103 mutex_lock(&ch->port.mutex);
48104diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
48105index 6422390..49003ac8 100644
48106--- a/drivers/tty/n_gsm.c
48107+++ b/drivers/tty/n_gsm.c
48108@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
48109 spin_lock_init(&dlci->lock);
48110 mutex_init(&dlci->mutex);
48111 dlci->fifo = &dlci->_fifo;
48112- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
48113+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
48114 kfree(dlci);
48115 return NULL;
48116 }
48117@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
48118 struct gsm_dlci *dlci = tty->driver_data;
48119 struct tty_port *port = &dlci->port;
48120
48121- port->count++;
48122+ atomic_inc(&port->count);
48123 dlci_get(dlci);
48124 dlci_get(dlci->gsm->dlci[0]);
48125 mux_get(dlci->gsm);
48126diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
48127index 6c7fe90..9241dab 100644
48128--- a/drivers/tty/n_tty.c
48129+++ b/drivers/tty/n_tty.c
48130@@ -2203,6 +2203,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
48131 {
48132 *ops = tty_ldisc_N_TTY;
48133 ops->owner = NULL;
48134- ops->refcount = ops->flags = 0;
48135+ atomic_set(&ops->refcount, 0);
48136+ ops->flags = 0;
48137 }
48138 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
48139diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
48140index abfd990..5ab5da9 100644
48141--- a/drivers/tty/pty.c
48142+++ b/drivers/tty/pty.c
48143@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
48144 panic("Couldn't register Unix98 pts driver");
48145
48146 /* Now create the /dev/ptmx special device */
48147+ pax_open_kernel();
48148 tty_default_fops(&ptmx_fops);
48149- ptmx_fops.open = ptmx_open;
48150+ *(void **)&ptmx_fops.open = ptmx_open;
48151+ pax_close_kernel();
48152
48153 cdev_init(&ptmx_cdev, &ptmx_fops);
48154 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
48155diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
48156index 354564e..fe50d9a 100644
48157--- a/drivers/tty/rocket.c
48158+++ b/drivers/tty/rocket.c
48159@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48160 tty->driver_data = info;
48161 tty_port_tty_set(port, tty);
48162
48163- if (port->count++ == 0) {
48164+ if (atomic_inc_return(&port->count) == 1) {
48165 atomic_inc(&rp_num_ports_open);
48166
48167 #ifdef ROCKET_DEBUG_OPEN
48168@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48169 #endif
48170 }
48171 #ifdef ROCKET_DEBUG_OPEN
48172- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
48173+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
48174 #endif
48175
48176 /*
48177@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
48178 spin_unlock_irqrestore(&info->port.lock, flags);
48179 return;
48180 }
48181- if (info->port.count)
48182+ if (atomic_read(&info->port.count))
48183 atomic_dec(&rp_num_ports_open);
48184 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
48185 spin_unlock_irqrestore(&info->port.lock, flags);
48186diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
48187index e2520ab..034e20b 100644
48188--- a/drivers/tty/serial/ioc4_serial.c
48189+++ b/drivers/tty/serial/ioc4_serial.c
48190@@ -437,7 +437,7 @@ struct ioc4_soft {
48191 } is_intr_info[MAX_IOC4_INTR_ENTS];
48192
48193 /* Number of entries active in the above array */
48194- atomic_t is_num_intrs;
48195+ atomic_unchecked_t is_num_intrs;
48196 } is_intr_type[IOC4_NUM_INTR_TYPES];
48197
48198 /* is_ir_lock must be held while
48199@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
48200 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
48201 || (type == IOC4_OTHER_INTR_TYPE)));
48202
48203- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
48204+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
48205 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
48206
48207 /* Save off the lower level interrupt handler */
48208@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
48209
48210 soft = arg;
48211 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
48212- num_intrs = (int)atomic_read(
48213+ num_intrs = (int)atomic_read_unchecked(
48214 &soft->is_intr_type[intr_type].is_num_intrs);
48215
48216 this_mir = this_ir = pending_intrs(soft, intr_type);
48217diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
48218index 1002054..dd644a8 100644
48219--- a/drivers/tty/serial/kgdboc.c
48220+++ b/drivers/tty/serial/kgdboc.c
48221@@ -24,8 +24,9 @@
48222 #define MAX_CONFIG_LEN 40
48223
48224 static struct kgdb_io kgdboc_io_ops;
48225+static struct kgdb_io kgdboc_io_ops_console;
48226
48227-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
48228+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
48229 static int configured = -1;
48230
48231 static char config[MAX_CONFIG_LEN];
48232@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
48233 kgdboc_unregister_kbd();
48234 if (configured == 1)
48235 kgdb_unregister_io_module(&kgdboc_io_ops);
48236+ else if (configured == 2)
48237+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
48238 }
48239
48240 static int configure_kgdboc(void)
48241@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
48242 int err;
48243 char *cptr = config;
48244 struct console *cons;
48245+ int is_console = 0;
48246
48247 err = kgdboc_option_setup(config);
48248 if (err || !strlen(config) || isspace(config[0]))
48249 goto noconfig;
48250
48251 err = -ENODEV;
48252- kgdboc_io_ops.is_console = 0;
48253 kgdb_tty_driver = NULL;
48254
48255 kgdboc_use_kms = 0;
48256@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
48257 int idx;
48258 if (cons->device && cons->device(cons, &idx) == p &&
48259 idx == tty_line) {
48260- kgdboc_io_ops.is_console = 1;
48261+ is_console = 1;
48262 break;
48263 }
48264 cons = cons->next;
48265@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
48266 kgdb_tty_line = tty_line;
48267
48268 do_register:
48269- err = kgdb_register_io_module(&kgdboc_io_ops);
48270+ if (is_console) {
48271+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
48272+ configured = 2;
48273+ } else {
48274+ err = kgdb_register_io_module(&kgdboc_io_ops);
48275+ configured = 1;
48276+ }
48277 if (err)
48278 goto noconfig;
48279
48280@@ -205,8 +214,6 @@ do_register:
48281 if (err)
48282 goto nmi_con_failed;
48283
48284- configured = 1;
48285-
48286 return 0;
48287
48288 nmi_con_failed:
48289@@ -223,7 +230,7 @@ noconfig:
48290 static int __init init_kgdboc(void)
48291 {
48292 /* Already configured? */
48293- if (configured == 1)
48294+ if (configured >= 1)
48295 return 0;
48296
48297 return configure_kgdboc();
48298@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
48299 if (config[len - 1] == '\n')
48300 config[len - 1] = '\0';
48301
48302- if (configured == 1)
48303+ if (configured >= 1)
48304 cleanup_kgdboc();
48305
48306 /* Go and configure with the new params. */
48307@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
48308 .post_exception = kgdboc_post_exp_handler,
48309 };
48310
48311+static struct kgdb_io kgdboc_io_ops_console = {
48312+ .name = "kgdboc",
48313+ .read_char = kgdboc_get_char,
48314+ .write_char = kgdboc_put_char,
48315+ .pre_exception = kgdboc_pre_exp_handler,
48316+ .post_exception = kgdboc_post_exp_handler,
48317+ .is_console = 1
48318+};
48319+
48320 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48321 /* This is only available if kgdboc is a built in for early debugging */
48322 static int __init kgdboc_early_init(char *opt)
48323diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48324index b11e997..6d25a3b 100644
48325--- a/drivers/tty/serial/msm_serial.c
48326+++ b/drivers/tty/serial/msm_serial.c
48327@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
48328 .cons = MSM_CONSOLE,
48329 };
48330
48331-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48332+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48333
48334 static int __init msm_serial_probe(struct platform_device *pdev)
48335 {
48336@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48337 int irq;
48338
48339 if (pdev->id == -1)
48340- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48341+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48342
48343 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48344 return -ENXIO;
48345diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48346index 0c8a9fa..234a95f 100644
48347--- a/drivers/tty/serial/samsung.c
48348+++ b/drivers/tty/serial/samsung.c
48349@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48350 }
48351 }
48352
48353+static int s3c64xx_serial_startup(struct uart_port *port);
48354 static int s3c24xx_serial_startup(struct uart_port *port)
48355 {
48356 struct s3c24xx_uart_port *ourport = to_ourport(port);
48357 int ret;
48358
48359+ /* Startup sequence is different for s3c64xx and higher SoC's */
48360+ if (s3c24xx_serial_has_interrupt_mask(port))
48361+ return s3c64xx_serial_startup(port);
48362+
48363 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48364 port->mapbase, port->membase);
48365
48366@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48367 /* setup info for port */
48368 port->dev = &platdev->dev;
48369
48370- /* Startup sequence is different for s3c64xx and higher SoC's */
48371- if (s3c24xx_serial_has_interrupt_mask(port))
48372- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48373-
48374 port->uartclk = 1;
48375
48376 if (cfg->uart_flags & UPF_CONS_FLOW) {
48377diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48378index f87dbfd..42ad4b1 100644
48379--- a/drivers/tty/serial/serial_core.c
48380+++ b/drivers/tty/serial/serial_core.c
48381@@ -1454,7 +1454,7 @@ static void uart_hangup(struct tty_struct *tty)
48382 uart_flush_buffer(tty);
48383 uart_shutdown(tty, state);
48384 spin_lock_irqsave(&port->lock, flags);
48385- port->count = 0;
48386+ atomic_set(&port->count, 0);
48387 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48388 spin_unlock_irqrestore(&port->lock, flags);
48389 tty_port_tty_set(port, NULL);
48390@@ -1550,7 +1550,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48391 goto end;
48392 }
48393
48394- port->count++;
48395+ atomic_inc(&port->count);
48396 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48397 retval = -ENXIO;
48398 goto err_dec_count;
48399@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48400 /*
48401 * Make sure the device is in D0 state.
48402 */
48403- if (port->count == 1)
48404+ if (atomic_read(&port->count) == 1)
48405 uart_change_pm(state, UART_PM_STATE_ON);
48406
48407 /*
48408@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48409 end:
48410 return retval;
48411 err_dec_count:
48412- port->count--;
48413+ atomic_inc(&port->count);
48414 mutex_unlock(&port->mutex);
48415 goto end;
48416 }
48417diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48418index 8eaf1ab..85c030d 100644
48419--- a/drivers/tty/synclink.c
48420+++ b/drivers/tty/synclink.c
48421@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48422
48423 if (debug_level >= DEBUG_LEVEL_INFO)
48424 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48425- __FILE__,__LINE__, info->device_name, info->port.count);
48426+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48427
48428 if (tty_port_close_start(&info->port, tty, filp) == 0)
48429 goto cleanup;
48430@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48431 cleanup:
48432 if (debug_level >= DEBUG_LEVEL_INFO)
48433 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48434- tty->driver->name, info->port.count);
48435+ tty->driver->name, atomic_read(&info->port.count));
48436
48437 } /* end of mgsl_close() */
48438
48439@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48440
48441 mgsl_flush_buffer(tty);
48442 shutdown(info);
48443-
48444- info->port.count = 0;
48445+
48446+ atomic_set(&info->port.count, 0);
48447 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48448 info->port.tty = NULL;
48449
48450@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48451
48452 if (debug_level >= DEBUG_LEVEL_INFO)
48453 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48454- __FILE__,__LINE__, tty->driver->name, port->count );
48455+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48456
48457 spin_lock_irqsave(&info->irq_spinlock, flags);
48458 if (!tty_hung_up_p(filp)) {
48459 extra_count = true;
48460- port->count--;
48461+ atomic_dec(&port->count);
48462 }
48463 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48464 port->blocked_open++;
48465@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48466
48467 if (debug_level >= DEBUG_LEVEL_INFO)
48468 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48469- __FILE__,__LINE__, tty->driver->name, port->count );
48470+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48471
48472 tty_unlock(tty);
48473 schedule();
48474@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48475
48476 /* FIXME: Racy on hangup during close wait */
48477 if (extra_count)
48478- port->count++;
48479+ atomic_inc(&port->count);
48480 port->blocked_open--;
48481
48482 if (debug_level >= DEBUG_LEVEL_INFO)
48483 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48484- __FILE__,__LINE__, tty->driver->name, port->count );
48485+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48486
48487 if (!retval)
48488 port->flags |= ASYNC_NORMAL_ACTIVE;
48489@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48490
48491 if (debug_level >= DEBUG_LEVEL_INFO)
48492 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48493- __FILE__,__LINE__,tty->driver->name, info->port.count);
48494+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48495
48496 /* If port is closing, signal caller to try again */
48497 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48498@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48499 spin_unlock_irqrestore(&info->netlock, flags);
48500 goto cleanup;
48501 }
48502- info->port.count++;
48503+ atomic_inc(&info->port.count);
48504 spin_unlock_irqrestore(&info->netlock, flags);
48505
48506- if (info->port.count == 1) {
48507+ if (atomic_read(&info->port.count) == 1) {
48508 /* 1st open on this device, init hardware */
48509 retval = startup(info);
48510 if (retval < 0)
48511@@ -3446,8 +3446,8 @@ cleanup:
48512 if (retval) {
48513 if (tty->count == 1)
48514 info->port.tty = NULL; /* tty layer will release tty struct */
48515- if(info->port.count)
48516- info->port.count--;
48517+ if (atomic_read(&info->port.count))
48518+ atomic_dec(&info->port.count);
48519 }
48520
48521 return retval;
48522@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48523 unsigned short new_crctype;
48524
48525 /* return error if TTY interface open */
48526- if (info->port.count)
48527+ if (atomic_read(&info->port.count))
48528 return -EBUSY;
48529
48530 switch (encoding)
48531@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48532
48533 /* arbitrate between network and tty opens */
48534 spin_lock_irqsave(&info->netlock, flags);
48535- if (info->port.count != 0 || info->netcount != 0) {
48536+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48537 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48538 spin_unlock_irqrestore(&info->netlock, flags);
48539 return -EBUSY;
48540@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48541 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48542
48543 /* return error if TTY interface open */
48544- if (info->port.count)
48545+ if (atomic_read(&info->port.count))
48546 return -EBUSY;
48547
48548 if (cmd != SIOCWANDEV)
48549diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48550index 1abf946..1ee34fc 100644
48551--- a/drivers/tty/synclink_gt.c
48552+++ b/drivers/tty/synclink_gt.c
48553@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48554 tty->driver_data = info;
48555 info->port.tty = tty;
48556
48557- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48558+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48559
48560 /* If port is closing, signal caller to try again */
48561 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48562@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48563 mutex_unlock(&info->port.mutex);
48564 goto cleanup;
48565 }
48566- info->port.count++;
48567+ atomic_inc(&info->port.count);
48568 spin_unlock_irqrestore(&info->netlock, flags);
48569
48570- if (info->port.count == 1) {
48571+ if (atomic_read(&info->port.count) == 1) {
48572 /* 1st open on this device, init hardware */
48573 retval = startup(info);
48574 if (retval < 0) {
48575@@ -715,8 +715,8 @@ cleanup:
48576 if (retval) {
48577 if (tty->count == 1)
48578 info->port.tty = NULL; /* tty layer will release tty struct */
48579- if(info->port.count)
48580- info->port.count--;
48581+ if(atomic_read(&info->port.count))
48582+ atomic_dec(&info->port.count);
48583 }
48584
48585 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48586@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48587
48588 if (sanity_check(info, tty->name, "close"))
48589 return;
48590- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48591+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48592
48593 if (tty_port_close_start(&info->port, tty, filp) == 0)
48594 goto cleanup;
48595@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48596 tty_port_close_end(&info->port, tty);
48597 info->port.tty = NULL;
48598 cleanup:
48599- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48600+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48601 }
48602
48603 static void hangup(struct tty_struct *tty)
48604@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48605 shutdown(info);
48606
48607 spin_lock_irqsave(&info->port.lock, flags);
48608- info->port.count = 0;
48609+ atomic_set(&info->port.count, 0);
48610 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48611 info->port.tty = NULL;
48612 spin_unlock_irqrestore(&info->port.lock, flags);
48613@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48614 unsigned short new_crctype;
48615
48616 /* return error if TTY interface open */
48617- if (info->port.count)
48618+ if (atomic_read(&info->port.count))
48619 return -EBUSY;
48620
48621 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48622@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48623
48624 /* arbitrate between network and tty opens */
48625 spin_lock_irqsave(&info->netlock, flags);
48626- if (info->port.count != 0 || info->netcount != 0) {
48627+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48628 DBGINFO(("%s hdlc_open busy\n", dev->name));
48629 spin_unlock_irqrestore(&info->netlock, flags);
48630 return -EBUSY;
48631@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48632 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48633
48634 /* return error if TTY interface open */
48635- if (info->port.count)
48636+ if (atomic_read(&info->port.count))
48637 return -EBUSY;
48638
48639 if (cmd != SIOCWANDEV)
48640@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48641 if (port == NULL)
48642 continue;
48643 spin_lock(&port->lock);
48644- if ((port->port.count || port->netcount) &&
48645+ if ((atomic_read(&port->port.count) || port->netcount) &&
48646 port->pending_bh && !port->bh_running &&
48647 !port->bh_requested) {
48648 DBGISR(("%s bh queued\n", port->device_name));
48649@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48650 spin_lock_irqsave(&info->lock, flags);
48651 if (!tty_hung_up_p(filp)) {
48652 extra_count = true;
48653- port->count--;
48654+ atomic_dec(&port->count);
48655 }
48656 spin_unlock_irqrestore(&info->lock, flags);
48657 port->blocked_open++;
48658@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48659 remove_wait_queue(&port->open_wait, &wait);
48660
48661 if (extra_count)
48662- port->count++;
48663+ atomic_inc(&port->count);
48664 port->blocked_open--;
48665
48666 if (!retval)
48667diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48668index ff17138..e38b41e 100644
48669--- a/drivers/tty/synclinkmp.c
48670+++ b/drivers/tty/synclinkmp.c
48671@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48672
48673 if (debug_level >= DEBUG_LEVEL_INFO)
48674 printk("%s(%d):%s open(), old ref count = %d\n",
48675- __FILE__,__LINE__,tty->driver->name, info->port.count);
48676+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48677
48678 /* If port is closing, signal caller to try again */
48679 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48680@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48681 spin_unlock_irqrestore(&info->netlock, flags);
48682 goto cleanup;
48683 }
48684- info->port.count++;
48685+ atomic_inc(&info->port.count);
48686 spin_unlock_irqrestore(&info->netlock, flags);
48687
48688- if (info->port.count == 1) {
48689+ if (atomic_read(&info->port.count) == 1) {
48690 /* 1st open on this device, init hardware */
48691 retval = startup(info);
48692 if (retval < 0)
48693@@ -796,8 +796,8 @@ cleanup:
48694 if (retval) {
48695 if (tty->count == 1)
48696 info->port.tty = NULL; /* tty layer will release tty struct */
48697- if(info->port.count)
48698- info->port.count--;
48699+ if(atomic_read(&info->port.count))
48700+ atomic_dec(&info->port.count);
48701 }
48702
48703 return retval;
48704@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48705
48706 if (debug_level >= DEBUG_LEVEL_INFO)
48707 printk("%s(%d):%s close() entry, count=%d\n",
48708- __FILE__,__LINE__, info->device_name, info->port.count);
48709+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48710
48711 if (tty_port_close_start(&info->port, tty, filp) == 0)
48712 goto cleanup;
48713@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48714 cleanup:
48715 if (debug_level >= DEBUG_LEVEL_INFO)
48716 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48717- tty->driver->name, info->port.count);
48718+ tty->driver->name, atomic_read(&info->port.count));
48719 }
48720
48721 /* Called by tty_hangup() when a hangup is signaled.
48722@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48723 shutdown(info);
48724
48725 spin_lock_irqsave(&info->port.lock, flags);
48726- info->port.count = 0;
48727+ atomic_set(&info->port.count, 0);
48728 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48729 info->port.tty = NULL;
48730 spin_unlock_irqrestore(&info->port.lock, flags);
48731@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48732 unsigned short new_crctype;
48733
48734 /* return error if TTY interface open */
48735- if (info->port.count)
48736+ if (atomic_read(&info->port.count))
48737 return -EBUSY;
48738
48739 switch (encoding)
48740@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48741
48742 /* arbitrate between network and tty opens */
48743 spin_lock_irqsave(&info->netlock, flags);
48744- if (info->port.count != 0 || info->netcount != 0) {
48745+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48746 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48747 spin_unlock_irqrestore(&info->netlock, flags);
48748 return -EBUSY;
48749@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48750 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48751
48752 /* return error if TTY interface open */
48753- if (info->port.count)
48754+ if (atomic_read(&info->port.count))
48755 return -EBUSY;
48756
48757 if (cmd != SIOCWANDEV)
48758@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48759 * do not request bottom half processing if the
48760 * device is not open in a normal mode.
48761 */
48762- if ( port && (port->port.count || port->netcount) &&
48763+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48764 port->pending_bh && !port->bh_running &&
48765 !port->bh_requested ) {
48766 if ( debug_level >= DEBUG_LEVEL_ISR )
48767@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48768
48769 if (debug_level >= DEBUG_LEVEL_INFO)
48770 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48771- __FILE__,__LINE__, tty->driver->name, port->count );
48772+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48773
48774 spin_lock_irqsave(&info->lock, flags);
48775 if (!tty_hung_up_p(filp)) {
48776 extra_count = true;
48777- port->count--;
48778+ atomic_dec(&port->count);
48779 }
48780 spin_unlock_irqrestore(&info->lock, flags);
48781 port->blocked_open++;
48782@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48783
48784 if (debug_level >= DEBUG_LEVEL_INFO)
48785 printk("%s(%d):%s block_til_ready() count=%d\n",
48786- __FILE__,__LINE__, tty->driver->name, port->count );
48787+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48788
48789 tty_unlock(tty);
48790 schedule();
48791@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48792 remove_wait_queue(&port->open_wait, &wait);
48793
48794 if (extra_count)
48795- port->count++;
48796+ atomic_inc(&port->count);
48797 port->blocked_open--;
48798
48799 if (debug_level >= DEBUG_LEVEL_INFO)
48800 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48801- __FILE__,__LINE__, tty->driver->name, port->count );
48802+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48803
48804 if (!retval)
48805 port->flags |= ASYNC_NORMAL_ACTIVE;
48806diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48807index b51c154..17d55d1 100644
48808--- a/drivers/tty/sysrq.c
48809+++ b/drivers/tty/sysrq.c
48810@@ -1022,7 +1022,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48811 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48812 size_t count, loff_t *ppos)
48813 {
48814- if (count) {
48815+ if (count && capable(CAP_SYS_ADMIN)) {
48816 char c;
48817
48818 if (get_user(c, buf))
48819diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48820index 4476682..d77e748 100644
48821--- a/drivers/tty/tty_io.c
48822+++ b/drivers/tty/tty_io.c
48823@@ -3466,7 +3466,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48824
48825 void tty_default_fops(struct file_operations *fops)
48826 {
48827- *fops = tty_fops;
48828+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48829 }
48830
48831 /*
48832diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48833index 1afe192..73d2c20 100644
48834--- a/drivers/tty/tty_ldisc.c
48835+++ b/drivers/tty/tty_ldisc.c
48836@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48837 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48838 tty_ldiscs[disc] = new_ldisc;
48839 new_ldisc->num = disc;
48840- new_ldisc->refcount = 0;
48841+ atomic_set(&new_ldisc->refcount, 0);
48842 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48843
48844 return ret;
48845@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48846 return -EINVAL;
48847
48848 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48849- if (tty_ldiscs[disc]->refcount)
48850+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48851 ret = -EBUSY;
48852 else
48853 tty_ldiscs[disc] = NULL;
48854@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48855 if (ldops) {
48856 ret = ERR_PTR(-EAGAIN);
48857 if (try_module_get(ldops->owner)) {
48858- ldops->refcount++;
48859+ atomic_inc(&ldops->refcount);
48860 ret = ldops;
48861 }
48862 }
48863@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48864 unsigned long flags;
48865
48866 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48867- ldops->refcount--;
48868+ atomic_dec(&ldops->refcount);
48869 module_put(ldops->owner);
48870 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48871 }
48872@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48873 /* unreleased reader reference(s) will cause this WARN */
48874 WARN_ON(!atomic_dec_and_test(&ld->users));
48875
48876- ld->ops->refcount--;
48877+ atomic_dec(&ld->ops->refcount);
48878 module_put(ld->ops->owner);
48879 kfree(ld);
48880 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48881diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48882index f597e88..b7f68ed 100644
48883--- a/drivers/tty/tty_port.c
48884+++ b/drivers/tty/tty_port.c
48885@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48886 unsigned long flags;
48887
48888 spin_lock_irqsave(&port->lock, flags);
48889- port->count = 0;
48890+ atomic_set(&port->count, 0);
48891 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48892 tty = port->tty;
48893 if (tty)
48894@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48895 /* The port lock protects the port counts */
48896 spin_lock_irqsave(&port->lock, flags);
48897 if (!tty_hung_up_p(filp))
48898- port->count--;
48899+ atomic_dec(&port->count);
48900 port->blocked_open++;
48901 spin_unlock_irqrestore(&port->lock, flags);
48902
48903@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48904 we must not mess that up further */
48905 spin_lock_irqsave(&port->lock, flags);
48906 if (!tty_hung_up_p(filp))
48907- port->count++;
48908+ atomic_inc(&port->count);
48909 port->blocked_open--;
48910 if (retval == 0)
48911 port->flags |= ASYNC_NORMAL_ACTIVE;
48912@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48913 return 0;
48914 }
48915
48916- if (tty->count == 1 && port->count != 1) {
48917+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48918 printk(KERN_WARNING
48919 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48920- port->count);
48921- port->count = 1;
48922+ atomic_read(&port->count));
48923+ atomic_set(&port->count, 1);
48924 }
48925- if (--port->count < 0) {
48926+ if (atomic_dec_return(&port->count) < 0) {
48927 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48928- port->count);
48929- port->count = 0;
48930+ atomic_read(&port->count));
48931+ atomic_set(&port->count, 0);
48932 }
48933
48934- if (port->count) {
48935+ if (atomic_read(&port->count)) {
48936 spin_unlock_irqrestore(&port->lock, flags);
48937 if (port->ops->drop)
48938 port->ops->drop(port);
48939@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48940 {
48941 spin_lock_irq(&port->lock);
48942 if (!tty_hung_up_p(filp))
48943- ++port->count;
48944+ atomic_inc(&port->count);
48945 spin_unlock_irq(&port->lock);
48946 tty_port_tty_set(port, tty);
48947
48948diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48949index a9af1b9a..1e08e7f 100644
48950--- a/drivers/tty/vt/keyboard.c
48951+++ b/drivers/tty/vt/keyboard.c
48952@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48953 kbd->kbdmode == VC_OFF) &&
48954 value != KVAL(K_SAK))
48955 return; /* SAK is allowed even in raw mode */
48956+
48957+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48958+ {
48959+ void *func = fn_handler[value];
48960+ if (func == fn_show_state || func == fn_show_ptregs ||
48961+ func == fn_show_mem)
48962+ return;
48963+ }
48964+#endif
48965+
48966 fn_handler[value](vc);
48967 }
48968
48969@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48970 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48971 return -EFAULT;
48972
48973- if (!capable(CAP_SYS_TTY_CONFIG))
48974- perm = 0;
48975-
48976 switch (cmd) {
48977 case KDGKBENT:
48978 /* Ensure another thread doesn't free it under us */
48979@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48980 spin_unlock_irqrestore(&kbd_event_lock, flags);
48981 return put_user(val, &user_kbe->kb_value);
48982 case KDSKBENT:
48983+ if (!capable(CAP_SYS_TTY_CONFIG))
48984+ perm = 0;
48985+
48986 if (!perm)
48987 return -EPERM;
48988 if (!i && v == K_NOSUCHMAP) {
48989@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48990 int i, j, k;
48991 int ret;
48992
48993- if (!capable(CAP_SYS_TTY_CONFIG))
48994- perm = 0;
48995-
48996 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48997 if (!kbs) {
48998 ret = -ENOMEM;
48999@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
49000 kfree(kbs);
49001 return ((p && *p) ? -EOVERFLOW : 0);
49002 case KDSKBSENT:
49003+ if (!capable(CAP_SYS_TTY_CONFIG))
49004+ perm = 0;
49005+
49006 if (!perm) {
49007 ret = -EPERM;
49008 goto reterr;
49009diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
49010index b645c47..a55c182 100644
49011--- a/drivers/uio/uio.c
49012+++ b/drivers/uio/uio.c
49013@@ -25,6 +25,7 @@
49014 #include <linux/kobject.h>
49015 #include <linux/cdev.h>
49016 #include <linux/uio_driver.h>
49017+#include <asm/local.h>
49018
49019 #define UIO_MAX_DEVICES (1U << MINORBITS)
49020
49021@@ -32,10 +33,10 @@ struct uio_device {
49022 struct module *owner;
49023 struct device *dev;
49024 int minor;
49025- atomic_t event;
49026+ atomic_unchecked_t event;
49027 struct fasync_struct *async_queue;
49028 wait_queue_head_t wait;
49029- int vma_count;
49030+ local_t vma_count;
49031 struct uio_info *info;
49032 struct kobject *map_dir;
49033 struct kobject *portio_dir;
49034@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
49035 struct device_attribute *attr, char *buf)
49036 {
49037 struct uio_device *idev = dev_get_drvdata(dev);
49038- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
49039+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
49040 }
49041
49042 static struct device_attribute uio_class_attributes[] = {
49043@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
49044 {
49045 struct uio_device *idev = info->uio_dev;
49046
49047- atomic_inc(&idev->event);
49048+ atomic_inc_unchecked(&idev->event);
49049 wake_up_interruptible(&idev->wait);
49050 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
49051 }
49052@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
49053 }
49054
49055 listener->dev = idev;
49056- listener->event_count = atomic_read(&idev->event);
49057+ listener->event_count = atomic_read_unchecked(&idev->event);
49058 filep->private_data = listener;
49059
49060 if (idev->info->open) {
49061@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
49062 return -EIO;
49063
49064 poll_wait(filep, &idev->wait, wait);
49065- if (listener->event_count != atomic_read(&idev->event))
49066+ if (listener->event_count != atomic_read_unchecked(&idev->event))
49067 return POLLIN | POLLRDNORM;
49068 return 0;
49069 }
49070@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
49071 do {
49072 set_current_state(TASK_INTERRUPTIBLE);
49073
49074- event_count = atomic_read(&idev->event);
49075+ event_count = atomic_read_unchecked(&idev->event);
49076 if (event_count != listener->event_count) {
49077 if (copy_to_user(buf, &event_count, count))
49078 retval = -EFAULT;
49079@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
49080 static void uio_vma_open(struct vm_area_struct *vma)
49081 {
49082 struct uio_device *idev = vma->vm_private_data;
49083- idev->vma_count++;
49084+ local_inc(&idev->vma_count);
49085 }
49086
49087 static void uio_vma_close(struct vm_area_struct *vma)
49088 {
49089 struct uio_device *idev = vma->vm_private_data;
49090- idev->vma_count--;
49091+ local_dec(&idev->vma_count);
49092 }
49093
49094 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
49095@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
49096 idev->owner = owner;
49097 idev->info = info;
49098 init_waitqueue_head(&idev->wait);
49099- atomic_set(&idev->event, 0);
49100+ atomic_set_unchecked(&idev->event, 0);
49101
49102 ret = uio_get_minor(idev);
49103 if (ret)
49104diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
49105index 8a7eb77..c00402f 100644
49106--- a/drivers/usb/atm/cxacru.c
49107+++ b/drivers/usb/atm/cxacru.c
49108@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
49109 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
49110 if (ret < 2)
49111 return -EINVAL;
49112- if (index < 0 || index > 0x7f)
49113+ if (index > 0x7f)
49114 return -EINVAL;
49115 pos += tmp;
49116
49117diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
49118index d3527dd..26effa2 100644
49119--- a/drivers/usb/atm/usbatm.c
49120+++ b/drivers/usb/atm/usbatm.c
49121@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49122 if (printk_ratelimit())
49123 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
49124 __func__, vpi, vci);
49125- atomic_inc(&vcc->stats->rx_err);
49126+ atomic_inc_unchecked(&vcc->stats->rx_err);
49127 return;
49128 }
49129
49130@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49131 if (length > ATM_MAX_AAL5_PDU) {
49132 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
49133 __func__, length, vcc);
49134- atomic_inc(&vcc->stats->rx_err);
49135+ atomic_inc_unchecked(&vcc->stats->rx_err);
49136 goto out;
49137 }
49138
49139@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49140 if (sarb->len < pdu_length) {
49141 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
49142 __func__, pdu_length, sarb->len, vcc);
49143- atomic_inc(&vcc->stats->rx_err);
49144+ atomic_inc_unchecked(&vcc->stats->rx_err);
49145 goto out;
49146 }
49147
49148 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
49149 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
49150 __func__, vcc);
49151- atomic_inc(&vcc->stats->rx_err);
49152+ atomic_inc_unchecked(&vcc->stats->rx_err);
49153 goto out;
49154 }
49155
49156@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49157 if (printk_ratelimit())
49158 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
49159 __func__, length);
49160- atomic_inc(&vcc->stats->rx_drop);
49161+ atomic_inc_unchecked(&vcc->stats->rx_drop);
49162 goto out;
49163 }
49164
49165@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49166
49167 vcc->push(vcc, skb);
49168
49169- atomic_inc(&vcc->stats->rx);
49170+ atomic_inc_unchecked(&vcc->stats->rx);
49171 out:
49172 skb_trim(sarb, 0);
49173 }
49174@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
49175 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
49176
49177 usbatm_pop(vcc, skb);
49178- atomic_inc(&vcc->stats->tx);
49179+ atomic_inc_unchecked(&vcc->stats->tx);
49180
49181 skb = skb_dequeue(&instance->sndqueue);
49182 }
49183@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
49184 if (!left--)
49185 return sprintf(page,
49186 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
49187- atomic_read(&atm_dev->stats.aal5.tx),
49188- atomic_read(&atm_dev->stats.aal5.tx_err),
49189- atomic_read(&atm_dev->stats.aal5.rx),
49190- atomic_read(&atm_dev->stats.aal5.rx_err),
49191- atomic_read(&atm_dev->stats.aal5.rx_drop));
49192+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
49193+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
49194+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
49195+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
49196+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
49197
49198 if (!left--) {
49199 if (instance->disconnected)
49200diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
49201index 2a3bbdf..91d72cf 100644
49202--- a/drivers/usb/core/devices.c
49203+++ b/drivers/usb/core/devices.c
49204@@ -126,7 +126,7 @@ static const char format_endpt[] =
49205 * time it gets called.
49206 */
49207 static struct device_connect_event {
49208- atomic_t count;
49209+ atomic_unchecked_t count;
49210 wait_queue_head_t wait;
49211 } device_event = {
49212 .count = ATOMIC_INIT(1),
49213@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
49214
49215 void usbfs_conn_disc_event(void)
49216 {
49217- atomic_add(2, &device_event.count);
49218+ atomic_add_unchecked(2, &device_event.count);
49219 wake_up(&device_event.wait);
49220 }
49221
49222@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
49223
49224 poll_wait(file, &device_event.wait, wait);
49225
49226- event_count = atomic_read(&device_event.count);
49227+ event_count = atomic_read_unchecked(&device_event.count);
49228 if (file->f_version != event_count) {
49229 file->f_version = event_count;
49230 return POLLIN | POLLRDNORM;
49231diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
49232index d53547d..6a22d02 100644
49233--- a/drivers/usb/core/hcd.c
49234+++ b/drivers/usb/core/hcd.c
49235@@ -1526,7 +1526,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49236 */
49237 usb_get_urb(urb);
49238 atomic_inc(&urb->use_count);
49239- atomic_inc(&urb->dev->urbnum);
49240+ atomic_inc_unchecked(&urb->dev->urbnum);
49241 usbmon_urb_submit(&hcd->self, urb);
49242
49243 /* NOTE requirements on root-hub callers (usbfs and the hub
49244@@ -1553,7 +1553,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49245 urb->hcpriv = NULL;
49246 INIT_LIST_HEAD(&urb->urb_list);
49247 atomic_dec(&urb->use_count);
49248- atomic_dec(&urb->dev->urbnum);
49249+ atomic_dec_unchecked(&urb->dev->urbnum);
49250 if (atomic_read(&urb->reject))
49251 wake_up(&usb_kill_urb_queue);
49252 usb_put_urb(urb);
49253diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
49254index da2905a..834a569 100644
49255--- a/drivers/usb/core/hub.c
49256+++ b/drivers/usb/core/hub.c
49257@@ -27,6 +27,7 @@
49258 #include <linux/freezer.h>
49259 #include <linux/random.h>
49260 #include <linux/pm_qos.h>
49261+#include <linux/grsecurity.h>
49262
49263 #include <asm/uaccess.h>
49264 #include <asm/byteorder.h>
49265@@ -4424,6 +4425,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
49266 goto done;
49267 return;
49268 }
49269+
49270+ if (gr_handle_new_usb())
49271+ goto done;
49272+
49273 if (hub_is_superspeed(hub->hdev))
49274 unit_load = 150;
49275 else
49276diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
49277index 444d30e..f15c850 100644
49278--- a/drivers/usb/core/message.c
49279+++ b/drivers/usb/core/message.c
49280@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
49281 * method can wait for it to complete. Since you don't have a handle on the
49282 * URB used, you can't cancel the request.
49283 */
49284-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49285+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49286 __u8 requesttype, __u16 value, __u16 index, void *data,
49287 __u16 size, int timeout)
49288 {
49289diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
49290index aa38db4..0a08682 100644
49291--- a/drivers/usb/core/sysfs.c
49292+++ b/drivers/usb/core/sysfs.c
49293@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
49294 struct usb_device *udev;
49295
49296 udev = to_usb_device(dev);
49297- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
49298+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
49299 }
49300 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
49301
49302diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
49303index b10da72..43aa0b2 100644
49304--- a/drivers/usb/core/usb.c
49305+++ b/drivers/usb/core/usb.c
49306@@ -389,7 +389,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
49307 set_dev_node(&dev->dev, dev_to_node(bus->controller));
49308 dev->state = USB_STATE_ATTACHED;
49309 dev->lpm_disable_count = 1;
49310- atomic_set(&dev->urbnum, 0);
49311+ atomic_set_unchecked(&dev->urbnum, 0);
49312
49313 INIT_LIST_HEAD(&dev->ep0.urb_list);
49314 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49315diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49316index f77083f..f3e2e34 100644
49317--- a/drivers/usb/dwc3/gadget.c
49318+++ b/drivers/usb/dwc3/gadget.c
49319@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49320 if (!usb_endpoint_xfer_isoc(desc))
49321 return 0;
49322
49323- memset(&trb_link, 0, sizeof(trb_link));
49324-
49325 /* Link TRB for ISOC. The HWO bit is never reset */
49326 trb_st_hw = &dep->trb_pool[0];
49327
49328diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49329index 5e29dde..eca992f 100644
49330--- a/drivers/usb/early/ehci-dbgp.c
49331+++ b/drivers/usb/early/ehci-dbgp.c
49332@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49333
49334 #ifdef CONFIG_KGDB
49335 static struct kgdb_io kgdbdbgp_io_ops;
49336-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49337+static struct kgdb_io kgdbdbgp_io_ops_console;
49338+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49339 #else
49340 #define dbgp_kgdb_mode (0)
49341 #endif
49342@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49343 .write_char = kgdbdbgp_write_char,
49344 };
49345
49346+static struct kgdb_io kgdbdbgp_io_ops_console = {
49347+ .name = "kgdbdbgp",
49348+ .read_char = kgdbdbgp_read_char,
49349+ .write_char = kgdbdbgp_write_char,
49350+ .is_console = 1
49351+};
49352+
49353 static int kgdbdbgp_wait_time;
49354
49355 static int __init kgdbdbgp_parse_config(char *str)
49356@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49357 ptr++;
49358 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49359 }
49360- kgdb_register_io_module(&kgdbdbgp_io_ops);
49361- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49362+ if (early_dbgp_console.index != -1)
49363+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49364+ else
49365+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49366
49367 return 0;
49368 }
49369diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49370index b369292..9f3ba40 100644
49371--- a/drivers/usb/gadget/u_serial.c
49372+++ b/drivers/usb/gadget/u_serial.c
49373@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49374 spin_lock_irq(&port->port_lock);
49375
49376 /* already open? Great. */
49377- if (port->port.count) {
49378+ if (atomic_read(&port->port.count)) {
49379 status = 0;
49380- port->port.count++;
49381+ atomic_inc(&port->port.count);
49382
49383 /* currently opening/closing? wait ... */
49384 } else if (port->openclose) {
49385@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49386 tty->driver_data = port;
49387 port->port.tty = tty;
49388
49389- port->port.count = 1;
49390+ atomic_set(&port->port.count, 1);
49391 port->openclose = false;
49392
49393 /* if connected, start the I/O stream */
49394@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49395
49396 spin_lock_irq(&port->port_lock);
49397
49398- if (port->port.count != 1) {
49399- if (port->port.count == 0)
49400+ if (atomic_read(&port->port.count) != 1) {
49401+ if (atomic_read(&port->port.count) == 0)
49402 WARN_ON(1);
49403 else
49404- --port->port.count;
49405+ atomic_dec(&port->port.count);
49406 goto exit;
49407 }
49408
49409@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49410 * and sleep if necessary
49411 */
49412 port->openclose = true;
49413- port->port.count = 0;
49414+ atomic_set(&port->port.count, 0);
49415
49416 gser = port->port_usb;
49417 if (gser && gser->disconnect)
49418@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49419 int cond;
49420
49421 spin_lock_irq(&port->port_lock);
49422- cond = (port->port.count == 0) && !port->openclose;
49423+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49424 spin_unlock_irq(&port->port_lock);
49425 return cond;
49426 }
49427@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49428 /* if it's already open, start I/O ... and notify the serial
49429 * protocol about open/close status (connect/disconnect).
49430 */
49431- if (port->port.count) {
49432+ if (atomic_read(&port->port.count)) {
49433 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49434 gs_start_io(port);
49435 if (gser->connect)
49436@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49437
49438 port->port_usb = NULL;
49439 gser->ioport = NULL;
49440- if (port->port.count > 0 || port->openclose) {
49441+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49442 wake_up_interruptible(&port->drain_wait);
49443 if (port->port.tty)
49444 tty_hangup(port->port.tty);
49445@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49446
49447 /* finally, free any unused/unusable I/O buffers */
49448 spin_lock_irqsave(&port->port_lock, flags);
49449- if (port->port.count == 0 && !port->openclose)
49450+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49451 gs_buf_free(&port->port_write_buf);
49452 gs_free_requests(gser->out, &port->read_pool, NULL);
49453 gs_free_requests(gser->out, &port->read_queue, NULL);
49454diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49455index ba6a5d6..f88f7f3 100644
49456--- a/drivers/usb/misc/appledisplay.c
49457+++ b/drivers/usb/misc/appledisplay.c
49458@@ -83,7 +83,7 @@ struct appledisplay {
49459 spinlock_t lock;
49460 };
49461
49462-static atomic_t count_displays = ATOMIC_INIT(0);
49463+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49464 static struct workqueue_struct *wq;
49465
49466 static void appledisplay_complete(struct urb *urb)
49467@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49468
49469 /* Register backlight device */
49470 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49471- atomic_inc_return(&count_displays) - 1);
49472+ atomic_inc_return_unchecked(&count_displays) - 1);
49473 memset(&props, 0, sizeof(struct backlight_properties));
49474 props.type = BACKLIGHT_RAW;
49475 props.max_brightness = 0xff;
49476diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49477index 5f3bcd3..bfca43f 100644
49478--- a/drivers/usb/serial/console.c
49479+++ b/drivers/usb/serial/console.c
49480@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49481
49482 info->port = port;
49483
49484- ++port->port.count;
49485+ atomic_inc(&port->port.count);
49486 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49487 if (serial->type->set_termios) {
49488 /*
49489@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49490 }
49491 /* Now that any required fake tty operations are completed restore
49492 * the tty port count */
49493- --port->port.count;
49494+ atomic_dec(&port->port.count);
49495 /* The console is special in terms of closing the device so
49496 * indicate this port is now acting as a system console. */
49497 port->port.console = 1;
49498@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49499 free_tty:
49500 kfree(tty);
49501 reset_open_count:
49502- port->port.count = 0;
49503+ atomic_set(&port->port.count, 0);
49504 usb_autopm_put_interface(serial->interface);
49505 error_get_interface:
49506 usb_serial_put(serial);
49507diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49508index 75f70f0..d467e1a 100644
49509--- a/drivers/usb/storage/usb.h
49510+++ b/drivers/usb/storage/usb.h
49511@@ -63,7 +63,7 @@ struct us_unusual_dev {
49512 __u8 useProtocol;
49513 __u8 useTransport;
49514 int (*initFunction)(struct us_data *);
49515-};
49516+} __do_const;
49517
49518
49519 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49520diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49521index d6bea3e..60b250e 100644
49522--- a/drivers/usb/wusbcore/wa-hc.h
49523+++ b/drivers/usb/wusbcore/wa-hc.h
49524@@ -192,7 +192,7 @@ struct wahc {
49525 struct list_head xfer_delayed_list;
49526 spinlock_t xfer_list_lock;
49527 struct work_struct xfer_work;
49528- atomic_t xfer_id_count;
49529+ atomic_unchecked_t xfer_id_count;
49530 };
49531
49532
49533@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49534 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49535 spin_lock_init(&wa->xfer_list_lock);
49536 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49537- atomic_set(&wa->xfer_id_count, 1);
49538+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49539 }
49540
49541 /**
49542diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49543index 028fc83..65bb105 100644
49544--- a/drivers/usb/wusbcore/wa-xfer.c
49545+++ b/drivers/usb/wusbcore/wa-xfer.c
49546@@ -296,7 +296,7 @@ out:
49547 */
49548 static void wa_xfer_id_init(struct wa_xfer *xfer)
49549 {
49550- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49551+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49552 }
49553
49554 /*
49555diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49556index 6d78736..65be90e 100644
49557--- a/drivers/vfio/vfio.c
49558+++ b/drivers/vfio/vfio.c
49559@@ -486,7 +486,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49560 return 0;
49561
49562 /* TODO Prevent device auto probing */
49563- WARN("Device %s added to live group %d!\n", dev_name(dev),
49564+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49565 iommu_group_id(group->iommu_group));
49566
49567 return 0;
49568@@ -506,7 +506,7 @@ static int vfio_group_nb_del_dev(struct vfio_group *group, struct device *dev)
49569 if (likely(!device))
49570 return 0;
49571
49572- WARN("Device %s removed from live group %d!\n", dev_name(dev),
49573+ WARN(1, "Device %s removed from live group %d!\n", dev_name(dev),
49574 iommu_group_id(group->iommu_group));
49575
49576 vfio_device_put(device);
49577diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49578index 5174eba..86e764a 100644
49579--- a/drivers/vhost/vringh.c
49580+++ b/drivers/vhost/vringh.c
49581@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49582
49583 static inline int putu16_kern(u16 *p, u16 val)
49584 {
49585- ACCESS_ONCE(*p) = val;
49586+ ACCESS_ONCE_RW(*p) = val;
49587 return 0;
49588 }
49589
49590diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49591index 8c55011..eed4ae1a 100644
49592--- a/drivers/video/aty/aty128fb.c
49593+++ b/drivers/video/aty/aty128fb.c
49594@@ -149,7 +149,7 @@ enum {
49595 };
49596
49597 /* Must match above enum */
49598-static char * const r128_family[] = {
49599+static const char * const r128_family[] = {
49600 "AGP",
49601 "PCI",
49602 "PRO AGP",
49603diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49604index 4f27fdc..d3537e6 100644
49605--- a/drivers/video/aty/atyfb_base.c
49606+++ b/drivers/video/aty/atyfb_base.c
49607@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
49608 par->accel_flags = var->accel_flags; /* hack */
49609
49610 if (var->accel_flags) {
49611- info->fbops->fb_sync = atyfb_sync;
49612+ pax_open_kernel();
49613+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49614+ pax_close_kernel();
49615 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49616 } else {
49617- info->fbops->fb_sync = NULL;
49618+ pax_open_kernel();
49619+ *(void **)&info->fbops->fb_sync = NULL;
49620+ pax_close_kernel();
49621 info->flags |= FBINFO_HWACCEL_DISABLED;
49622 }
49623
49624diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49625index 95ec042..e6affdd 100644
49626--- a/drivers/video/aty/mach64_cursor.c
49627+++ b/drivers/video/aty/mach64_cursor.c
49628@@ -7,6 +7,7 @@
49629 #include <linux/string.h>
49630
49631 #include <asm/io.h>
49632+#include <asm/pgtable.h>
49633
49634 #ifdef __sparc__
49635 #include <asm/fbio.h>
49636@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49637 info->sprite.buf_align = 16; /* and 64 lines tall. */
49638 info->sprite.flags = FB_PIXMAP_IO;
49639
49640- info->fbops->fb_cursor = atyfb_cursor;
49641+ pax_open_kernel();
49642+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49643+ pax_close_kernel();
49644
49645 return 0;
49646 }
49647diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
49648index c74e7aa..e3c2790 100644
49649--- a/drivers/video/backlight/backlight.c
49650+++ b/drivers/video/backlight/backlight.c
49651@@ -304,7 +304,7 @@ struct backlight_device *backlight_device_register(const char *name,
49652 new_bd->dev.class = backlight_class;
49653 new_bd->dev.parent = parent;
49654 new_bd->dev.release = bl_device_release;
49655- dev_set_name(&new_bd->dev, name);
49656+ dev_set_name(&new_bd->dev, "%s", name);
49657 dev_set_drvdata(&new_bd->dev, devdata);
49658
49659 /* Set default properties */
49660diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49661index bca6ccc..252107e 100644
49662--- a/drivers/video/backlight/kb3886_bl.c
49663+++ b/drivers/video/backlight/kb3886_bl.c
49664@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49665 static unsigned long kb3886bl_flags;
49666 #define KB3886BL_SUSPENDED 0x01
49667
49668-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49669+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49670 {
49671 .ident = "Sahara Touch-iT",
49672 .matches = {
49673diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
49674index 34fb6bd..3649fd9 100644
49675--- a/drivers/video/backlight/lcd.c
49676+++ b/drivers/video/backlight/lcd.c
49677@@ -219,7 +219,7 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent,
49678 new_ld->dev.class = lcd_class;
49679 new_ld->dev.parent = parent;
49680 new_ld->dev.release = lcd_device_release;
49681- dev_set_name(&new_ld->dev, name);
49682+ dev_set_name(&new_ld->dev, "%s", name);
49683 dev_set_drvdata(&new_ld->dev, devdata);
49684
49685 rc = device_register(&new_ld->dev);
49686diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49687index 900aa4e..6d49418 100644
49688--- a/drivers/video/fb_defio.c
49689+++ b/drivers/video/fb_defio.c
49690@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49691
49692 BUG_ON(!fbdefio);
49693 mutex_init(&fbdefio->lock);
49694- info->fbops->fb_mmap = fb_deferred_io_mmap;
49695+ pax_open_kernel();
49696+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49697+ pax_close_kernel();
49698 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49699 INIT_LIST_HEAD(&fbdefio->pagelist);
49700 if (fbdefio->delay == 0) /* set a default of 1 s */
49701@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49702 page->mapping = NULL;
49703 }
49704
49705- info->fbops->fb_mmap = NULL;
49706+ *(void **)&info->fbops->fb_mmap = NULL;
49707 mutex_destroy(&fbdefio->lock);
49708 }
49709 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49710diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49711index 5c3960d..15cf8fc 100644
49712--- a/drivers/video/fbcmap.c
49713+++ b/drivers/video/fbcmap.c
49714@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49715 rc = -ENODEV;
49716 goto out;
49717 }
49718- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49719- !info->fbops->fb_setcmap)) {
49720+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49721 rc = -EINVAL;
49722 goto out1;
49723 }
49724diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49725index 098bfc6..796841d 100644
49726--- a/drivers/video/fbmem.c
49727+++ b/drivers/video/fbmem.c
49728@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49729 image->dx += image->width + 8;
49730 }
49731 } else if (rotate == FB_ROTATE_UD) {
49732- for (x = 0; x < num && image->dx >= 0; x++) {
49733+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49734 info->fbops->fb_imageblit(info, image);
49735 image->dx -= image->width + 8;
49736 }
49737@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49738 image->dy += image->height + 8;
49739 }
49740 } else if (rotate == FB_ROTATE_CCW) {
49741- for (x = 0; x < num && image->dy >= 0; x++) {
49742+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49743 info->fbops->fb_imageblit(info, image);
49744 image->dy -= image->height + 8;
49745 }
49746@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49747 return -EFAULT;
49748 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49749 return -EINVAL;
49750- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49751+ if (con2fb.framebuffer >= FB_MAX)
49752 return -EINVAL;
49753 if (!registered_fb[con2fb.framebuffer])
49754 request_module("fb%d", con2fb.framebuffer);
49755diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49756index d4d2c5f..ebbd113 100644
49757--- a/drivers/video/hyperv_fb.c
49758+++ b/drivers/video/hyperv_fb.c
49759@@ -233,7 +233,7 @@ static uint screen_fb_size;
49760 static inline int synthvid_send(struct hv_device *hdev,
49761 struct synthvid_msg *msg)
49762 {
49763- static atomic64_t request_id = ATOMIC64_INIT(0);
49764+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49765 int ret;
49766
49767 msg->pipe_hdr.type = PIPE_MSG_DATA;
49768@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49769
49770 ret = vmbus_sendpacket(hdev->channel, msg,
49771 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49772- atomic64_inc_return(&request_id),
49773+ atomic64_inc_return_unchecked(&request_id),
49774 VM_PKT_DATA_INBAND, 0);
49775
49776 if (ret)
49777diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49778index 7672d2e..b56437f 100644
49779--- a/drivers/video/i810/i810_accel.c
49780+++ b/drivers/video/i810/i810_accel.c
49781@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49782 }
49783 }
49784 printk("ringbuffer lockup!!!\n");
49785+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49786 i810_report_error(mmio);
49787 par->dev_flags |= LOCKUP;
49788 info->pixmap.scan_align = 1;
49789diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49790index 3c14e43..eafa544 100644
49791--- a/drivers/video/logo/logo_linux_clut224.ppm
49792+++ b/drivers/video/logo/logo_linux_clut224.ppm
49793@@ -1,1604 +1,1123 @@
49794 P3
49795-# Standard 224-color Linux logo
49796 80 80
49797 255
49798- 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
49800- 0 0 0 0 0 0 0 0 0 0 0 0
49801- 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
49803- 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
49805- 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
49807- 6 6 6 6 6 6 10 10 10 10 10 10
49808- 10 10 10 6 6 6 6 6 6 6 6 6
49809- 0 0 0 0 0 0 0 0 0 0 0 0
49810- 0 0 0 0 0 0 0 0 0 0 0 0
49811- 0 0 0 0 0 0 0 0 0 0 0 0
49812- 0 0 0 0 0 0 0 0 0 0 0 0
49813- 0 0 0 0 0 0 0 0 0 0 0 0
49814- 0 0 0 0 0 0 0 0 0 0 0 0
49815- 0 0 0 0 0 0 0 0 0 0 0 0
49816- 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
49818- 0 0 0 0 0 0 0 0 0 0 0 0
49819- 0 0 0 0 0 0 0 0 0 0 0 0
49820- 0 0 0 0 0 0 0 0 0 0 0 0
49821- 0 0 0 0 0 0 0 0 0 0 0 0
49822- 0 0 0 0 0 0 0 0 0 0 0 0
49823- 0 0 0 0 0 0 0 0 0 0 0 0
49824- 0 0 0 0 0 0 0 0 0 0 0 0
49825- 0 0 0 0 0 0 0 0 0 0 0 0
49826- 0 0 0 6 6 6 10 10 10 14 14 14
49827- 22 22 22 26 26 26 30 30 30 34 34 34
49828- 30 30 30 30 30 30 26 26 26 18 18 18
49829- 14 14 14 10 10 10 6 6 6 0 0 0
49830- 0 0 0 0 0 0 0 0 0 0 0 0
49831- 0 0 0 0 0 0 0 0 0 0 0 0
49832- 0 0 0 0 0 0 0 0 0 0 0 0
49833- 0 0 0 0 0 0 0 0 0 0 0 0
49834- 0 0 0 0 0 0 0 0 0 0 0 0
49835- 0 0 0 0 0 0 0 0 0 0 0 0
49836- 0 0 0 0 0 0 0 0 0 0 0 0
49837- 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
49839- 0 0 0 0 0 1 0 0 1 0 0 0
49840- 0 0 0 0 0 0 0 0 0 0 0 0
49841- 0 0 0 0 0 0 0 0 0 0 0 0
49842- 0 0 0 0 0 0 0 0 0 0 0 0
49843- 0 0 0 0 0 0 0 0 0 0 0 0
49844- 0 0 0 0 0 0 0 0 0 0 0 0
49845- 0 0 0 0 0 0 0 0 0 0 0 0
49846- 6 6 6 14 14 14 26 26 26 42 42 42
49847- 54 54 54 66 66 66 78 78 78 78 78 78
49848- 78 78 78 74 74 74 66 66 66 54 54 54
49849- 42 42 42 26 26 26 18 18 18 10 10 10
49850- 6 6 6 0 0 0 0 0 0 0 0 0
49851- 0 0 0 0 0 0 0 0 0 0 0 0
49852- 0 0 0 0 0 0 0 0 0 0 0 0
49853- 0 0 0 0 0 0 0 0 0 0 0 0
49854- 0 0 0 0 0 0 0 0 0 0 0 0
49855- 0 0 0 0 0 0 0 0 0 0 0 0
49856- 0 0 0 0 0 0 0 0 0 0 0 0
49857- 0 0 0 0 0 0 0 0 0 0 0 0
49858- 0 0 0 0 0 0 0 0 0 0 0 0
49859- 0 0 1 0 0 0 0 0 0 0 0 0
49860- 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
49862- 0 0 0 0 0 0 0 0 0 0 0 0
49863- 0 0 0 0 0 0 0 0 0 0 0 0
49864- 0 0 0 0 0 0 0 0 0 0 0 0
49865- 0 0 0 0 0 0 0 0 0 10 10 10
49866- 22 22 22 42 42 42 66 66 66 86 86 86
49867- 66 66 66 38 38 38 38 38 38 22 22 22
49868- 26 26 26 34 34 34 54 54 54 66 66 66
49869- 86 86 86 70 70 70 46 46 46 26 26 26
49870- 14 14 14 6 6 6 0 0 0 0 0 0
49871- 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
49873- 0 0 0 0 0 0 0 0 0 0 0 0
49874- 0 0 0 0 0 0 0 0 0 0 0 0
49875- 0 0 0 0 0 0 0 0 0 0 0 0
49876- 0 0 0 0 0 0 0 0 0 0 0 0
49877- 0 0 0 0 0 0 0 0 0 0 0 0
49878- 0 0 0 0 0 0 0 0 0 0 0 0
49879- 0 0 1 0 0 1 0 0 1 0 0 0
49880- 0 0 0 0 0 0 0 0 0 0 0 0
49881- 0 0 0 0 0 0 0 0 0 0 0 0
49882- 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
49884- 0 0 0 0 0 0 0 0 0 0 0 0
49885- 0 0 0 0 0 0 10 10 10 26 26 26
49886- 50 50 50 82 82 82 58 58 58 6 6 6
49887- 2 2 6 2 2 6 2 2 6 2 2 6
49888- 2 2 6 2 2 6 2 2 6 2 2 6
49889- 6 6 6 54 54 54 86 86 86 66 66 66
49890- 38 38 38 18 18 18 6 6 6 0 0 0
49891- 0 0 0 0 0 0 0 0 0 0 0 0
49892- 0 0 0 0 0 0 0 0 0 0 0 0
49893- 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
49895- 0 0 0 0 0 0 0 0 0 0 0 0
49896- 0 0 0 0 0 0 0 0 0 0 0 0
49897- 0 0 0 0 0 0 0 0 0 0 0 0
49898- 0 0 0 0 0 0 0 0 0 0 0 0
49899- 0 0 0 0 0 0 0 0 0 0 0 0
49900- 0 0 0 0 0 0 0 0 0 0 0 0
49901- 0 0 0 0 0 0 0 0 0 0 0 0
49902- 0 0 0 0 0 0 0 0 0 0 0 0
49903- 0 0 0 0 0 0 0 0 0 0 0 0
49904- 0 0 0 0 0 0 0 0 0 0 0 0
49905- 0 0 0 6 6 6 22 22 22 50 50 50
49906- 78 78 78 34 34 34 2 2 6 2 2 6
49907- 2 2 6 2 2 6 2 2 6 2 2 6
49908- 2 2 6 2 2 6 2 2 6 2 2 6
49909- 2 2 6 2 2 6 6 6 6 70 70 70
49910- 78 78 78 46 46 46 22 22 22 6 6 6
49911- 0 0 0 0 0 0 0 0 0 0 0 0
49912- 0 0 0 0 0 0 0 0 0 0 0 0
49913- 0 0 0 0 0 0 0 0 0 0 0 0
49914- 0 0 0 0 0 0 0 0 0 0 0 0
49915- 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
49917- 0 0 0 0 0 0 0 0 0 0 0 0
49918- 0 0 0 0 0 0 0 0 0 0 0 0
49919- 0 0 1 0 0 1 0 0 1 0 0 0
49920- 0 0 0 0 0 0 0 0 0 0 0 0
49921- 0 0 0 0 0 0 0 0 0 0 0 0
49922- 0 0 0 0 0 0 0 0 0 0 0 0
49923- 0 0 0 0 0 0 0 0 0 0 0 0
49924- 0 0 0 0 0 0 0 0 0 0 0 0
49925- 6 6 6 18 18 18 42 42 42 82 82 82
49926- 26 26 26 2 2 6 2 2 6 2 2 6
49927- 2 2 6 2 2 6 2 2 6 2 2 6
49928- 2 2 6 2 2 6 2 2 6 14 14 14
49929- 46 46 46 34 34 34 6 6 6 2 2 6
49930- 42 42 42 78 78 78 42 42 42 18 18 18
49931- 6 6 6 0 0 0 0 0 0 0 0 0
49932- 0 0 0 0 0 0 0 0 0 0 0 0
49933- 0 0 0 0 0 0 0 0 0 0 0 0
49934- 0 0 0 0 0 0 0 0 0 0 0 0
49935- 0 0 0 0 0 0 0 0 0 0 0 0
49936- 0 0 0 0 0 0 0 0 0 0 0 0
49937- 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
49939- 0 0 1 0 0 0 0 0 1 0 0 0
49940- 0 0 0 0 0 0 0 0 0 0 0 0
49941- 0 0 0 0 0 0 0 0 0 0 0 0
49942- 0 0 0 0 0 0 0 0 0 0 0 0
49943- 0 0 0 0 0 0 0 0 0 0 0 0
49944- 0 0 0 0 0 0 0 0 0 0 0 0
49945- 10 10 10 30 30 30 66 66 66 58 58 58
49946- 2 2 6 2 2 6 2 2 6 2 2 6
49947- 2 2 6 2 2 6 2 2 6 2 2 6
49948- 2 2 6 2 2 6 2 2 6 26 26 26
49949- 86 86 86 101 101 101 46 46 46 10 10 10
49950- 2 2 6 58 58 58 70 70 70 34 34 34
49951- 10 10 10 0 0 0 0 0 0 0 0 0
49952- 0 0 0 0 0 0 0 0 0 0 0 0
49953- 0 0 0 0 0 0 0 0 0 0 0 0
49954- 0 0 0 0 0 0 0 0 0 0 0 0
49955- 0 0 0 0 0 0 0 0 0 0 0 0
49956- 0 0 0 0 0 0 0 0 0 0 0 0
49957- 0 0 0 0 0 0 0 0 0 0 0 0
49958- 0 0 0 0 0 0 0 0 0 0 0 0
49959- 0 0 1 0 0 1 0 0 1 0 0 0
49960- 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
49962- 0 0 0 0 0 0 0 0 0 0 0 0
49963- 0 0 0 0 0 0 0 0 0 0 0 0
49964- 0 0 0 0 0 0 0 0 0 0 0 0
49965- 14 14 14 42 42 42 86 86 86 10 10 10
49966- 2 2 6 2 2 6 2 2 6 2 2 6
49967- 2 2 6 2 2 6 2 2 6 2 2 6
49968- 2 2 6 2 2 6 2 2 6 30 30 30
49969- 94 94 94 94 94 94 58 58 58 26 26 26
49970- 2 2 6 6 6 6 78 78 78 54 54 54
49971- 22 22 22 6 6 6 0 0 0 0 0 0
49972- 0 0 0 0 0 0 0 0 0 0 0 0
49973- 0 0 0 0 0 0 0 0 0 0 0 0
49974- 0 0 0 0 0 0 0 0 0 0 0 0
49975- 0 0 0 0 0 0 0 0 0 0 0 0
49976- 0 0 0 0 0 0 0 0 0 0 0 0
49977- 0 0 0 0 0 0 0 0 0 0 0 0
49978- 0 0 0 0 0 0 0 0 0 0 0 0
49979- 0 0 0 0 0 0 0 0 0 0 0 0
49980- 0 0 0 0 0 0 0 0 0 0 0 0
49981- 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
49983- 0 0 0 0 0 0 0 0 0 0 0 0
49984- 0 0 0 0 0 0 0 0 0 6 6 6
49985- 22 22 22 62 62 62 62 62 62 2 2 6
49986- 2 2 6 2 2 6 2 2 6 2 2 6
49987- 2 2 6 2 2 6 2 2 6 2 2 6
49988- 2 2 6 2 2 6 2 2 6 26 26 26
49989- 54 54 54 38 38 38 18 18 18 10 10 10
49990- 2 2 6 2 2 6 34 34 34 82 82 82
49991- 38 38 38 14 14 14 0 0 0 0 0 0
49992- 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
49994- 0 0 0 0 0 0 0 0 0 0 0 0
49995- 0 0 0 0 0 0 0 0 0 0 0 0
49996- 0 0 0 0 0 0 0 0 0 0 0 0
49997- 0 0 0 0 0 0 0 0 0 0 0 0
49998- 0 0 0 0 0 0 0 0 0 0 0 0
49999- 0 0 0 0 0 1 0 0 1 0 0 0
50000- 0 0 0 0 0 0 0 0 0 0 0 0
50001- 0 0 0 0 0 0 0 0 0 0 0 0
50002- 0 0 0 0 0 0 0 0 0 0 0 0
50003- 0 0 0 0 0 0 0 0 0 0 0 0
50004- 0 0 0 0 0 0 0 0 0 6 6 6
50005- 30 30 30 78 78 78 30 30 30 2 2 6
50006- 2 2 6 2 2 6 2 2 6 2 2 6
50007- 2 2 6 2 2 6 2 2 6 2 2 6
50008- 2 2 6 2 2 6 2 2 6 10 10 10
50009- 10 10 10 2 2 6 2 2 6 2 2 6
50010- 2 2 6 2 2 6 2 2 6 78 78 78
50011- 50 50 50 18 18 18 6 6 6 0 0 0
50012- 0 0 0 0 0 0 0 0 0 0 0 0
50013- 0 0 0 0 0 0 0 0 0 0 0 0
50014- 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
50016- 0 0 0 0 0 0 0 0 0 0 0 0
50017- 0 0 0 0 0 0 0 0 0 0 0 0
50018- 0 0 0 0 0 0 0 0 0 0 0 0
50019- 0 0 1 0 0 0 0 0 0 0 0 0
50020- 0 0 0 0 0 0 0 0 0 0 0 0
50021- 0 0 0 0 0 0 0 0 0 0 0 0
50022- 0 0 0 0 0 0 0 0 0 0 0 0
50023- 0 0 0 0 0 0 0 0 0 0 0 0
50024- 0 0 0 0 0 0 0 0 0 10 10 10
50025- 38 38 38 86 86 86 14 14 14 2 2 6
50026- 2 2 6 2 2 6 2 2 6 2 2 6
50027- 2 2 6 2 2 6 2 2 6 2 2 6
50028- 2 2 6 2 2 6 2 2 6 2 2 6
50029- 2 2 6 2 2 6 2 2 6 2 2 6
50030- 2 2 6 2 2 6 2 2 6 54 54 54
50031- 66 66 66 26 26 26 6 6 6 0 0 0
50032- 0 0 0 0 0 0 0 0 0 0 0 0
50033- 0 0 0 0 0 0 0 0 0 0 0 0
50034- 0 0 0 0 0 0 0 0 0 0 0 0
50035- 0 0 0 0 0 0 0 0 0 0 0 0
50036- 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
50038- 0 0 0 0 0 0 0 0 0 0 0 0
50039- 0 0 0 0 0 1 0 0 1 0 0 0
50040- 0 0 0 0 0 0 0 0 0 0 0 0
50041- 0 0 0 0 0 0 0 0 0 0 0 0
50042- 0 0 0 0 0 0 0 0 0 0 0 0
50043- 0 0 0 0 0 0 0 0 0 0 0 0
50044- 0 0 0 0 0 0 0 0 0 14 14 14
50045- 42 42 42 82 82 82 2 2 6 2 2 6
50046- 2 2 6 6 6 6 10 10 10 2 2 6
50047- 2 2 6 2 2 6 2 2 6 2 2 6
50048- 2 2 6 2 2 6 2 2 6 6 6 6
50049- 14 14 14 10 10 10 2 2 6 2 2 6
50050- 2 2 6 2 2 6 2 2 6 18 18 18
50051- 82 82 82 34 34 34 10 10 10 0 0 0
50052- 0 0 0 0 0 0 0 0 0 0 0 0
50053- 0 0 0 0 0 0 0 0 0 0 0 0
50054- 0 0 0 0 0 0 0 0 0 0 0 0
50055- 0 0 0 0 0 0 0 0 0 0 0 0
50056- 0 0 0 0 0 0 0 0 0 0 0 0
50057- 0 0 0 0 0 0 0 0 0 0 0 0
50058- 0 0 0 0 0 0 0 0 0 0 0 0
50059- 0 0 1 0 0 0 0 0 0 0 0 0
50060- 0 0 0 0 0 0 0 0 0 0 0 0
50061- 0 0 0 0 0 0 0 0 0 0 0 0
50062- 0 0 0 0 0 0 0 0 0 0 0 0
50063- 0 0 0 0 0 0 0 0 0 0 0 0
50064- 0 0 0 0 0 0 0 0 0 14 14 14
50065- 46 46 46 86 86 86 2 2 6 2 2 6
50066- 6 6 6 6 6 6 22 22 22 34 34 34
50067- 6 6 6 2 2 6 2 2 6 2 2 6
50068- 2 2 6 2 2 6 18 18 18 34 34 34
50069- 10 10 10 50 50 50 22 22 22 2 2 6
50070- 2 2 6 2 2 6 2 2 6 10 10 10
50071- 86 86 86 42 42 42 14 14 14 0 0 0
50072- 0 0 0 0 0 0 0 0 0 0 0 0
50073- 0 0 0 0 0 0 0 0 0 0 0 0
50074- 0 0 0 0 0 0 0 0 0 0 0 0
50075- 0 0 0 0 0 0 0 0 0 0 0 0
50076- 0 0 0 0 0 0 0 0 0 0 0 0
50077- 0 0 0 0 0 0 0 0 0 0 0 0
50078- 0 0 0 0 0 0 0 0 0 0 0 0
50079- 0 0 1 0 0 1 0 0 1 0 0 0
50080- 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
50082- 0 0 0 0 0 0 0 0 0 0 0 0
50083- 0 0 0 0 0 0 0 0 0 0 0 0
50084- 0 0 0 0 0 0 0 0 0 14 14 14
50085- 46 46 46 86 86 86 2 2 6 2 2 6
50086- 38 38 38 116 116 116 94 94 94 22 22 22
50087- 22 22 22 2 2 6 2 2 6 2 2 6
50088- 14 14 14 86 86 86 138 138 138 162 162 162
50089-154 154 154 38 38 38 26 26 26 6 6 6
50090- 2 2 6 2 2 6 2 2 6 2 2 6
50091- 86 86 86 46 46 46 14 14 14 0 0 0
50092- 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
50094- 0 0 0 0 0 0 0 0 0 0 0 0
50095- 0 0 0 0 0 0 0 0 0 0 0 0
50096- 0 0 0 0 0 0 0 0 0 0 0 0
50097- 0 0 0 0 0 0 0 0 0 0 0 0
50098- 0 0 0 0 0 0 0 0 0 0 0 0
50099- 0 0 0 0 0 0 0 0 0 0 0 0
50100- 0 0 0 0 0 0 0 0 0 0 0 0
50101- 0 0 0 0 0 0 0 0 0 0 0 0
50102- 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
50104- 0 0 0 0 0 0 0 0 0 14 14 14
50105- 46 46 46 86 86 86 2 2 6 14 14 14
50106-134 134 134 198 198 198 195 195 195 116 116 116
50107- 10 10 10 2 2 6 2 2 6 6 6 6
50108-101 98 89 187 187 187 210 210 210 218 218 218
50109-214 214 214 134 134 134 14 14 14 6 6 6
50110- 2 2 6 2 2 6 2 2 6 2 2 6
50111- 86 86 86 50 50 50 18 18 18 6 6 6
50112- 0 0 0 0 0 0 0 0 0 0 0 0
50113- 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
50115- 0 0 0 0 0 0 0 0 0 0 0 0
50116- 0 0 0 0 0 0 0 0 0 0 0 0
50117- 0 0 0 0 0 0 0 0 0 0 0 0
50118- 0 0 0 0 0 0 0 0 1 0 0 0
50119- 0 0 1 0 0 1 0 0 1 0 0 0
50120- 0 0 0 0 0 0 0 0 0 0 0 0
50121- 0 0 0 0 0 0 0 0 0 0 0 0
50122- 0 0 0 0 0 0 0 0 0 0 0 0
50123- 0 0 0 0 0 0 0 0 0 0 0 0
50124- 0 0 0 0 0 0 0 0 0 14 14 14
50125- 46 46 46 86 86 86 2 2 6 54 54 54
50126-218 218 218 195 195 195 226 226 226 246 246 246
50127- 58 58 58 2 2 6 2 2 6 30 30 30
50128-210 210 210 253 253 253 174 174 174 123 123 123
50129-221 221 221 234 234 234 74 74 74 2 2 6
50130- 2 2 6 2 2 6 2 2 6 2 2 6
50131- 70 70 70 58 58 58 22 22 22 6 6 6
50132- 0 0 0 0 0 0 0 0 0 0 0 0
50133- 0 0 0 0 0 0 0 0 0 0 0 0
50134- 0 0 0 0 0 0 0 0 0 0 0 0
50135- 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
50137- 0 0 0 0 0 0 0 0 0 0 0 0
50138- 0 0 0 0 0 0 0 0 0 0 0 0
50139- 0 0 0 0 0 0 0 0 0 0 0 0
50140- 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
50142- 0 0 0 0 0 0 0 0 0 0 0 0
50143- 0 0 0 0 0 0 0 0 0 0 0 0
50144- 0 0 0 0 0 0 0 0 0 14 14 14
50145- 46 46 46 82 82 82 2 2 6 106 106 106
50146-170 170 170 26 26 26 86 86 86 226 226 226
50147-123 123 123 10 10 10 14 14 14 46 46 46
50148-231 231 231 190 190 190 6 6 6 70 70 70
50149- 90 90 90 238 238 238 158 158 158 2 2 6
50150- 2 2 6 2 2 6 2 2 6 2 2 6
50151- 70 70 70 58 58 58 22 22 22 6 6 6
50152- 0 0 0 0 0 0 0 0 0 0 0 0
50153- 0 0 0 0 0 0 0 0 0 0 0 0
50154- 0 0 0 0 0 0 0 0 0 0 0 0
50155- 0 0 0 0 0 0 0 0 0 0 0 0
50156- 0 0 0 0 0 0 0 0 0 0 0 0
50157- 0 0 0 0 0 0 0 0 0 0 0 0
50158- 0 0 0 0 0 0 0 0 1 0 0 0
50159- 0 0 1 0 0 1 0 0 1 0 0 0
50160- 0 0 0 0 0 0 0 0 0 0 0 0
50161- 0 0 0 0 0 0 0 0 0 0 0 0
50162- 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
50164- 0 0 0 0 0 0 0 0 0 14 14 14
50165- 42 42 42 86 86 86 6 6 6 116 116 116
50166-106 106 106 6 6 6 70 70 70 149 149 149
50167-128 128 128 18 18 18 38 38 38 54 54 54
50168-221 221 221 106 106 106 2 2 6 14 14 14
50169- 46 46 46 190 190 190 198 198 198 2 2 6
50170- 2 2 6 2 2 6 2 2 6 2 2 6
50171- 74 74 74 62 62 62 22 22 22 6 6 6
50172- 0 0 0 0 0 0 0 0 0 0 0 0
50173- 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
50175- 0 0 0 0 0 0 0 0 0 0 0 0
50176- 0 0 0 0 0 0 0 0 0 0 0 0
50177- 0 0 0 0 0 0 0 0 0 0 0 0
50178- 0 0 0 0 0 0 0 0 1 0 0 0
50179- 0 0 1 0 0 0 0 0 1 0 0 0
50180- 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
50182- 0 0 0 0 0 0 0 0 0 0 0 0
50183- 0 0 0 0 0 0 0 0 0 0 0 0
50184- 0 0 0 0 0 0 0 0 0 14 14 14
50185- 42 42 42 94 94 94 14 14 14 101 101 101
50186-128 128 128 2 2 6 18 18 18 116 116 116
50187-118 98 46 121 92 8 121 92 8 98 78 10
50188-162 162 162 106 106 106 2 2 6 2 2 6
50189- 2 2 6 195 195 195 195 195 195 6 6 6
50190- 2 2 6 2 2 6 2 2 6 2 2 6
50191- 74 74 74 62 62 62 22 22 22 6 6 6
50192- 0 0 0 0 0 0 0 0 0 0 0 0
50193- 0 0 0 0 0 0 0 0 0 0 0 0
50194- 0 0 0 0 0 0 0 0 0 0 0 0
50195- 0 0 0 0 0 0 0 0 0 0 0 0
50196- 0 0 0 0 0 0 0 0 0 0 0 0
50197- 0 0 0 0 0 0 0 0 0 0 0 0
50198- 0 0 0 0 0 0 0 0 1 0 0 1
50199- 0 0 1 0 0 0 0 0 1 0 0 0
50200- 0 0 0 0 0 0 0 0 0 0 0 0
50201- 0 0 0 0 0 0 0 0 0 0 0 0
50202- 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
50204- 0 0 0 0 0 0 0 0 0 10 10 10
50205- 38 38 38 90 90 90 14 14 14 58 58 58
50206-210 210 210 26 26 26 54 38 6 154 114 10
50207-226 170 11 236 186 11 225 175 15 184 144 12
50208-215 174 15 175 146 61 37 26 9 2 2 6
50209- 70 70 70 246 246 246 138 138 138 2 2 6
50210- 2 2 6 2 2 6 2 2 6 2 2 6
50211- 70 70 70 66 66 66 26 26 26 6 6 6
50212- 0 0 0 0 0 0 0 0 0 0 0 0
50213- 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
50215- 0 0 0 0 0 0 0 0 0 0 0 0
50216- 0 0 0 0 0 0 0 0 0 0 0 0
50217- 0 0 0 0 0 0 0 0 0 0 0 0
50218- 0 0 0 0 0 0 0 0 0 0 0 0
50219- 0 0 0 0 0 0 0 0 0 0 0 0
50220- 0 0 0 0 0 0 0 0 0 0 0 0
50221- 0 0 0 0 0 0 0 0 0 0 0 0
50222- 0 0 0 0 0 0 0 0 0 0 0 0
50223- 0 0 0 0 0 0 0 0 0 0 0 0
50224- 0 0 0 0 0 0 0 0 0 10 10 10
50225- 38 38 38 86 86 86 14 14 14 10 10 10
50226-195 195 195 188 164 115 192 133 9 225 175 15
50227-239 182 13 234 190 10 232 195 16 232 200 30
50228-245 207 45 241 208 19 232 195 16 184 144 12
50229-218 194 134 211 206 186 42 42 42 2 2 6
50230- 2 2 6 2 2 6 2 2 6 2 2 6
50231- 50 50 50 74 74 74 30 30 30 6 6 6
50232- 0 0 0 0 0 0 0 0 0 0 0 0
50233- 0 0 0 0 0 0 0 0 0 0 0 0
50234- 0 0 0 0 0 0 0 0 0 0 0 0
50235- 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
50237- 0 0 0 0 0 0 0 0 0 0 0 0
50238- 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
50240- 0 0 0 0 0 0 0 0 0 0 0 0
50241- 0 0 0 0 0 0 0 0 0 0 0 0
50242- 0 0 0 0 0 0 0 0 0 0 0 0
50243- 0 0 0 0 0 0 0 0 0 0 0 0
50244- 0 0 0 0 0 0 0 0 0 10 10 10
50245- 34 34 34 86 86 86 14 14 14 2 2 6
50246-121 87 25 192 133 9 219 162 10 239 182 13
50247-236 186 11 232 195 16 241 208 19 244 214 54
50248-246 218 60 246 218 38 246 215 20 241 208 19
50249-241 208 19 226 184 13 121 87 25 2 2 6
50250- 2 2 6 2 2 6 2 2 6 2 2 6
50251- 50 50 50 82 82 82 34 34 34 10 10 10
50252- 0 0 0 0 0 0 0 0 0 0 0 0
50253- 0 0 0 0 0 0 0 0 0 0 0 0
50254- 0 0 0 0 0 0 0 0 0 0 0 0
50255- 0 0 0 0 0 0 0 0 0 0 0 0
50256- 0 0 0 0 0 0 0 0 0 0 0 0
50257- 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
50259- 0 0 0 0 0 0 0 0 0 0 0 0
50260- 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
50262- 0 0 0 0 0 0 0 0 0 0 0 0
50263- 0 0 0 0 0 0 0 0 0 0 0 0
50264- 0 0 0 0 0 0 0 0 0 10 10 10
50265- 34 34 34 82 82 82 30 30 30 61 42 6
50266-180 123 7 206 145 10 230 174 11 239 182 13
50267-234 190 10 238 202 15 241 208 19 246 218 74
50268-246 218 38 246 215 20 246 215 20 246 215 20
50269-226 184 13 215 174 15 184 144 12 6 6 6
50270- 2 2 6 2 2 6 2 2 6 2 2 6
50271- 26 26 26 94 94 94 42 42 42 14 14 14
50272- 0 0 0 0 0 0 0 0 0 0 0 0
50273- 0 0 0 0 0 0 0 0 0 0 0 0
50274- 0 0 0 0 0 0 0 0 0 0 0 0
50275- 0 0 0 0 0 0 0 0 0 0 0 0
50276- 0 0 0 0 0 0 0 0 0 0 0 0
50277- 0 0 0 0 0 0 0 0 0 0 0 0
50278- 0 0 0 0 0 0 0 0 0 0 0 0
50279- 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
50281- 0 0 0 0 0 0 0 0 0 0 0 0
50282- 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
50284- 0 0 0 0 0 0 0 0 0 10 10 10
50285- 30 30 30 78 78 78 50 50 50 104 69 6
50286-192 133 9 216 158 10 236 178 12 236 186 11
50287-232 195 16 241 208 19 244 214 54 245 215 43
50288-246 215 20 246 215 20 241 208 19 198 155 10
50289-200 144 11 216 158 10 156 118 10 2 2 6
50290- 2 2 6 2 2 6 2 2 6 2 2 6
50291- 6 6 6 90 90 90 54 54 54 18 18 18
50292- 6 6 6 0 0 0 0 0 0 0 0 0
50293- 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
50295- 0 0 0 0 0 0 0 0 0 0 0 0
50296- 0 0 0 0 0 0 0 0 0 0 0 0
50297- 0 0 0 0 0 0 0 0 0 0 0 0
50298- 0 0 0 0 0 0 0 0 0 0 0 0
50299- 0 0 0 0 0 0 0 0 0 0 0 0
50300- 0 0 0 0 0 0 0 0 0 0 0 0
50301- 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
50303- 0 0 0 0 0 0 0 0 0 0 0 0
50304- 0 0 0 0 0 0 0 0 0 10 10 10
50305- 30 30 30 78 78 78 46 46 46 22 22 22
50306-137 92 6 210 162 10 239 182 13 238 190 10
50307-238 202 15 241 208 19 246 215 20 246 215 20
50308-241 208 19 203 166 17 185 133 11 210 150 10
50309-216 158 10 210 150 10 102 78 10 2 2 6
50310- 6 6 6 54 54 54 14 14 14 2 2 6
50311- 2 2 6 62 62 62 74 74 74 30 30 30
50312- 10 10 10 0 0 0 0 0 0 0 0 0
50313- 0 0 0 0 0 0 0 0 0 0 0 0
50314- 0 0 0 0 0 0 0 0 0 0 0 0
50315- 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
50317- 0 0 0 0 0 0 0 0 0 0 0 0
50318- 0 0 0 0 0 0 0 0 0 0 0 0
50319- 0 0 0 0 0 0 0 0 0 0 0 0
50320- 0 0 0 0 0 0 0 0 0 0 0 0
50321- 0 0 0 0 0 0 0 0 0 0 0 0
50322- 0 0 0 0 0 0 0 0 0 0 0 0
50323- 0 0 0 0 0 0 0 0 0 0 0 0
50324- 0 0 0 0 0 0 0 0 0 10 10 10
50325- 34 34 34 78 78 78 50 50 50 6 6 6
50326- 94 70 30 139 102 15 190 146 13 226 184 13
50327-232 200 30 232 195 16 215 174 15 190 146 13
50328-168 122 10 192 133 9 210 150 10 213 154 11
50329-202 150 34 182 157 106 101 98 89 2 2 6
50330- 2 2 6 78 78 78 116 116 116 58 58 58
50331- 2 2 6 22 22 22 90 90 90 46 46 46
50332- 18 18 18 6 6 6 0 0 0 0 0 0
50333- 0 0 0 0 0 0 0 0 0 0 0 0
50334- 0 0 0 0 0 0 0 0 0 0 0 0
50335- 0 0 0 0 0 0 0 0 0 0 0 0
50336- 0 0 0 0 0 0 0 0 0 0 0 0
50337- 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
50339- 0 0 0 0 0 0 0 0 0 0 0 0
50340- 0 0 0 0 0 0 0 0 0 0 0 0
50341- 0 0 0 0 0 0 0 0 0 0 0 0
50342- 0 0 0 0 0 0 0 0 0 0 0 0
50343- 0 0 0 0 0 0 0 0 0 0 0 0
50344- 0 0 0 0 0 0 0 0 0 10 10 10
50345- 38 38 38 86 86 86 50 50 50 6 6 6
50346-128 128 128 174 154 114 156 107 11 168 122 10
50347-198 155 10 184 144 12 197 138 11 200 144 11
50348-206 145 10 206 145 10 197 138 11 188 164 115
50349-195 195 195 198 198 198 174 174 174 14 14 14
50350- 2 2 6 22 22 22 116 116 116 116 116 116
50351- 22 22 22 2 2 6 74 74 74 70 70 70
50352- 30 30 30 10 10 10 0 0 0 0 0 0
50353- 0 0 0 0 0 0 0 0 0 0 0 0
50354- 0 0 0 0 0 0 0 0 0 0 0 0
50355- 0 0 0 0 0 0 0 0 0 0 0 0
50356- 0 0 0 0 0 0 0 0 0 0 0 0
50357- 0 0 0 0 0 0 0 0 0 0 0 0
50358- 0 0 0 0 0 0 0 0 0 0 0 0
50359- 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
50361- 0 0 0 0 0 0 0 0 0 0 0 0
50362- 0 0 0 0 0 0 0 0 0 0 0 0
50363- 0 0 0 0 0 0 0 0 0 0 0 0
50364- 0 0 0 0 0 0 6 6 6 18 18 18
50365- 50 50 50 101 101 101 26 26 26 10 10 10
50366-138 138 138 190 190 190 174 154 114 156 107 11
50367-197 138 11 200 144 11 197 138 11 192 133 9
50368-180 123 7 190 142 34 190 178 144 187 187 187
50369-202 202 202 221 221 221 214 214 214 66 66 66
50370- 2 2 6 2 2 6 50 50 50 62 62 62
50371- 6 6 6 2 2 6 10 10 10 90 90 90
50372- 50 50 50 18 18 18 6 6 6 0 0 0
50373- 0 0 0 0 0 0 0 0 0 0 0 0
50374- 0 0 0 0 0 0 0 0 0 0 0 0
50375- 0 0 0 0 0 0 0 0 0 0 0 0
50376- 0 0 0 0 0 0 0 0 0 0 0 0
50377- 0 0 0 0 0 0 0 0 0 0 0 0
50378- 0 0 0 0 0 0 0 0 0 0 0 0
50379- 0 0 0 0 0 0 0 0 0 0 0 0
50380- 0 0 0 0 0 0 0 0 0 0 0 0
50381- 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
50383- 0 0 0 0 0 0 0 0 0 0 0 0
50384- 0 0 0 0 0 0 10 10 10 34 34 34
50385- 74 74 74 74 74 74 2 2 6 6 6 6
50386-144 144 144 198 198 198 190 190 190 178 166 146
50387-154 121 60 156 107 11 156 107 11 168 124 44
50388-174 154 114 187 187 187 190 190 190 210 210 210
50389-246 246 246 253 253 253 253 253 253 182 182 182
50390- 6 6 6 2 2 6 2 2 6 2 2 6
50391- 2 2 6 2 2 6 2 2 6 62 62 62
50392- 74 74 74 34 34 34 14 14 14 0 0 0
50393- 0 0 0 0 0 0 0 0 0 0 0 0
50394- 0 0 0 0 0 0 0 0 0 0 0 0
50395- 0 0 0 0 0 0 0 0 0 0 0 0
50396- 0 0 0 0 0 0 0 0 0 0 0 0
50397- 0 0 0 0 0 0 0 0 0 0 0 0
50398- 0 0 0 0 0 0 0 0 0 0 0 0
50399- 0 0 0 0 0 0 0 0 0 0 0 0
50400- 0 0 0 0 0 0 0 0 0 0 0 0
50401- 0 0 0 0 0 0 0 0 0 0 0 0
50402- 0 0 0 0 0 0 0 0 0 0 0 0
50403- 0 0 0 0 0 0 0 0 0 0 0 0
50404- 0 0 0 10 10 10 22 22 22 54 54 54
50405- 94 94 94 18 18 18 2 2 6 46 46 46
50406-234 234 234 221 221 221 190 190 190 190 190 190
50407-190 190 190 187 187 187 187 187 187 190 190 190
50408-190 190 190 195 195 195 214 214 214 242 242 242
50409-253 253 253 253 253 253 253 253 253 253 253 253
50410- 82 82 82 2 2 6 2 2 6 2 2 6
50411- 2 2 6 2 2 6 2 2 6 14 14 14
50412- 86 86 86 54 54 54 22 22 22 6 6 6
50413- 0 0 0 0 0 0 0 0 0 0 0 0
50414- 0 0 0 0 0 0 0 0 0 0 0 0
50415- 0 0 0 0 0 0 0 0 0 0 0 0
50416- 0 0 0 0 0 0 0 0 0 0 0 0
50417- 0 0 0 0 0 0 0 0 0 0 0 0
50418- 0 0 0 0 0 0 0 0 0 0 0 0
50419- 0 0 0 0 0 0 0 0 0 0 0 0
50420- 0 0 0 0 0 0 0 0 0 0 0 0
50421- 0 0 0 0 0 0 0 0 0 0 0 0
50422- 0 0 0 0 0 0 0 0 0 0 0 0
50423- 0 0 0 0 0 0 0 0 0 0 0 0
50424- 6 6 6 18 18 18 46 46 46 90 90 90
50425- 46 46 46 18 18 18 6 6 6 182 182 182
50426-253 253 253 246 246 246 206 206 206 190 190 190
50427-190 190 190 190 190 190 190 190 190 190 190 190
50428-206 206 206 231 231 231 250 250 250 253 253 253
50429-253 253 253 253 253 253 253 253 253 253 253 253
50430-202 202 202 14 14 14 2 2 6 2 2 6
50431- 2 2 6 2 2 6 2 2 6 2 2 6
50432- 42 42 42 86 86 86 42 42 42 18 18 18
50433- 6 6 6 0 0 0 0 0 0 0 0 0
50434- 0 0 0 0 0 0 0 0 0 0 0 0
50435- 0 0 0 0 0 0 0 0 0 0 0 0
50436- 0 0 0 0 0 0 0 0 0 0 0 0
50437- 0 0 0 0 0 0 0 0 0 0 0 0
50438- 0 0 0 0 0 0 0 0 0 0 0 0
50439- 0 0 0 0 0 0 0 0 0 0 0 0
50440- 0 0 0 0 0 0 0 0 0 0 0 0
50441- 0 0 0 0 0 0 0 0 0 0 0 0
50442- 0 0 0 0 0 0 0 0 0 0 0 0
50443- 0 0 0 0 0 0 0 0 0 6 6 6
50444- 14 14 14 38 38 38 74 74 74 66 66 66
50445- 2 2 6 6 6 6 90 90 90 250 250 250
50446-253 253 253 253 253 253 238 238 238 198 198 198
50447-190 190 190 190 190 190 195 195 195 221 221 221
50448-246 246 246 253 253 253 253 253 253 253 253 253
50449-253 253 253 253 253 253 253 253 253 253 253 253
50450-253 253 253 82 82 82 2 2 6 2 2 6
50451- 2 2 6 2 2 6 2 2 6 2 2 6
50452- 2 2 6 78 78 78 70 70 70 34 34 34
50453- 14 14 14 6 6 6 0 0 0 0 0 0
50454- 0 0 0 0 0 0 0 0 0 0 0 0
50455- 0 0 0 0 0 0 0 0 0 0 0 0
50456- 0 0 0 0 0 0 0 0 0 0 0 0
50457- 0 0 0 0 0 0 0 0 0 0 0 0
50458- 0 0 0 0 0 0 0 0 0 0 0 0
50459- 0 0 0 0 0 0 0 0 0 0 0 0
50460- 0 0 0 0 0 0 0 0 0 0 0 0
50461- 0 0 0 0 0 0 0 0 0 0 0 0
50462- 0 0 0 0 0 0 0 0 0 0 0 0
50463- 0 0 0 0 0 0 0 0 0 14 14 14
50464- 34 34 34 66 66 66 78 78 78 6 6 6
50465- 2 2 6 18 18 18 218 218 218 253 253 253
50466-253 253 253 253 253 253 253 253 253 246 246 246
50467-226 226 226 231 231 231 246 246 246 253 253 253
50468-253 253 253 253 253 253 253 253 253 253 253 253
50469-253 253 253 253 253 253 253 253 253 253 253 253
50470-253 253 253 178 178 178 2 2 6 2 2 6
50471- 2 2 6 2 2 6 2 2 6 2 2 6
50472- 2 2 6 18 18 18 90 90 90 62 62 62
50473- 30 30 30 10 10 10 0 0 0 0 0 0
50474- 0 0 0 0 0 0 0 0 0 0 0 0
50475- 0 0 0 0 0 0 0 0 0 0 0 0
50476- 0 0 0 0 0 0 0 0 0 0 0 0
50477- 0 0 0 0 0 0 0 0 0 0 0 0
50478- 0 0 0 0 0 0 0 0 0 0 0 0
50479- 0 0 0 0 0 0 0 0 0 0 0 0
50480- 0 0 0 0 0 0 0 0 0 0 0 0
50481- 0 0 0 0 0 0 0 0 0 0 0 0
50482- 0 0 0 0 0 0 0 0 0 0 0 0
50483- 0 0 0 0 0 0 10 10 10 26 26 26
50484- 58 58 58 90 90 90 18 18 18 2 2 6
50485- 2 2 6 110 110 110 253 253 253 253 253 253
50486-253 253 253 253 253 253 253 253 253 253 253 253
50487-250 250 250 253 253 253 253 253 253 253 253 253
50488-253 253 253 253 253 253 253 253 253 253 253 253
50489-253 253 253 253 253 253 253 253 253 253 253 253
50490-253 253 253 231 231 231 18 18 18 2 2 6
50491- 2 2 6 2 2 6 2 2 6 2 2 6
50492- 2 2 6 2 2 6 18 18 18 94 94 94
50493- 54 54 54 26 26 26 10 10 10 0 0 0
50494- 0 0 0 0 0 0 0 0 0 0 0 0
50495- 0 0 0 0 0 0 0 0 0 0 0 0
50496- 0 0 0 0 0 0 0 0 0 0 0 0
50497- 0 0 0 0 0 0 0 0 0 0 0 0
50498- 0 0 0 0 0 0 0 0 0 0 0 0
50499- 0 0 0 0 0 0 0 0 0 0 0 0
50500- 0 0 0 0 0 0 0 0 0 0 0 0
50501- 0 0 0 0 0 0 0 0 0 0 0 0
50502- 0 0 0 0 0 0 0 0 0 0 0 0
50503- 0 0 0 6 6 6 22 22 22 50 50 50
50504- 90 90 90 26 26 26 2 2 6 2 2 6
50505- 14 14 14 195 195 195 250 250 250 253 253 253
50506-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
50508-253 253 253 253 253 253 253 253 253 253 253 253
50509-253 253 253 253 253 253 253 253 253 253 253 253
50510-250 250 250 242 242 242 54 54 54 2 2 6
50511- 2 2 6 2 2 6 2 2 6 2 2 6
50512- 2 2 6 2 2 6 2 2 6 38 38 38
50513- 86 86 86 50 50 50 22 22 22 6 6 6
50514- 0 0 0 0 0 0 0 0 0 0 0 0
50515- 0 0 0 0 0 0 0 0 0 0 0 0
50516- 0 0 0 0 0 0 0 0 0 0 0 0
50517- 0 0 0 0 0 0 0 0 0 0 0 0
50518- 0 0 0 0 0 0 0 0 0 0 0 0
50519- 0 0 0 0 0 0 0 0 0 0 0 0
50520- 0 0 0 0 0 0 0 0 0 0 0 0
50521- 0 0 0 0 0 0 0 0 0 0 0 0
50522- 0 0 0 0 0 0 0 0 0 0 0 0
50523- 6 6 6 14 14 14 38 38 38 82 82 82
50524- 34 34 34 2 2 6 2 2 6 2 2 6
50525- 42 42 42 195 195 195 246 246 246 253 253 253
50526-253 253 253 253 253 253 253 253 253 250 250 250
50527-242 242 242 242 242 242 250 250 250 253 253 253
50528-253 253 253 253 253 253 253 253 253 253 253 253
50529-253 253 253 250 250 250 246 246 246 238 238 238
50530-226 226 226 231 231 231 101 101 101 6 6 6
50531- 2 2 6 2 2 6 2 2 6 2 2 6
50532- 2 2 6 2 2 6 2 2 6 2 2 6
50533- 38 38 38 82 82 82 42 42 42 14 14 14
50534- 6 6 6 0 0 0 0 0 0 0 0 0
50535- 0 0 0 0 0 0 0 0 0 0 0 0
50536- 0 0 0 0 0 0 0 0 0 0 0 0
50537- 0 0 0 0 0 0 0 0 0 0 0 0
50538- 0 0 0 0 0 0 0 0 0 0 0 0
50539- 0 0 0 0 0 0 0 0 0 0 0 0
50540- 0 0 0 0 0 0 0 0 0 0 0 0
50541- 0 0 0 0 0 0 0 0 0 0 0 0
50542- 0 0 0 0 0 0 0 0 0 0 0 0
50543- 10 10 10 26 26 26 62 62 62 66 66 66
50544- 2 2 6 2 2 6 2 2 6 6 6 6
50545- 70 70 70 170 170 170 206 206 206 234 234 234
50546-246 246 246 250 250 250 250 250 250 238 238 238
50547-226 226 226 231 231 231 238 238 238 250 250 250
50548-250 250 250 250 250 250 246 246 246 231 231 231
50549-214 214 214 206 206 206 202 202 202 202 202 202
50550-198 198 198 202 202 202 182 182 182 18 18 18
50551- 2 2 6 2 2 6 2 2 6 2 2 6
50552- 2 2 6 2 2 6 2 2 6 2 2 6
50553- 2 2 6 62 62 62 66 66 66 30 30 30
50554- 10 10 10 0 0 0 0 0 0 0 0 0
50555- 0 0 0 0 0 0 0 0 0 0 0 0
50556- 0 0 0 0 0 0 0 0 0 0 0 0
50557- 0 0 0 0 0 0 0 0 0 0 0 0
50558- 0 0 0 0 0 0 0 0 0 0 0 0
50559- 0 0 0 0 0 0 0 0 0 0 0 0
50560- 0 0 0 0 0 0 0 0 0 0 0 0
50561- 0 0 0 0 0 0 0 0 0 0 0 0
50562- 0 0 0 0 0 0 0 0 0 0 0 0
50563- 14 14 14 42 42 42 82 82 82 18 18 18
50564- 2 2 6 2 2 6 2 2 6 10 10 10
50565- 94 94 94 182 182 182 218 218 218 242 242 242
50566-250 250 250 253 253 253 253 253 253 250 250 250
50567-234 234 234 253 253 253 253 253 253 253 253 253
50568-253 253 253 253 253 253 253 253 253 246 246 246
50569-238 238 238 226 226 226 210 210 210 202 202 202
50570-195 195 195 195 195 195 210 210 210 158 158 158
50571- 6 6 6 14 14 14 50 50 50 14 14 14
50572- 2 2 6 2 2 6 2 2 6 2 2 6
50573- 2 2 6 6 6 6 86 86 86 46 46 46
50574- 18 18 18 6 6 6 0 0 0 0 0 0
50575- 0 0 0 0 0 0 0 0 0 0 0 0
50576- 0 0 0 0 0 0 0 0 0 0 0 0
50577- 0 0 0 0 0 0 0 0 0 0 0 0
50578- 0 0 0 0 0 0 0 0 0 0 0 0
50579- 0 0 0 0 0 0 0 0 0 0 0 0
50580- 0 0 0 0 0 0 0 0 0 0 0 0
50581- 0 0 0 0 0 0 0 0 0 0 0 0
50582- 0 0 0 0 0 0 0 0 0 6 6 6
50583- 22 22 22 54 54 54 70 70 70 2 2 6
50584- 2 2 6 10 10 10 2 2 6 22 22 22
50585-166 166 166 231 231 231 250 250 250 253 253 253
50586-253 253 253 253 253 253 253 253 253 250 250 250
50587-242 242 242 253 253 253 253 253 253 253 253 253
50588-253 253 253 253 253 253 253 253 253 253 253 253
50589-253 253 253 253 253 253 253 253 253 246 246 246
50590-231 231 231 206 206 206 198 198 198 226 226 226
50591- 94 94 94 2 2 6 6 6 6 38 38 38
50592- 30 30 30 2 2 6 2 2 6 2 2 6
50593- 2 2 6 2 2 6 62 62 62 66 66 66
50594- 26 26 26 10 10 10 0 0 0 0 0 0
50595- 0 0 0 0 0 0 0 0 0 0 0 0
50596- 0 0 0 0 0 0 0 0 0 0 0 0
50597- 0 0 0 0 0 0 0 0 0 0 0 0
50598- 0 0 0 0 0 0 0 0 0 0 0 0
50599- 0 0 0 0 0 0 0 0 0 0 0 0
50600- 0 0 0 0 0 0 0 0 0 0 0 0
50601- 0 0 0 0 0 0 0 0 0 0 0 0
50602- 0 0 0 0 0 0 0 0 0 10 10 10
50603- 30 30 30 74 74 74 50 50 50 2 2 6
50604- 26 26 26 26 26 26 2 2 6 106 106 106
50605-238 238 238 253 253 253 253 253 253 253 253 253
50606-253 253 253 253 253 253 253 253 253 253 253 253
50607-253 253 253 253 253 253 253 253 253 253 253 253
50608-253 253 253 253 253 253 253 253 253 253 253 253
50609-253 253 253 253 253 253 253 253 253 253 253 253
50610-253 253 253 246 246 246 218 218 218 202 202 202
50611-210 210 210 14 14 14 2 2 6 2 2 6
50612- 30 30 30 22 22 22 2 2 6 2 2 6
50613- 2 2 6 2 2 6 18 18 18 86 86 86
50614- 42 42 42 14 14 14 0 0 0 0 0 0
50615- 0 0 0 0 0 0 0 0 0 0 0 0
50616- 0 0 0 0 0 0 0 0 0 0 0 0
50617- 0 0 0 0 0 0 0 0 0 0 0 0
50618- 0 0 0 0 0 0 0 0 0 0 0 0
50619- 0 0 0 0 0 0 0 0 0 0 0 0
50620- 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
50622- 0 0 0 0 0 0 0 0 0 14 14 14
50623- 42 42 42 90 90 90 22 22 22 2 2 6
50624- 42 42 42 2 2 6 18 18 18 218 218 218
50625-253 253 253 253 253 253 253 253 253 253 253 253
50626-253 253 253 253 253 253 253 253 253 253 253 253
50627-253 253 253 253 253 253 253 253 253 253 253 253
50628-253 253 253 253 253 253 253 253 253 253 253 253
50629-253 253 253 253 253 253 253 253 253 253 253 253
50630-253 253 253 253 253 253 250 250 250 221 221 221
50631-218 218 218 101 101 101 2 2 6 14 14 14
50632- 18 18 18 38 38 38 10 10 10 2 2 6
50633- 2 2 6 2 2 6 2 2 6 78 78 78
50634- 58 58 58 22 22 22 6 6 6 0 0 0
50635- 0 0 0 0 0 0 0 0 0 0 0 0
50636- 0 0 0 0 0 0 0 0 0 0 0 0
50637- 0 0 0 0 0 0 0 0 0 0 0 0
50638- 0 0 0 0 0 0 0 0 0 0 0 0
50639- 0 0 0 0 0 0 0 0 0 0 0 0
50640- 0 0 0 0 0 0 0 0 0 0 0 0
50641- 0 0 0 0 0 0 0 0 0 0 0 0
50642- 0 0 0 0 0 0 6 6 6 18 18 18
50643- 54 54 54 82 82 82 2 2 6 26 26 26
50644- 22 22 22 2 2 6 123 123 123 253 253 253
50645-253 253 253 253 253 253 253 253 253 253 253 253
50646-253 253 253 253 253 253 253 253 253 253 253 253
50647-253 253 253 253 253 253 253 253 253 253 253 253
50648-253 253 253 253 253 253 253 253 253 253 253 253
50649-253 253 253 253 253 253 253 253 253 253 253 253
50650-253 253 253 253 253 253 253 253 253 250 250 250
50651-238 238 238 198 198 198 6 6 6 38 38 38
50652- 58 58 58 26 26 26 38 38 38 2 2 6
50653- 2 2 6 2 2 6 2 2 6 46 46 46
50654- 78 78 78 30 30 30 10 10 10 0 0 0
50655- 0 0 0 0 0 0 0 0 0 0 0 0
50656- 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
50658- 0 0 0 0 0 0 0 0 0 0 0 0
50659- 0 0 0 0 0 0 0 0 0 0 0 0
50660- 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
50662- 0 0 0 0 0 0 10 10 10 30 30 30
50663- 74 74 74 58 58 58 2 2 6 42 42 42
50664- 2 2 6 22 22 22 231 231 231 253 253 253
50665-253 253 253 253 253 253 253 253 253 253 253 253
50666-253 253 253 253 253 253 253 253 253 250 250 250
50667-253 253 253 253 253 253 253 253 253 253 253 253
50668-253 253 253 253 253 253 253 253 253 253 253 253
50669-253 253 253 253 253 253 253 253 253 253 253 253
50670-253 253 253 253 253 253 253 253 253 253 253 253
50671-253 253 253 246 246 246 46 46 46 38 38 38
50672- 42 42 42 14 14 14 38 38 38 14 14 14
50673- 2 2 6 2 2 6 2 2 6 6 6 6
50674- 86 86 86 46 46 46 14 14 14 0 0 0
50675- 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
50677- 0 0 0 0 0 0 0 0 0 0 0 0
50678- 0 0 0 0 0 0 0 0 0 0 0 0
50679- 0 0 0 0 0 0 0 0 0 0 0 0
50680- 0 0 0 0 0 0 0 0 0 0 0 0
50681- 0 0 0 0 0 0 0 0 0 0 0 0
50682- 0 0 0 6 6 6 14 14 14 42 42 42
50683- 90 90 90 18 18 18 18 18 18 26 26 26
50684- 2 2 6 116 116 116 253 253 253 253 253 253
50685-253 253 253 253 253 253 253 253 253 253 253 253
50686-253 253 253 253 253 253 250 250 250 238 238 238
50687-253 253 253 253 253 253 253 253 253 253 253 253
50688-253 253 253 253 253 253 253 253 253 253 253 253
50689-253 253 253 253 253 253 253 253 253 253 253 253
50690-253 253 253 253 253 253 253 253 253 253 253 253
50691-253 253 253 253 253 253 94 94 94 6 6 6
50692- 2 2 6 2 2 6 10 10 10 34 34 34
50693- 2 2 6 2 2 6 2 2 6 2 2 6
50694- 74 74 74 58 58 58 22 22 22 6 6 6
50695- 0 0 0 0 0 0 0 0 0 0 0 0
50696- 0 0 0 0 0 0 0 0 0 0 0 0
50697- 0 0 0 0 0 0 0 0 0 0 0 0
50698- 0 0 0 0 0 0 0 0 0 0 0 0
50699- 0 0 0 0 0 0 0 0 0 0 0 0
50700- 0 0 0 0 0 0 0 0 0 0 0 0
50701- 0 0 0 0 0 0 0 0 0 0 0 0
50702- 0 0 0 10 10 10 26 26 26 66 66 66
50703- 82 82 82 2 2 6 38 38 38 6 6 6
50704- 14 14 14 210 210 210 253 253 253 253 253 253
50705-253 253 253 253 253 253 253 253 253 253 253 253
50706-253 253 253 253 253 253 246 246 246 242 242 242
50707-253 253 253 253 253 253 253 253 253 253 253 253
50708-253 253 253 253 253 253 253 253 253 253 253 253
50709-253 253 253 253 253 253 253 253 253 253 253 253
50710-253 253 253 253 253 253 253 253 253 253 253 253
50711-253 253 253 253 253 253 144 144 144 2 2 6
50712- 2 2 6 2 2 6 2 2 6 46 46 46
50713- 2 2 6 2 2 6 2 2 6 2 2 6
50714- 42 42 42 74 74 74 30 30 30 10 10 10
50715- 0 0 0 0 0 0 0 0 0 0 0 0
50716- 0 0 0 0 0 0 0 0 0 0 0 0
50717- 0 0 0 0 0 0 0 0 0 0 0 0
50718- 0 0 0 0 0 0 0 0 0 0 0 0
50719- 0 0 0 0 0 0 0 0 0 0 0 0
50720- 0 0 0 0 0 0 0 0 0 0 0 0
50721- 0 0 0 0 0 0 0 0 0 0 0 0
50722- 6 6 6 14 14 14 42 42 42 90 90 90
50723- 26 26 26 6 6 6 42 42 42 2 2 6
50724- 74 74 74 250 250 250 253 253 253 253 253 253
50725-253 253 253 253 253 253 253 253 253 253 253 253
50726-253 253 253 253 253 253 242 242 242 242 242 242
50727-253 253 253 253 253 253 253 253 253 253 253 253
50728-253 253 253 253 253 253 253 253 253 253 253 253
50729-253 253 253 253 253 253 253 253 253 253 253 253
50730-253 253 253 253 253 253 253 253 253 253 253 253
50731-253 253 253 253 253 253 182 182 182 2 2 6
50732- 2 2 6 2 2 6 2 2 6 46 46 46
50733- 2 2 6 2 2 6 2 2 6 2 2 6
50734- 10 10 10 86 86 86 38 38 38 10 10 10
50735- 0 0 0 0 0 0 0 0 0 0 0 0
50736- 0 0 0 0 0 0 0 0 0 0 0 0
50737- 0 0 0 0 0 0 0 0 0 0 0 0
50738- 0 0 0 0 0 0 0 0 0 0 0 0
50739- 0 0 0 0 0 0 0 0 0 0 0 0
50740- 0 0 0 0 0 0 0 0 0 0 0 0
50741- 0 0 0 0 0 0 0 0 0 0 0 0
50742- 10 10 10 26 26 26 66 66 66 82 82 82
50743- 2 2 6 22 22 22 18 18 18 2 2 6
50744-149 149 149 253 253 253 253 253 253 253 253 253
50745-253 253 253 253 253 253 253 253 253 253 253 253
50746-253 253 253 253 253 253 234 234 234 242 242 242
50747-253 253 253 253 253 253 253 253 253 253 253 253
50748-253 253 253 253 253 253 253 253 253 253 253 253
50749-253 253 253 253 253 253 253 253 253 253 253 253
50750-253 253 253 253 253 253 253 253 253 253 253 253
50751-253 253 253 253 253 253 206 206 206 2 2 6
50752- 2 2 6 2 2 6 2 2 6 38 38 38
50753- 2 2 6 2 2 6 2 2 6 2 2 6
50754- 6 6 6 86 86 86 46 46 46 14 14 14
50755- 0 0 0 0 0 0 0 0 0 0 0 0
50756- 0 0 0 0 0 0 0 0 0 0 0 0
50757- 0 0 0 0 0 0 0 0 0 0 0 0
50758- 0 0 0 0 0 0 0 0 0 0 0 0
50759- 0 0 0 0 0 0 0 0 0 0 0 0
50760- 0 0 0 0 0 0 0 0 0 0 0 0
50761- 0 0 0 0 0 0 0 0 0 6 6 6
50762- 18 18 18 46 46 46 86 86 86 18 18 18
50763- 2 2 6 34 34 34 10 10 10 6 6 6
50764-210 210 210 253 253 253 253 253 253 253 253 253
50765-253 253 253 253 253 253 253 253 253 253 253 253
50766-253 253 253 253 253 253 234 234 234 242 242 242
50767-253 253 253 253 253 253 253 253 253 253 253 253
50768-253 253 253 253 253 253 253 253 253 253 253 253
50769-253 253 253 253 253 253 253 253 253 253 253 253
50770-253 253 253 253 253 253 253 253 253 253 253 253
50771-253 253 253 253 253 253 221 221 221 6 6 6
50772- 2 2 6 2 2 6 6 6 6 30 30 30
50773- 2 2 6 2 2 6 2 2 6 2 2 6
50774- 2 2 6 82 82 82 54 54 54 18 18 18
50775- 6 6 6 0 0 0 0 0 0 0 0 0
50776- 0 0 0 0 0 0 0 0 0 0 0 0
50777- 0 0 0 0 0 0 0 0 0 0 0 0
50778- 0 0 0 0 0 0 0 0 0 0 0 0
50779- 0 0 0 0 0 0 0 0 0 0 0 0
50780- 0 0 0 0 0 0 0 0 0 0 0 0
50781- 0 0 0 0 0 0 0 0 0 10 10 10
50782- 26 26 26 66 66 66 62 62 62 2 2 6
50783- 2 2 6 38 38 38 10 10 10 26 26 26
50784-238 238 238 253 253 253 253 253 253 253 253 253
50785-253 253 253 253 253 253 253 253 253 253 253 253
50786-253 253 253 253 253 253 231 231 231 238 238 238
50787-253 253 253 253 253 253 253 253 253 253 253 253
50788-253 253 253 253 253 253 253 253 253 253 253 253
50789-253 253 253 253 253 253 253 253 253 253 253 253
50790-253 253 253 253 253 253 253 253 253 253 253 253
50791-253 253 253 253 253 253 231 231 231 6 6 6
50792- 2 2 6 2 2 6 10 10 10 30 30 30
50793- 2 2 6 2 2 6 2 2 6 2 2 6
50794- 2 2 6 66 66 66 58 58 58 22 22 22
50795- 6 6 6 0 0 0 0 0 0 0 0 0
50796- 0 0 0 0 0 0 0 0 0 0 0 0
50797- 0 0 0 0 0 0 0 0 0 0 0 0
50798- 0 0 0 0 0 0 0 0 0 0 0 0
50799- 0 0 0 0 0 0 0 0 0 0 0 0
50800- 0 0 0 0 0 0 0 0 0 0 0 0
50801- 0 0 0 0 0 0 0 0 0 10 10 10
50802- 38 38 38 78 78 78 6 6 6 2 2 6
50803- 2 2 6 46 46 46 14 14 14 42 42 42
50804-246 246 246 253 253 253 253 253 253 253 253 253
50805-253 253 253 253 253 253 253 253 253 253 253 253
50806-253 253 253 253 253 253 231 231 231 242 242 242
50807-253 253 253 253 253 253 253 253 253 253 253 253
50808-253 253 253 253 253 253 253 253 253 253 253 253
50809-253 253 253 253 253 253 253 253 253 253 253 253
50810-253 253 253 253 253 253 253 253 253 253 253 253
50811-253 253 253 253 253 253 234 234 234 10 10 10
50812- 2 2 6 2 2 6 22 22 22 14 14 14
50813- 2 2 6 2 2 6 2 2 6 2 2 6
50814- 2 2 6 66 66 66 62 62 62 22 22 22
50815- 6 6 6 0 0 0 0 0 0 0 0 0
50816- 0 0 0 0 0 0 0 0 0 0 0 0
50817- 0 0 0 0 0 0 0 0 0 0 0 0
50818- 0 0 0 0 0 0 0 0 0 0 0 0
50819- 0 0 0 0 0 0 0 0 0 0 0 0
50820- 0 0 0 0 0 0 0 0 0 0 0 0
50821- 0 0 0 0 0 0 6 6 6 18 18 18
50822- 50 50 50 74 74 74 2 2 6 2 2 6
50823- 14 14 14 70 70 70 34 34 34 62 62 62
50824-250 250 250 253 253 253 253 253 253 253 253 253
50825-253 253 253 253 253 253 253 253 253 253 253 253
50826-253 253 253 253 253 253 231 231 231 246 246 246
50827-253 253 253 253 253 253 253 253 253 253 253 253
50828-253 253 253 253 253 253 253 253 253 253 253 253
50829-253 253 253 253 253 253 253 253 253 253 253 253
50830-253 253 253 253 253 253 253 253 253 253 253 253
50831-253 253 253 253 253 253 234 234 234 14 14 14
50832- 2 2 6 2 2 6 30 30 30 2 2 6
50833- 2 2 6 2 2 6 2 2 6 2 2 6
50834- 2 2 6 66 66 66 62 62 62 22 22 22
50835- 6 6 6 0 0 0 0 0 0 0 0 0
50836- 0 0 0 0 0 0 0 0 0 0 0 0
50837- 0 0 0 0 0 0 0 0 0 0 0 0
50838- 0 0 0 0 0 0 0 0 0 0 0 0
50839- 0 0 0 0 0 0 0 0 0 0 0 0
50840- 0 0 0 0 0 0 0 0 0 0 0 0
50841- 0 0 0 0 0 0 6 6 6 18 18 18
50842- 54 54 54 62 62 62 2 2 6 2 2 6
50843- 2 2 6 30 30 30 46 46 46 70 70 70
50844-250 250 250 253 253 253 253 253 253 253 253 253
50845-253 253 253 253 253 253 253 253 253 253 253 253
50846-253 253 253 253 253 253 231 231 231 246 246 246
50847-253 253 253 253 253 253 253 253 253 253 253 253
50848-253 253 253 253 253 253 253 253 253 253 253 253
50849-253 253 253 253 253 253 253 253 253 253 253 253
50850-253 253 253 253 253 253 253 253 253 253 253 253
50851-253 253 253 253 253 253 226 226 226 10 10 10
50852- 2 2 6 6 6 6 30 30 30 2 2 6
50853- 2 2 6 2 2 6 2 2 6 2 2 6
50854- 2 2 6 66 66 66 58 58 58 22 22 22
50855- 6 6 6 0 0 0 0 0 0 0 0 0
50856- 0 0 0 0 0 0 0 0 0 0 0 0
50857- 0 0 0 0 0 0 0 0 0 0 0 0
50858- 0 0 0 0 0 0 0 0 0 0 0 0
50859- 0 0 0 0 0 0 0 0 0 0 0 0
50860- 0 0 0 0 0 0 0 0 0 0 0 0
50861- 0 0 0 0 0 0 6 6 6 22 22 22
50862- 58 58 58 62 62 62 2 2 6 2 2 6
50863- 2 2 6 2 2 6 30 30 30 78 78 78
50864-250 250 250 253 253 253 253 253 253 253 253 253
50865-253 253 253 253 253 253 253 253 253 253 253 253
50866-253 253 253 253 253 253 231 231 231 246 246 246
50867-253 253 253 253 253 253 253 253 253 253 253 253
50868-253 253 253 253 253 253 253 253 253 253 253 253
50869-253 253 253 253 253 253 253 253 253 253 253 253
50870-253 253 253 253 253 253 253 253 253 253 253 253
50871-253 253 253 253 253 253 206 206 206 2 2 6
50872- 22 22 22 34 34 34 18 14 6 22 22 22
50873- 26 26 26 18 18 18 6 6 6 2 2 6
50874- 2 2 6 82 82 82 54 54 54 18 18 18
50875- 6 6 6 0 0 0 0 0 0 0 0 0
50876- 0 0 0 0 0 0 0 0 0 0 0 0
50877- 0 0 0 0 0 0 0 0 0 0 0 0
50878- 0 0 0 0 0 0 0 0 0 0 0 0
50879- 0 0 0 0 0 0 0 0 0 0 0 0
50880- 0 0 0 0 0 0 0 0 0 0 0 0
50881- 0 0 0 0 0 0 6 6 6 26 26 26
50882- 62 62 62 106 106 106 74 54 14 185 133 11
50883-210 162 10 121 92 8 6 6 6 62 62 62
50884-238 238 238 253 253 253 253 253 253 253 253 253
50885-253 253 253 253 253 253 253 253 253 253 253 253
50886-253 253 253 253 253 253 231 231 231 246 246 246
50887-253 253 253 253 253 253 253 253 253 253 253 253
50888-253 253 253 253 253 253 253 253 253 253 253 253
50889-253 253 253 253 253 253 253 253 253 253 253 253
50890-253 253 253 253 253 253 253 253 253 253 253 253
50891-253 253 253 253 253 253 158 158 158 18 18 18
50892- 14 14 14 2 2 6 2 2 6 2 2 6
50893- 6 6 6 18 18 18 66 66 66 38 38 38
50894- 6 6 6 94 94 94 50 50 50 18 18 18
50895- 6 6 6 0 0 0 0 0 0 0 0 0
50896- 0 0 0 0 0 0 0 0 0 0 0 0
50897- 0 0 0 0 0 0 0 0 0 0 0 0
50898- 0 0 0 0 0 0 0 0 0 0 0 0
50899- 0 0 0 0 0 0 0 0 0 0 0 0
50900- 0 0 0 0 0 0 0 0 0 6 6 6
50901- 10 10 10 10 10 10 18 18 18 38 38 38
50902- 78 78 78 142 134 106 216 158 10 242 186 14
50903-246 190 14 246 190 14 156 118 10 10 10 10
50904- 90 90 90 238 238 238 253 253 253 253 253 253
50905-253 253 253 253 253 253 253 253 253 253 253 253
50906-253 253 253 253 253 253 231 231 231 250 250 250
50907-253 253 253 253 253 253 253 253 253 253 253 253
50908-253 253 253 253 253 253 253 253 253 253 253 253
50909-253 253 253 253 253 253 253 253 253 253 253 253
50910-253 253 253 253 253 253 253 253 253 246 230 190
50911-238 204 91 238 204 91 181 142 44 37 26 9
50912- 2 2 6 2 2 6 2 2 6 2 2 6
50913- 2 2 6 2 2 6 38 38 38 46 46 46
50914- 26 26 26 106 106 106 54 54 54 18 18 18
50915- 6 6 6 0 0 0 0 0 0 0 0 0
50916- 0 0 0 0 0 0 0 0 0 0 0 0
50917- 0 0 0 0 0 0 0 0 0 0 0 0
50918- 0 0 0 0 0 0 0 0 0 0 0 0
50919- 0 0 0 0 0 0 0 0 0 0 0 0
50920- 0 0 0 6 6 6 14 14 14 22 22 22
50921- 30 30 30 38 38 38 50 50 50 70 70 70
50922-106 106 106 190 142 34 226 170 11 242 186 14
50923-246 190 14 246 190 14 246 190 14 154 114 10
50924- 6 6 6 74 74 74 226 226 226 253 253 253
50925-253 253 253 253 253 253 253 253 253 253 253 253
50926-253 253 253 253 253 253 231 231 231 250 250 250
50927-253 253 253 253 253 253 253 253 253 253 253 253
50928-253 253 253 253 253 253 253 253 253 253 253 253
50929-253 253 253 253 253 253 253 253 253 253 253 253
50930-253 253 253 253 253 253 253 253 253 228 184 62
50931-241 196 14 241 208 19 232 195 16 38 30 10
50932- 2 2 6 2 2 6 2 2 6 2 2 6
50933- 2 2 6 6 6 6 30 30 30 26 26 26
50934-203 166 17 154 142 90 66 66 66 26 26 26
50935- 6 6 6 0 0 0 0 0 0 0 0 0
50936- 0 0 0 0 0 0 0 0 0 0 0 0
50937- 0 0 0 0 0 0 0 0 0 0 0 0
50938- 0 0 0 0 0 0 0 0 0 0 0 0
50939- 0 0 0 0 0 0 0 0 0 0 0 0
50940- 6 6 6 18 18 18 38 38 38 58 58 58
50941- 78 78 78 86 86 86 101 101 101 123 123 123
50942-175 146 61 210 150 10 234 174 13 246 186 14
50943-246 190 14 246 190 14 246 190 14 238 190 10
50944-102 78 10 2 2 6 46 46 46 198 198 198
50945-253 253 253 253 253 253 253 253 253 253 253 253
50946-253 253 253 253 253 253 234 234 234 242 242 242
50947-253 253 253 253 253 253 253 253 253 253 253 253
50948-253 253 253 253 253 253 253 253 253 253 253 253
50949-253 253 253 253 253 253 253 253 253 253 253 253
50950-253 253 253 253 253 253 253 253 253 224 178 62
50951-242 186 14 241 196 14 210 166 10 22 18 6
50952- 2 2 6 2 2 6 2 2 6 2 2 6
50953- 2 2 6 2 2 6 6 6 6 121 92 8
50954-238 202 15 232 195 16 82 82 82 34 34 34
50955- 10 10 10 0 0 0 0 0 0 0 0 0
50956- 0 0 0 0 0 0 0 0 0 0 0 0
50957- 0 0 0 0 0 0 0 0 0 0 0 0
50958- 0 0 0 0 0 0 0 0 0 0 0 0
50959- 0 0 0 0 0 0 0 0 0 0 0 0
50960- 14 14 14 38 38 38 70 70 70 154 122 46
50961-190 142 34 200 144 11 197 138 11 197 138 11
50962-213 154 11 226 170 11 242 186 14 246 190 14
50963-246 190 14 246 190 14 246 190 14 246 190 14
50964-225 175 15 46 32 6 2 2 6 22 22 22
50965-158 158 158 250 250 250 253 253 253 253 253 253
50966-253 253 253 253 253 253 253 253 253 253 253 253
50967-253 253 253 253 253 253 253 253 253 253 253 253
50968-253 253 253 253 253 253 253 253 253 253 253 253
50969-253 253 253 253 253 253 253 253 253 253 253 253
50970-253 253 253 250 250 250 242 242 242 224 178 62
50971-239 182 13 236 186 11 213 154 11 46 32 6
50972- 2 2 6 2 2 6 2 2 6 2 2 6
50973- 2 2 6 2 2 6 61 42 6 225 175 15
50974-238 190 10 236 186 11 112 100 78 42 42 42
50975- 14 14 14 0 0 0 0 0 0 0 0 0
50976- 0 0 0 0 0 0 0 0 0 0 0 0
50977- 0 0 0 0 0 0 0 0 0 0 0 0
50978- 0 0 0 0 0 0 0 0 0 0 0 0
50979- 0 0 0 0 0 0 0 0 0 6 6 6
50980- 22 22 22 54 54 54 154 122 46 213 154 11
50981-226 170 11 230 174 11 226 170 11 226 170 11
50982-236 178 12 242 186 14 246 190 14 246 190 14
50983-246 190 14 246 190 14 246 190 14 246 190 14
50984-241 196 14 184 144 12 10 10 10 2 2 6
50985- 6 6 6 116 116 116 242 242 242 253 253 253
50986-253 253 253 253 253 253 253 253 253 253 253 253
50987-253 253 253 253 253 253 253 253 253 253 253 253
50988-253 253 253 253 253 253 253 253 253 253 253 253
50989-253 253 253 253 253 253 253 253 253 253 253 253
50990-253 253 253 231 231 231 198 198 198 214 170 54
50991-236 178 12 236 178 12 210 150 10 137 92 6
50992- 18 14 6 2 2 6 2 2 6 2 2 6
50993- 6 6 6 70 47 6 200 144 11 236 178 12
50994-239 182 13 239 182 13 124 112 88 58 58 58
50995- 22 22 22 6 6 6 0 0 0 0 0 0
50996- 0 0 0 0 0 0 0 0 0 0 0 0
50997- 0 0 0 0 0 0 0 0 0 0 0 0
50998- 0 0 0 0 0 0 0 0 0 0 0 0
50999- 0 0 0 0 0 0 0 0 0 10 10 10
51000- 30 30 30 70 70 70 180 133 36 226 170 11
51001-239 182 13 242 186 14 242 186 14 246 186 14
51002-246 190 14 246 190 14 246 190 14 246 190 14
51003-246 190 14 246 190 14 246 190 14 246 190 14
51004-246 190 14 232 195 16 98 70 6 2 2 6
51005- 2 2 6 2 2 6 66 66 66 221 221 221
51006-253 253 253 253 253 253 253 253 253 253 253 253
51007-253 253 253 253 253 253 253 253 253 253 253 253
51008-253 253 253 253 253 253 253 253 253 253 253 253
51009-253 253 253 253 253 253 253 253 253 253 253 253
51010-253 253 253 206 206 206 198 198 198 214 166 58
51011-230 174 11 230 174 11 216 158 10 192 133 9
51012-163 110 8 116 81 8 102 78 10 116 81 8
51013-167 114 7 197 138 11 226 170 11 239 182 13
51014-242 186 14 242 186 14 162 146 94 78 78 78
51015- 34 34 34 14 14 14 6 6 6 0 0 0
51016- 0 0 0 0 0 0 0 0 0 0 0 0
51017- 0 0 0 0 0 0 0 0 0 0 0 0
51018- 0 0 0 0 0 0 0 0 0 0 0 0
51019- 0 0 0 0 0 0 0 0 0 6 6 6
51020- 30 30 30 78 78 78 190 142 34 226 170 11
51021-239 182 13 246 190 14 246 190 14 246 190 14
51022-246 190 14 246 190 14 246 190 14 246 190 14
51023-246 190 14 246 190 14 246 190 14 246 190 14
51024-246 190 14 241 196 14 203 166 17 22 18 6
51025- 2 2 6 2 2 6 2 2 6 38 38 38
51026-218 218 218 253 253 253 253 253 253 253 253 253
51027-253 253 253 253 253 253 253 253 253 253 253 253
51028-253 253 253 253 253 253 253 253 253 253 253 253
51029-253 253 253 253 253 253 253 253 253 253 253 253
51030-250 250 250 206 206 206 198 198 198 202 162 69
51031-226 170 11 236 178 12 224 166 10 210 150 10
51032-200 144 11 197 138 11 192 133 9 197 138 11
51033-210 150 10 226 170 11 242 186 14 246 190 14
51034-246 190 14 246 186 14 225 175 15 124 112 88
51035- 62 62 62 30 30 30 14 14 14 6 6 6
51036- 0 0 0 0 0 0 0 0 0 0 0 0
51037- 0 0 0 0 0 0 0 0 0 0 0 0
51038- 0 0 0 0 0 0 0 0 0 0 0 0
51039- 0 0 0 0 0 0 0 0 0 10 10 10
51040- 30 30 30 78 78 78 174 135 50 224 166 10
51041-239 182 13 246 190 14 246 190 14 246 190 14
51042-246 190 14 246 190 14 246 190 14 246 190 14
51043-246 190 14 246 190 14 246 190 14 246 190 14
51044-246 190 14 246 190 14 241 196 14 139 102 15
51045- 2 2 6 2 2 6 2 2 6 2 2 6
51046- 78 78 78 250 250 250 253 253 253 253 253 253
51047-253 253 253 253 253 253 253 253 253 253 253 253
51048-253 253 253 253 253 253 253 253 253 253 253 253
51049-253 253 253 253 253 253 253 253 253 253 253 253
51050-250 250 250 214 214 214 198 198 198 190 150 46
51051-219 162 10 236 178 12 234 174 13 224 166 10
51052-216 158 10 213 154 11 213 154 11 216 158 10
51053-226 170 11 239 182 13 246 190 14 246 190 14
51054-246 190 14 246 190 14 242 186 14 206 162 42
51055-101 101 101 58 58 58 30 30 30 14 14 14
51056- 6 6 6 0 0 0 0 0 0 0 0 0
51057- 0 0 0 0 0 0 0 0 0 0 0 0
51058- 0 0 0 0 0 0 0 0 0 0 0 0
51059- 0 0 0 0 0 0 0 0 0 10 10 10
51060- 30 30 30 74 74 74 174 135 50 216 158 10
51061-236 178 12 246 190 14 246 190 14 246 190 14
51062-246 190 14 246 190 14 246 190 14 246 190 14
51063-246 190 14 246 190 14 246 190 14 246 190 14
51064-246 190 14 246 190 14 241 196 14 226 184 13
51065- 61 42 6 2 2 6 2 2 6 2 2 6
51066- 22 22 22 238 238 238 253 253 253 253 253 253
51067-253 253 253 253 253 253 253 253 253 253 253 253
51068-253 253 253 253 253 253 253 253 253 253 253 253
51069-253 253 253 253 253 253 253 253 253 253 253 253
51070-253 253 253 226 226 226 187 187 187 180 133 36
51071-216 158 10 236 178 12 239 182 13 236 178 12
51072-230 174 11 226 170 11 226 170 11 230 174 11
51073-236 178 12 242 186 14 246 190 14 246 190 14
51074-246 190 14 246 190 14 246 186 14 239 182 13
51075-206 162 42 106 106 106 66 66 66 34 34 34
51076- 14 14 14 6 6 6 0 0 0 0 0 0
51077- 0 0 0 0 0 0 0 0 0 0 0 0
51078- 0 0 0 0 0 0 0 0 0 0 0 0
51079- 0 0 0 0 0 0 0 0 0 6 6 6
51080- 26 26 26 70 70 70 163 133 67 213 154 11
51081-236 178 12 246 190 14 246 190 14 246 190 14
51082-246 190 14 246 190 14 246 190 14 246 190 14
51083-246 190 14 246 190 14 246 190 14 246 190 14
51084-246 190 14 246 190 14 246 190 14 241 196 14
51085-190 146 13 18 14 6 2 2 6 2 2 6
51086- 46 46 46 246 246 246 253 253 253 253 253 253
51087-253 253 253 253 253 253 253 253 253 253 253 253
51088-253 253 253 253 253 253 253 253 253 253 253 253
51089-253 253 253 253 253 253 253 253 253 253 253 253
51090-253 253 253 221 221 221 86 86 86 156 107 11
51091-216 158 10 236 178 12 242 186 14 246 186 14
51092-242 186 14 239 182 13 239 182 13 242 186 14
51093-242 186 14 246 186 14 246 190 14 246 190 14
51094-246 190 14 246 190 14 246 190 14 246 190 14
51095-242 186 14 225 175 15 142 122 72 66 66 66
51096- 30 30 30 10 10 10 0 0 0 0 0 0
51097- 0 0 0 0 0 0 0 0 0 0 0 0
51098- 0 0 0 0 0 0 0 0 0 0 0 0
51099- 0 0 0 0 0 0 0 0 0 6 6 6
51100- 26 26 26 70 70 70 163 133 67 210 150 10
51101-236 178 12 246 190 14 246 190 14 246 190 14
51102-246 190 14 246 190 14 246 190 14 246 190 14
51103-246 190 14 246 190 14 246 190 14 246 190 14
51104-246 190 14 246 190 14 246 190 14 246 190 14
51105-232 195 16 121 92 8 34 34 34 106 106 106
51106-221 221 221 253 253 253 253 253 253 253 253 253
51107-253 253 253 253 253 253 253 253 253 253 253 253
51108-253 253 253 253 253 253 253 253 253 253 253 253
51109-253 253 253 253 253 253 253 253 253 253 253 253
51110-242 242 242 82 82 82 18 14 6 163 110 8
51111-216 158 10 236 178 12 242 186 14 246 190 14
51112-246 190 14 246 190 14 246 190 14 246 190 14
51113-246 190 14 246 190 14 246 190 14 246 190 14
51114-246 190 14 246 190 14 246 190 14 246 190 14
51115-246 190 14 246 190 14 242 186 14 163 133 67
51116- 46 46 46 18 18 18 6 6 6 0 0 0
51117- 0 0 0 0 0 0 0 0 0 0 0 0
51118- 0 0 0 0 0 0 0 0 0 0 0 0
51119- 0 0 0 0 0 0 0 0 0 10 10 10
51120- 30 30 30 78 78 78 163 133 67 210 150 10
51121-236 178 12 246 186 14 246 190 14 246 190 14
51122-246 190 14 246 190 14 246 190 14 246 190 14
51123-246 190 14 246 190 14 246 190 14 246 190 14
51124-246 190 14 246 190 14 246 190 14 246 190 14
51125-241 196 14 215 174 15 190 178 144 253 253 253
51126-253 253 253 253 253 253 253 253 253 253 253 253
51127-253 253 253 253 253 253 253 253 253 253 253 253
51128-253 253 253 253 253 253 253 253 253 253 253 253
51129-253 253 253 253 253 253 253 253 253 218 218 218
51130- 58 58 58 2 2 6 22 18 6 167 114 7
51131-216 158 10 236 178 12 246 186 14 246 190 14
51132-246 190 14 246 190 14 246 190 14 246 190 14
51133-246 190 14 246 190 14 246 190 14 246 190 14
51134-246 190 14 246 190 14 246 190 14 246 190 14
51135-246 190 14 246 186 14 242 186 14 190 150 46
51136- 54 54 54 22 22 22 6 6 6 0 0 0
51137- 0 0 0 0 0 0 0 0 0 0 0 0
51138- 0 0 0 0 0 0 0 0 0 0 0 0
51139- 0 0 0 0 0 0 0 0 0 14 14 14
51140- 38 38 38 86 86 86 180 133 36 213 154 11
51141-236 178 12 246 186 14 246 190 14 246 190 14
51142-246 190 14 246 190 14 246 190 14 246 190 14
51143-246 190 14 246 190 14 246 190 14 246 190 14
51144-246 190 14 246 190 14 246 190 14 246 190 14
51145-246 190 14 232 195 16 190 146 13 214 214 214
51146-253 253 253 253 253 253 253 253 253 253 253 253
51147-253 253 253 253 253 253 253 253 253 253 253 253
51148-253 253 253 253 253 253 253 253 253 253 253 253
51149-253 253 253 250 250 250 170 170 170 26 26 26
51150- 2 2 6 2 2 6 37 26 9 163 110 8
51151-219 162 10 239 182 13 246 186 14 246 190 14
51152-246 190 14 246 190 14 246 190 14 246 190 14
51153-246 190 14 246 190 14 246 190 14 246 190 14
51154-246 190 14 246 190 14 246 190 14 246 190 14
51155-246 186 14 236 178 12 224 166 10 142 122 72
51156- 46 46 46 18 18 18 6 6 6 0 0 0
51157- 0 0 0 0 0 0 0 0 0 0 0 0
51158- 0 0 0 0 0 0 0 0 0 0 0 0
51159- 0 0 0 0 0 0 6 6 6 18 18 18
51160- 50 50 50 109 106 95 192 133 9 224 166 10
51161-242 186 14 246 190 14 246 190 14 246 190 14
51162-246 190 14 246 190 14 246 190 14 246 190 14
51163-246 190 14 246 190 14 246 190 14 246 190 14
51164-246 190 14 246 190 14 246 190 14 246 190 14
51165-242 186 14 226 184 13 210 162 10 142 110 46
51166-226 226 226 253 253 253 253 253 253 253 253 253
51167-253 253 253 253 253 253 253 253 253 253 253 253
51168-253 253 253 253 253 253 253 253 253 253 253 253
51169-198 198 198 66 66 66 2 2 6 2 2 6
51170- 2 2 6 2 2 6 50 34 6 156 107 11
51171-219 162 10 239 182 13 246 186 14 246 190 14
51172-246 190 14 246 190 14 246 190 14 246 190 14
51173-246 190 14 246 190 14 246 190 14 246 190 14
51174-246 190 14 246 190 14 246 190 14 242 186 14
51175-234 174 13 213 154 11 154 122 46 66 66 66
51176- 30 30 30 10 10 10 0 0 0 0 0 0
51177- 0 0 0 0 0 0 0 0 0 0 0 0
51178- 0 0 0 0 0 0 0 0 0 0 0 0
51179- 0 0 0 0 0 0 6 6 6 22 22 22
51180- 58 58 58 154 121 60 206 145 10 234 174 13
51181-242 186 14 246 186 14 246 190 14 246 190 14
51182-246 190 14 246 190 14 246 190 14 246 190 14
51183-246 190 14 246 190 14 246 190 14 246 190 14
51184-246 190 14 246 190 14 246 190 14 246 190 14
51185-246 186 14 236 178 12 210 162 10 163 110 8
51186- 61 42 6 138 138 138 218 218 218 250 250 250
51187-253 253 253 253 253 253 253 253 253 250 250 250
51188-242 242 242 210 210 210 144 144 144 66 66 66
51189- 6 6 6 2 2 6 2 2 6 2 2 6
51190- 2 2 6 2 2 6 61 42 6 163 110 8
51191-216 158 10 236 178 12 246 190 14 246 190 14
51192-246 190 14 246 190 14 246 190 14 246 190 14
51193-246 190 14 246 190 14 246 190 14 246 190 14
51194-246 190 14 239 182 13 230 174 11 216 158 10
51195-190 142 34 124 112 88 70 70 70 38 38 38
51196- 18 18 18 6 6 6 0 0 0 0 0 0
51197- 0 0 0 0 0 0 0 0 0 0 0 0
51198- 0 0 0 0 0 0 0 0 0 0 0 0
51199- 0 0 0 0 0 0 6 6 6 22 22 22
51200- 62 62 62 168 124 44 206 145 10 224 166 10
51201-236 178 12 239 182 13 242 186 14 242 186 14
51202-246 186 14 246 190 14 246 190 14 246 190 14
51203-246 190 14 246 190 14 246 190 14 246 190 14
51204-246 190 14 246 190 14 246 190 14 246 190 14
51205-246 190 14 236 178 12 216 158 10 175 118 6
51206- 80 54 7 2 2 6 6 6 6 30 30 30
51207- 54 54 54 62 62 62 50 50 50 38 38 38
51208- 14 14 14 2 2 6 2 2 6 2 2 6
51209- 2 2 6 2 2 6 2 2 6 2 2 6
51210- 2 2 6 6 6 6 80 54 7 167 114 7
51211-213 154 11 236 178 12 246 190 14 246 190 14
51212-246 190 14 246 190 14 246 190 14 246 190 14
51213-246 190 14 242 186 14 239 182 13 239 182 13
51214-230 174 11 210 150 10 174 135 50 124 112 88
51215- 82 82 82 54 54 54 34 34 34 18 18 18
51216- 6 6 6 0 0 0 0 0 0 0 0 0
51217- 0 0 0 0 0 0 0 0 0 0 0 0
51218- 0 0 0 0 0 0 0 0 0 0 0 0
51219- 0 0 0 0 0 0 6 6 6 18 18 18
51220- 50 50 50 158 118 36 192 133 9 200 144 11
51221-216 158 10 219 162 10 224 166 10 226 170 11
51222-230 174 11 236 178 12 239 182 13 239 182 13
51223-242 186 14 246 186 14 246 190 14 246 190 14
51224-246 190 14 246 190 14 246 190 14 246 190 14
51225-246 186 14 230 174 11 210 150 10 163 110 8
51226-104 69 6 10 10 10 2 2 6 2 2 6
51227- 2 2 6 2 2 6 2 2 6 2 2 6
51228- 2 2 6 2 2 6 2 2 6 2 2 6
51229- 2 2 6 2 2 6 2 2 6 2 2 6
51230- 2 2 6 6 6 6 91 60 6 167 114 7
51231-206 145 10 230 174 11 242 186 14 246 190 14
51232-246 190 14 246 190 14 246 186 14 242 186 14
51233-239 182 13 230 174 11 224 166 10 213 154 11
51234-180 133 36 124 112 88 86 86 86 58 58 58
51235- 38 38 38 22 22 22 10 10 10 6 6 6
51236- 0 0 0 0 0 0 0 0 0 0 0 0
51237- 0 0 0 0 0 0 0 0 0 0 0 0
51238- 0 0 0 0 0 0 0 0 0 0 0 0
51239- 0 0 0 0 0 0 0 0 0 14 14 14
51240- 34 34 34 70 70 70 138 110 50 158 118 36
51241-167 114 7 180 123 7 192 133 9 197 138 11
51242-200 144 11 206 145 10 213 154 11 219 162 10
51243-224 166 10 230 174 11 239 182 13 242 186 14
51244-246 186 14 246 186 14 246 186 14 246 186 14
51245-239 182 13 216 158 10 185 133 11 152 99 6
51246-104 69 6 18 14 6 2 2 6 2 2 6
51247- 2 2 6 2 2 6 2 2 6 2 2 6
51248- 2 2 6 2 2 6 2 2 6 2 2 6
51249- 2 2 6 2 2 6 2 2 6 2 2 6
51250- 2 2 6 6 6 6 80 54 7 152 99 6
51251-192 133 9 219 162 10 236 178 12 239 182 13
51252-246 186 14 242 186 14 239 182 13 236 178 12
51253-224 166 10 206 145 10 192 133 9 154 121 60
51254- 94 94 94 62 62 62 42 42 42 22 22 22
51255- 14 14 14 6 6 6 0 0 0 0 0 0
51256- 0 0 0 0 0 0 0 0 0 0 0 0
51257- 0 0 0 0 0 0 0 0 0 0 0 0
51258- 0 0 0 0 0 0 0 0 0 0 0 0
51259- 0 0 0 0 0 0 0 0 0 6 6 6
51260- 18 18 18 34 34 34 58 58 58 78 78 78
51261-101 98 89 124 112 88 142 110 46 156 107 11
51262-163 110 8 167 114 7 175 118 6 180 123 7
51263-185 133 11 197 138 11 210 150 10 219 162 10
51264-226 170 11 236 178 12 236 178 12 234 174 13
51265-219 162 10 197 138 11 163 110 8 130 83 6
51266- 91 60 6 10 10 10 2 2 6 2 2 6
51267- 18 18 18 38 38 38 38 38 38 38 38 38
51268- 38 38 38 38 38 38 38 38 38 38 38 38
51269- 38 38 38 38 38 38 26 26 26 2 2 6
51270- 2 2 6 6 6 6 70 47 6 137 92 6
51271-175 118 6 200 144 11 219 162 10 230 174 11
51272-234 174 13 230 174 11 219 162 10 210 150 10
51273-192 133 9 163 110 8 124 112 88 82 82 82
51274- 50 50 50 30 30 30 14 14 14 6 6 6
51275- 0 0 0 0 0 0 0 0 0 0 0 0
51276- 0 0 0 0 0 0 0 0 0 0 0 0
51277- 0 0 0 0 0 0 0 0 0 0 0 0
51278- 0 0 0 0 0 0 0 0 0 0 0 0
51279- 0 0 0 0 0 0 0 0 0 0 0 0
51280- 6 6 6 14 14 14 22 22 22 34 34 34
51281- 42 42 42 58 58 58 74 74 74 86 86 86
51282-101 98 89 122 102 70 130 98 46 121 87 25
51283-137 92 6 152 99 6 163 110 8 180 123 7
51284-185 133 11 197 138 11 206 145 10 200 144 11
51285-180 123 7 156 107 11 130 83 6 104 69 6
51286- 50 34 6 54 54 54 110 110 110 101 98 89
51287- 86 86 86 82 82 82 78 78 78 78 78 78
51288- 78 78 78 78 78 78 78 78 78 78 78 78
51289- 78 78 78 82 82 82 86 86 86 94 94 94
51290-106 106 106 101 101 101 86 66 34 124 80 6
51291-156 107 11 180 123 7 192 133 9 200 144 11
51292-206 145 10 200 144 11 192 133 9 175 118 6
51293-139 102 15 109 106 95 70 70 70 42 42 42
51294- 22 22 22 10 10 10 0 0 0 0 0 0
51295- 0 0 0 0 0 0 0 0 0 0 0 0
51296- 0 0 0 0 0 0 0 0 0 0 0 0
51297- 0 0 0 0 0 0 0 0 0 0 0 0
51298- 0 0 0 0 0 0 0 0 0 0 0 0
51299- 0 0 0 0 0 0 0 0 0 0 0 0
51300- 0 0 0 0 0 0 6 6 6 10 10 10
51301- 14 14 14 22 22 22 30 30 30 38 38 38
51302- 50 50 50 62 62 62 74 74 74 90 90 90
51303-101 98 89 112 100 78 121 87 25 124 80 6
51304-137 92 6 152 99 6 152 99 6 152 99 6
51305-138 86 6 124 80 6 98 70 6 86 66 30
51306-101 98 89 82 82 82 58 58 58 46 46 46
51307- 38 38 38 34 34 34 34 34 34 34 34 34
51308- 34 34 34 34 34 34 34 34 34 34 34 34
51309- 34 34 34 34 34 34 38 38 38 42 42 42
51310- 54 54 54 82 82 82 94 86 76 91 60 6
51311-134 86 6 156 107 11 167 114 7 175 118 6
51312-175 118 6 167 114 7 152 99 6 121 87 25
51313-101 98 89 62 62 62 34 34 34 18 18 18
51314- 6 6 6 0 0 0 0 0 0 0 0 0
51315- 0 0 0 0 0 0 0 0 0 0 0 0
51316- 0 0 0 0 0 0 0 0 0 0 0 0
51317- 0 0 0 0 0 0 0 0 0 0 0 0
51318- 0 0 0 0 0 0 0 0 0 0 0 0
51319- 0 0 0 0 0 0 0 0 0 0 0 0
51320- 0 0 0 0 0 0 0 0 0 0 0 0
51321- 0 0 0 6 6 6 6 6 6 10 10 10
51322- 18 18 18 22 22 22 30 30 30 42 42 42
51323- 50 50 50 66 66 66 86 86 86 101 98 89
51324-106 86 58 98 70 6 104 69 6 104 69 6
51325-104 69 6 91 60 6 82 62 34 90 90 90
51326- 62 62 62 38 38 38 22 22 22 14 14 14
51327- 10 10 10 10 10 10 10 10 10 10 10 10
51328- 10 10 10 10 10 10 6 6 6 10 10 10
51329- 10 10 10 10 10 10 10 10 10 14 14 14
51330- 22 22 22 42 42 42 70 70 70 89 81 66
51331- 80 54 7 104 69 6 124 80 6 137 92 6
51332-134 86 6 116 81 8 100 82 52 86 86 86
51333- 58 58 58 30 30 30 14 14 14 6 6 6
51334- 0 0 0 0 0 0 0 0 0 0 0 0
51335- 0 0 0 0 0 0 0 0 0 0 0 0
51336- 0 0 0 0 0 0 0 0 0 0 0 0
51337- 0 0 0 0 0 0 0 0 0 0 0 0
51338- 0 0 0 0 0 0 0 0 0 0 0 0
51339- 0 0 0 0 0 0 0 0 0 0 0 0
51340- 0 0 0 0 0 0 0 0 0 0 0 0
51341- 0 0 0 0 0 0 0 0 0 0 0 0
51342- 0 0 0 6 6 6 10 10 10 14 14 14
51343- 18 18 18 26 26 26 38 38 38 54 54 54
51344- 70 70 70 86 86 86 94 86 76 89 81 66
51345- 89 81 66 86 86 86 74 74 74 50 50 50
51346- 30 30 30 14 14 14 6 6 6 0 0 0
51347- 0 0 0 0 0 0 0 0 0 0 0 0
51348- 0 0 0 0 0 0 0 0 0 0 0 0
51349- 0 0 0 0 0 0 0 0 0 0 0 0
51350- 6 6 6 18 18 18 34 34 34 58 58 58
51351- 82 82 82 89 81 66 89 81 66 89 81 66
51352- 94 86 66 94 86 76 74 74 74 50 50 50
51353- 26 26 26 14 14 14 6 6 6 0 0 0
51354- 0 0 0 0 0 0 0 0 0 0 0 0
51355- 0 0 0 0 0 0 0 0 0 0 0 0
51356- 0 0 0 0 0 0 0 0 0 0 0 0
51357- 0 0 0 0 0 0 0 0 0 0 0 0
51358- 0 0 0 0 0 0 0 0 0 0 0 0
51359- 0 0 0 0 0 0 0 0 0 0 0 0
51360- 0 0 0 0 0 0 0 0 0 0 0 0
51361- 0 0 0 0 0 0 0 0 0 0 0 0
51362- 0 0 0 0 0 0 0 0 0 0 0 0
51363- 6 6 6 6 6 6 14 14 14 18 18 18
51364- 30 30 30 38 38 38 46 46 46 54 54 54
51365- 50 50 50 42 42 42 30 30 30 18 18 18
51366- 10 10 10 0 0 0 0 0 0 0 0 0
51367- 0 0 0 0 0 0 0 0 0 0 0 0
51368- 0 0 0 0 0 0 0 0 0 0 0 0
51369- 0 0 0 0 0 0 0 0 0 0 0 0
51370- 0 0 0 6 6 6 14 14 14 26 26 26
51371- 38 38 38 50 50 50 58 58 58 58 58 58
51372- 54 54 54 42 42 42 30 30 30 18 18 18
51373- 10 10 10 0 0 0 0 0 0 0 0 0
51374- 0 0 0 0 0 0 0 0 0 0 0 0
51375- 0 0 0 0 0 0 0 0 0 0 0 0
51376- 0 0 0 0 0 0 0 0 0 0 0 0
51377- 0 0 0 0 0 0 0 0 0 0 0 0
51378- 0 0 0 0 0 0 0 0 0 0 0 0
51379- 0 0 0 0 0 0 0 0 0 0 0 0
51380- 0 0 0 0 0 0 0 0 0 0 0 0
51381- 0 0 0 0 0 0 0 0 0 0 0 0
51382- 0 0 0 0 0 0 0 0 0 0 0 0
51383- 0 0 0 0 0 0 0 0 0 6 6 6
51384- 6 6 6 10 10 10 14 14 14 18 18 18
51385- 18 18 18 14 14 14 10 10 10 6 6 6
51386- 0 0 0 0 0 0 0 0 0 0 0 0
51387- 0 0 0 0 0 0 0 0 0 0 0 0
51388- 0 0 0 0 0 0 0 0 0 0 0 0
51389- 0 0 0 0 0 0 0 0 0 0 0 0
51390- 0 0 0 0 0 0 0 0 0 6 6 6
51391- 14 14 14 18 18 18 22 22 22 22 22 22
51392- 18 18 18 14 14 14 10 10 10 6 6 6
51393- 0 0 0 0 0 0 0 0 0 0 0 0
51394- 0 0 0 0 0 0 0 0 0 0 0 0
51395- 0 0 0 0 0 0 0 0 0 0 0 0
51396- 0 0 0 0 0 0 0 0 0 0 0 0
51397- 0 0 0 0 0 0 0 0 0 0 0 0
51398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51411+4 4 4 4 4 4
51412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51425+4 4 4 4 4 4
51426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51439+4 4 4 4 4 4
51440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51453+4 4 4 4 4 4
51454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51461+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51467+4 4 4 4 4 4
51468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51481+4 4 4 4 4 4
51482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51486+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
51487+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
51490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51491+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
51492+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51493+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
51494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51495+4 4 4 4 4 4
51496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51500+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
51501+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
51502+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51503+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51505+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
51506+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
51507+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
51508+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51509+4 4 4 4 4 4
51510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51514+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
51515+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
51516+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51517+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51519+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
51520+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
51521+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
51522+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
51523+4 4 4 4 4 4
51524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51527+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
51528+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
51529+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
51530+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
51531+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51532+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
51533+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
51534+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
51535+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
51536+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
51537+4 4 4 4 4 4
51538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51541+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
51542+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
51543+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
51544+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
51545+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51546+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
51547+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
51548+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
51549+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
51550+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
51551+4 4 4 4 4 4
51552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51555+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
51556+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
51557+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
51558+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
51559+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
51560+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
51561+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
51562+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
51563+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
51564+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
51565+4 4 4 4 4 4
51566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51568+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
51569+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
51570+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
51571+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
51572+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
51573+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
51574+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
51575+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
51576+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
51577+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
51578+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
51579+4 4 4 4 4 4
51580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51582+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
51583+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
51584+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
51585+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
51586+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
51587+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
51588+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
51589+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
51590+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
51591+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
51592+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
51593+4 4 4 4 4 4
51594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51596+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
51597+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
51598+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
51599+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
51600+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
51601+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
51602+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
51603+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
51604+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
51605+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
51606+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51607+4 4 4 4 4 4
51608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51610+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
51611+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
51612+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
51613+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
51614+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
51615+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
51616+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
51617+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
51618+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
51619+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
51620+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
51621+4 4 4 4 4 4
51622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51623+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
51624+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
51625+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
51626+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
51627+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
51628+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
51629+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
51630+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
51631+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
51632+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
51633+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
51634+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
51635+4 4 4 4 4 4
51636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51637+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
51638+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
51639+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
51640+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51641+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
51642+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
51643+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
51644+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
51645+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
51646+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
51647+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
51648+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
51649+0 0 0 4 4 4
51650+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
51651+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
51652+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
51653+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
51654+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
51655+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
51656+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
51657+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
51658+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
51659+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
51660+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
51661+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
51662+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
51663+2 0 0 0 0 0
51664+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
51665+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
51666+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
51667+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
51668+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
51669+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
51670+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
51671+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
51672+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
51673+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
51674+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
51675+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
51676+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
51677+37 38 37 0 0 0
51678+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
51679+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
51680+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
51681+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
51682+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
51683+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
51684+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
51685+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
51686+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
51687+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
51688+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
51689+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
51690+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
51691+85 115 134 4 0 0
51692+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
51693+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
51694+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
51695+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
51696+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
51697+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
51698+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
51699+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
51700+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
51701+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
51702+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
51703+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
51704+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
51705+60 73 81 4 0 0
51706+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
51707+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
51708+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
51709+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
51710+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
51711+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
51712+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
51713+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
51714+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
51715+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
51716+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
51717+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
51718+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
51719+16 19 21 4 0 0
51720+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
51721+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
51722+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
51723+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
51724+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
51725+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
51726+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
51727+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
51728+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
51729+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
51730+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
51731+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
51732+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
51733+4 0 0 4 3 3
51734+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
51735+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
51736+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
51737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
51738+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
51739+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
51740+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
51741+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
51742+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
51743+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
51744+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
51745+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
51746+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
51747+3 2 2 4 4 4
51748+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
51749+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
51750+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
51751+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
51752+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
51753+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
51754+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
51755+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
51756+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
51757+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
51758+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
51759+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
51760+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
51761+4 4 4 4 4 4
51762+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
51763+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
51764+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
51765+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
51766+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
51767+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
51768+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
51769+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
51770+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
51771+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
51772+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
51773+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
51774+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
51775+4 4 4 4 4 4
51776+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
51777+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
51778+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
51779+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
51780+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
51781+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51782+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
51783+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
51784+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
51785+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
51786+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
51787+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
51788+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
51789+5 5 5 5 5 5
51790+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
51791+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
51792+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
51793+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
51794+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
51795+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51796+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
51797+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
51798+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
51799+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
51800+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
51801+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
51802+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51803+5 5 5 4 4 4
51804+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
51805+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
51806+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
51807+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
51808+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51809+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
51810+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
51811+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
51812+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
51813+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
51814+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
51815+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51817+4 4 4 4 4 4
51818+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
51819+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
51820+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
51821+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
51822+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
51823+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51824+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51825+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
51826+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
51827+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
51828+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
51829+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
51830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51831+4 4 4 4 4 4
51832+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
51833+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
51834+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
51835+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
51836+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51837+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
51838+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
51839+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
51840+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
51841+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
51842+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
51843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51845+4 4 4 4 4 4
51846+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
51847+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
51848+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
51849+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
51850+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51851+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51852+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51853+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
51854+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
51855+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
51856+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
51857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51859+4 4 4 4 4 4
51860+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
51861+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
51862+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
51863+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
51864+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51865+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
51866+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51867+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
51868+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
51869+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
51870+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51873+4 4 4 4 4 4
51874+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
51875+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
51876+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
51877+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
51878+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51879+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
51880+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
51881+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
51882+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
51883+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
51884+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
51885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51887+4 4 4 4 4 4
51888+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
51889+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
51890+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
51891+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
51892+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51893+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
51894+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
51895+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
51896+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
51897+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
51898+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
51899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51901+4 4 4 4 4 4
51902+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
51903+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
51904+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
51905+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51906+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
51907+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
51908+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
51909+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
51910+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
51911+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
51912+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51915+4 4 4 4 4 4
51916+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
51917+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
51918+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
51919+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51920+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51921+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
51922+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
51923+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
51924+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
51925+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
51926+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51929+4 4 4 4 4 4
51930+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
51931+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
51932+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51933+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51934+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51935+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
51936+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
51937+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
51938+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
51939+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
51940+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51943+4 4 4 4 4 4
51944+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
51945+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
51946+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51947+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51948+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51949+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
51950+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
51951+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
51952+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51953+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51954+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51957+4 4 4 4 4 4
51958+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51959+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
51960+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51961+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
51962+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
51963+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
51964+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
51965+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
51966+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51967+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51968+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51971+4 4 4 4 4 4
51972+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51973+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
51974+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51975+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
51976+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51977+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
51978+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
51979+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
51980+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51981+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51982+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51985+4 4 4 4 4 4
51986+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
51987+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
51988+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51989+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
51990+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
51991+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
51992+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
51993+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
51994+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51995+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51996+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51999+4 4 4 4 4 4
52000+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
52001+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
52002+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
52003+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
52004+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
52005+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
52006+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
52007+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
52008+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
52009+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52010+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52013+4 4 4 4 4 4
52014+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
52015+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
52016+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
52017+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
52018+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
52019+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
52020+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
52021+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
52022+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52023+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52024+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52027+4 4 4 4 4 4
52028+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
52029+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
52030+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
52031+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
52032+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
52033+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
52034+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
52035+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
52036+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
52037+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52038+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52041+4 4 4 4 4 4
52042+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
52043+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
52044+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
52045+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
52046+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
52047+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
52048+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
52049+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
52050+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52051+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52052+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52055+4 4 4 4 4 4
52056+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52057+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
52058+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
52059+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
52060+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
52061+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
52062+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
52063+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
52064+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
52065+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52066+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52069+4 4 4 4 4 4
52070+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
52071+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
52072+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
52073+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
52074+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
52075+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
52076+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52077+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
52078+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52079+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52080+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52083+4 4 4 4 4 4
52084+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52085+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
52086+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
52087+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
52088+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
52089+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
52090+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52091+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
52092+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
52093+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52094+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52097+4 4 4 4 4 4
52098+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
52099+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
52100+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
52101+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
52102+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
52103+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
52104+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
52105+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
52106+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
52107+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52108+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52111+4 4 4 4 4 4
52112+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52113+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
52114+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
52115+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
52116+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
52117+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
52118+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
52119+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
52120+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
52121+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52122+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52125+4 4 4 4 4 4
52126+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
52127+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
52128+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
52129+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
52130+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
52131+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
52132+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
52133+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
52134+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
52135+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52136+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52139+4 4 4 4 4 4
52140+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52141+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
52142+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
52143+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
52144+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
52145+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
52146+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
52147+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
52148+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
52149+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52150+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52153+4 4 4 4 4 4
52154+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
52155+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
52156+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
52157+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
52158+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
52159+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
52160+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
52161+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
52162+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
52163+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
52164+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52167+4 4 4 4 4 4
52168+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
52169+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
52170+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
52171+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
52172+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
52173+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
52174+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
52175+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
52176+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
52177+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
52178+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52181+4 4 4 4 4 4
52182+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
52183+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
52184+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
52185+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
52186+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
52187+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
52188+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52189+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
52190+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
52191+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
52192+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52195+4 4 4 4 4 4
52196+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
52197+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
52198+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
52199+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
52200+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
52201+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
52202+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
52203+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
52204+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
52205+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
52206+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52209+4 4 4 4 4 4
52210+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
52211+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
52212+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
52213+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
52214+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
52215+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
52216+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
52217+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
52218+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
52219+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
52220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52223+4 4 4 4 4 4
52224+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52225+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
52226+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
52227+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
52228+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
52229+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
52230+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
52231+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
52232+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
52233+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
52234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52237+4 4 4 4 4 4
52238+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
52239+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
52240+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
52241+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
52242+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
52243+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
52244+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
52245+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
52246+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
52247+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
52248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52251+4 4 4 4 4 4
52252+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
52253+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
52254+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
52255+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
52256+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
52257+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
52258+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
52259+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
52260+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
52261+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52265+4 4 4 4 4 4
52266+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
52267+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52268+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
52269+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
52270+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
52271+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
52272+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
52273+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
52274+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
52275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52279+4 4 4 4 4 4
52280+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
52281+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
52282+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
52283+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
52284+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
52285+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
52286+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
52287+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
52288+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
52289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52293+4 4 4 4 4 4
52294+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
52295+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
52296+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
52297+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
52298+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
52299+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
52300+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
52301+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
52302+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52307+4 4 4 4 4 4
52308+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
52309+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
52310+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
52311+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
52312+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
52313+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
52314+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
52315+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
52316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52321+4 4 4 4 4 4
52322+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
52323+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
52324+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
52325+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
52326+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
52327+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
52328+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
52329+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
52330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52335+4 4 4 4 4 4
52336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52337+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
52338+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52339+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
52340+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
52341+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
52342+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
52343+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
52344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52349+4 4 4 4 4 4
52350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52351+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
52352+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
52353+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
52354+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
52355+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
52356+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
52357+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
52358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52363+4 4 4 4 4 4
52364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52365+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
52366+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
52367+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
52368+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
52369+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
52370+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
52371+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52377+4 4 4 4 4 4
52378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52380+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
52381+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
52382+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
52383+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
52384+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
52385+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52391+4 4 4 4 4 4
52392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52395+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52396+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
52397+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
52398+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
52399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52405+4 4 4 4 4 4
52406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52409+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
52410+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
52411+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
52412+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
52413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52419+4 4 4 4 4 4
52420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52423+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
52424+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52425+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
52426+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
52427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52433+4 4 4 4 4 4
52434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52437+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
52438+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
52439+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
52440+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
52441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52447+4 4 4 4 4 4
52448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52452+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
52453+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52454+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52461+4 4 4 4 4 4
52462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52466+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
52467+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
52468+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
52469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52475+4 4 4 4 4 4
52476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52480+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
52481+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
52482+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52489+4 4 4 4 4 4
52490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52494+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
52495+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
52496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52503+4 4 4 4 4 4
52504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52508+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
52509+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
52510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52517+4 4 4 4 4 4
52518diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
52519index fe92eed..106e085 100644
52520--- a/drivers/video/mb862xx/mb862xxfb_accel.c
52521+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
52522@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
52523 struct mb862xxfb_par *par = info->par;
52524
52525 if (info->var.bits_per_pixel == 32) {
52526- info->fbops->fb_fillrect = cfb_fillrect;
52527- info->fbops->fb_copyarea = cfb_copyarea;
52528- info->fbops->fb_imageblit = cfb_imageblit;
52529+ pax_open_kernel();
52530+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52531+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52532+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52533+ pax_close_kernel();
52534 } else {
52535 outreg(disp, GC_L0EM, 3);
52536- info->fbops->fb_fillrect = mb86290fb_fillrect;
52537- info->fbops->fb_copyarea = mb86290fb_copyarea;
52538- info->fbops->fb_imageblit = mb86290fb_imageblit;
52539+ pax_open_kernel();
52540+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
52541+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
52542+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
52543+ pax_close_kernel();
52544 }
52545 outreg(draw, GDC_REG_DRAW_BASE, 0);
52546 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
52547diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
52548index ff22871..b129bed 100644
52549--- a/drivers/video/nvidia/nvidia.c
52550+++ b/drivers/video/nvidia/nvidia.c
52551@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
52552 info->fix.line_length = (info->var.xres_virtual *
52553 info->var.bits_per_pixel) >> 3;
52554 if (info->var.accel_flags) {
52555- info->fbops->fb_imageblit = nvidiafb_imageblit;
52556- info->fbops->fb_fillrect = nvidiafb_fillrect;
52557- info->fbops->fb_copyarea = nvidiafb_copyarea;
52558- info->fbops->fb_sync = nvidiafb_sync;
52559+ pax_open_kernel();
52560+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
52561+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
52562+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
52563+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
52564+ pax_close_kernel();
52565 info->pixmap.scan_align = 4;
52566 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52567 info->flags |= FBINFO_READS_FAST;
52568 NVResetGraphics(info);
52569 } else {
52570- info->fbops->fb_imageblit = cfb_imageblit;
52571- info->fbops->fb_fillrect = cfb_fillrect;
52572- info->fbops->fb_copyarea = cfb_copyarea;
52573- info->fbops->fb_sync = NULL;
52574+ pax_open_kernel();
52575+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52576+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52577+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52578+ *(void **)&info->fbops->fb_sync = NULL;
52579+ pax_close_kernel();
52580 info->pixmap.scan_align = 1;
52581 info->flags |= FBINFO_HWACCEL_DISABLED;
52582 info->flags &= ~FBINFO_READS_FAST;
52583@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
52584 info->pixmap.size = 8 * 1024;
52585 info->pixmap.flags = FB_PIXMAP_SYSTEM;
52586
52587- if (!hwcur)
52588- info->fbops->fb_cursor = NULL;
52589+ if (!hwcur) {
52590+ pax_open_kernel();
52591+ *(void **)&info->fbops->fb_cursor = NULL;
52592+ pax_close_kernel();
52593+ }
52594
52595 info->var.accel_flags = (!noaccel);
52596
52597diff --git a/drivers/video/output.c b/drivers/video/output.c
52598index 0d6f2cd..6285b97 100644
52599--- a/drivers/video/output.c
52600+++ b/drivers/video/output.c
52601@@ -97,7 +97,7 @@ struct output_device *video_output_register(const char *name,
52602 new_dev->props = op;
52603 new_dev->dev.class = &video_output_class;
52604 new_dev->dev.parent = dev;
52605- dev_set_name(&new_dev->dev, name);
52606+ dev_set_name(&new_dev->dev, "%s", name);
52607 dev_set_drvdata(&new_dev->dev, devdata);
52608 ret_code = device_register(&new_dev->dev);
52609 if (ret_code) {
52610diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
52611index 05c2dc3..ea1f391 100644
52612--- a/drivers/video/s1d13xxxfb.c
52613+++ b/drivers/video/s1d13xxxfb.c
52614@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
52615
52616 switch(prod_id) {
52617 case S1D13506_PROD_ID: /* activate acceleration */
52618- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52619- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52620+ pax_open_kernel();
52621+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52622+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52623+ pax_close_kernel();
52624 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
52625 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
52626 break;
52627diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
52628index b2b33fc..f9f4658 100644
52629--- a/drivers/video/smscufx.c
52630+++ b/drivers/video/smscufx.c
52631@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
52632 fb_deferred_io_cleanup(info);
52633 kfree(info->fbdefio);
52634 info->fbdefio = NULL;
52635- info->fbops->fb_mmap = ufx_ops_mmap;
52636+ pax_open_kernel();
52637+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
52638+ pax_close_kernel();
52639 }
52640
52641 pr_debug("released /dev/fb%d user=%d count=%d",
52642diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
52643index ec03e72..f578436 100644
52644--- a/drivers/video/udlfb.c
52645+++ b/drivers/video/udlfb.c
52646@@ -623,11 +623,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
52647 dlfb_urb_completion(urb);
52648
52649 error:
52650- atomic_add(bytes_sent, &dev->bytes_sent);
52651- atomic_add(bytes_identical, &dev->bytes_identical);
52652- atomic_add(width*height*2, &dev->bytes_rendered);
52653+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52654+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52655+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
52656 end_cycles = get_cycles();
52657- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52658+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52659 >> 10)), /* Kcycles */
52660 &dev->cpu_kcycles_used);
52661
52662@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
52663 dlfb_urb_completion(urb);
52664
52665 error:
52666- atomic_add(bytes_sent, &dev->bytes_sent);
52667- atomic_add(bytes_identical, &dev->bytes_identical);
52668- atomic_add(bytes_rendered, &dev->bytes_rendered);
52669+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52670+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52671+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
52672 end_cycles = get_cycles();
52673- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52674+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52675 >> 10)), /* Kcycles */
52676 &dev->cpu_kcycles_used);
52677 }
52678@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
52679 fb_deferred_io_cleanup(info);
52680 kfree(info->fbdefio);
52681 info->fbdefio = NULL;
52682- info->fbops->fb_mmap = dlfb_ops_mmap;
52683+ pax_open_kernel();
52684+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
52685+ pax_close_kernel();
52686 }
52687
52688 pr_warn("released /dev/fb%d user=%d count=%d\n",
52689@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
52690 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52691 struct dlfb_data *dev = fb_info->par;
52692 return snprintf(buf, PAGE_SIZE, "%u\n",
52693- atomic_read(&dev->bytes_rendered));
52694+ atomic_read_unchecked(&dev->bytes_rendered));
52695 }
52696
52697 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52698@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52699 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52700 struct dlfb_data *dev = fb_info->par;
52701 return snprintf(buf, PAGE_SIZE, "%u\n",
52702- atomic_read(&dev->bytes_identical));
52703+ atomic_read_unchecked(&dev->bytes_identical));
52704 }
52705
52706 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52707@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52708 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52709 struct dlfb_data *dev = fb_info->par;
52710 return snprintf(buf, PAGE_SIZE, "%u\n",
52711- atomic_read(&dev->bytes_sent));
52712+ atomic_read_unchecked(&dev->bytes_sent));
52713 }
52714
52715 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52716@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52717 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52718 struct dlfb_data *dev = fb_info->par;
52719 return snprintf(buf, PAGE_SIZE, "%u\n",
52720- atomic_read(&dev->cpu_kcycles_used));
52721+ atomic_read_unchecked(&dev->cpu_kcycles_used));
52722 }
52723
52724 static ssize_t edid_show(
52725@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
52726 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52727 struct dlfb_data *dev = fb_info->par;
52728
52729- atomic_set(&dev->bytes_rendered, 0);
52730- atomic_set(&dev->bytes_identical, 0);
52731- atomic_set(&dev->bytes_sent, 0);
52732- atomic_set(&dev->cpu_kcycles_used, 0);
52733+ atomic_set_unchecked(&dev->bytes_rendered, 0);
52734+ atomic_set_unchecked(&dev->bytes_identical, 0);
52735+ atomic_set_unchecked(&dev->bytes_sent, 0);
52736+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
52737
52738 return count;
52739 }
52740diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
52741index e328a61..1b08ecb 100644
52742--- a/drivers/video/uvesafb.c
52743+++ b/drivers/video/uvesafb.c
52744@@ -19,6 +19,7 @@
52745 #include <linux/io.h>
52746 #include <linux/mutex.h>
52747 #include <linux/slab.h>
52748+#include <linux/moduleloader.h>
52749 #include <video/edid.h>
52750 #include <video/uvesafb.h>
52751 #ifdef CONFIG_X86
52752@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
52753 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
52754 par->pmi_setpal = par->ypan = 0;
52755 } else {
52756+
52757+#ifdef CONFIG_PAX_KERNEXEC
52758+#ifdef CONFIG_MODULES
52759+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
52760+#endif
52761+ if (!par->pmi_code) {
52762+ par->pmi_setpal = par->ypan = 0;
52763+ return 0;
52764+ }
52765+#endif
52766+
52767 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
52768 + task->t.regs.edi);
52769+
52770+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52771+ pax_open_kernel();
52772+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
52773+ pax_close_kernel();
52774+
52775+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
52776+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
52777+#else
52778 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
52779 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
52780+#endif
52781+
52782 printk(KERN_INFO "uvesafb: protected mode interface info at "
52783 "%04x:%04x\n",
52784 (u16)task->t.regs.es, (u16)task->t.regs.edi);
52785@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
52786 par->ypan = ypan;
52787
52788 if (par->pmi_setpal || par->ypan) {
52789+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
52790 if (__supported_pte_mask & _PAGE_NX) {
52791 par->pmi_setpal = par->ypan = 0;
52792 printk(KERN_WARNING "uvesafb: NX protection is actively."
52793 "We have better not to use the PMI.\n");
52794- } else {
52795+ } else
52796+#endif
52797 uvesafb_vbe_getpmi(task, par);
52798- }
52799 }
52800 #else
52801 /* The protected mode interface is not available on non-x86. */
52802@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52803 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
52804
52805 /* Disable blanking if the user requested so. */
52806- if (!blank)
52807- info->fbops->fb_blank = NULL;
52808+ if (!blank) {
52809+ pax_open_kernel();
52810+ *(void **)&info->fbops->fb_blank = NULL;
52811+ pax_close_kernel();
52812+ }
52813
52814 /*
52815 * Find out how much IO memory is required for the mode with
52816@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52817 info->flags = FBINFO_FLAG_DEFAULT |
52818 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
52819
52820- if (!par->ypan)
52821- info->fbops->fb_pan_display = NULL;
52822+ if (!par->ypan) {
52823+ pax_open_kernel();
52824+ *(void **)&info->fbops->fb_pan_display = NULL;
52825+ pax_close_kernel();
52826+ }
52827 }
52828
52829 static void uvesafb_init_mtrr(struct fb_info *info)
52830@@ -1836,6 +1866,11 @@ out:
52831 if (par->vbe_modes)
52832 kfree(par->vbe_modes);
52833
52834+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52835+ if (par->pmi_code)
52836+ module_free_exec(NULL, par->pmi_code);
52837+#endif
52838+
52839 framebuffer_release(info);
52840 return err;
52841 }
52842@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
52843 kfree(par->vbe_state_orig);
52844 if (par->vbe_state_saved)
52845 kfree(par->vbe_state_saved);
52846+
52847+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52848+ if (par->pmi_code)
52849+ module_free_exec(NULL, par->pmi_code);
52850+#endif
52851+
52852 }
52853
52854 framebuffer_release(info);
52855diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
52856index 501b340..d80aa17 100644
52857--- a/drivers/video/vesafb.c
52858+++ b/drivers/video/vesafb.c
52859@@ -9,6 +9,7 @@
52860 */
52861
52862 #include <linux/module.h>
52863+#include <linux/moduleloader.h>
52864 #include <linux/kernel.h>
52865 #include <linux/errno.h>
52866 #include <linux/string.h>
52867@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
52868 static int vram_total __initdata; /* Set total amount of memory */
52869 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
52870 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
52871-static void (*pmi_start)(void) __read_mostly;
52872-static void (*pmi_pal) (void) __read_mostly;
52873+static void (*pmi_start)(void) __read_only;
52874+static void (*pmi_pal) (void) __read_only;
52875 static int depth __read_mostly;
52876 static int vga_compat __read_mostly;
52877 /* --------------------------------------------------------------------- */
52878@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
52879 unsigned int size_vmode;
52880 unsigned int size_remap;
52881 unsigned int size_total;
52882+ void *pmi_code = NULL;
52883
52884 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
52885 return -ENODEV;
52886@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
52887 size_remap = size_total;
52888 vesafb_fix.smem_len = size_remap;
52889
52890-#ifndef __i386__
52891- screen_info.vesapm_seg = 0;
52892-#endif
52893-
52894 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
52895 printk(KERN_WARNING
52896 "vesafb: cannot reserve video memory at 0x%lx\n",
52897@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
52898 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
52899 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
52900
52901+#ifdef __i386__
52902+
52903+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52904+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
52905+ if (!pmi_code)
52906+#elif !defined(CONFIG_PAX_KERNEXEC)
52907+ if (0)
52908+#endif
52909+
52910+#endif
52911+ screen_info.vesapm_seg = 0;
52912+
52913 if (screen_info.vesapm_seg) {
52914- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
52915- screen_info.vesapm_seg,screen_info.vesapm_off);
52916+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
52917+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
52918 }
52919
52920 if (screen_info.vesapm_seg < 0xc000)
52921@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
52922
52923 if (ypan || pmi_setpal) {
52924 unsigned short *pmi_base;
52925+
52926 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
52927- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
52928- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
52929+
52930+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52931+ pax_open_kernel();
52932+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
52933+#else
52934+ pmi_code = pmi_base;
52935+#endif
52936+
52937+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
52938+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
52939+
52940+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52941+ pmi_start = ktva_ktla(pmi_start);
52942+ pmi_pal = ktva_ktla(pmi_pal);
52943+ pax_close_kernel();
52944+#endif
52945+
52946 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
52947 if (pmi_base[3]) {
52948 printk(KERN_INFO "vesafb: pmi: ports = ");
52949@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52950 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
52951 (ypan ? FBINFO_HWACCEL_YPAN : 0);
52952
52953- if (!ypan)
52954- info->fbops->fb_pan_display = NULL;
52955+ if (!ypan) {
52956+ pax_open_kernel();
52957+ *(void **)&info->fbops->fb_pan_display = NULL;
52958+ pax_close_kernel();
52959+ }
52960
52961 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
52962 err = -ENOMEM;
52963@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52964 info->node, info->fix.id);
52965 return 0;
52966 err:
52967+
52968+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52969+ module_free_exec(NULL, pmi_code);
52970+#endif
52971+
52972 if (info->screen_base)
52973 iounmap(info->screen_base);
52974 framebuffer_release(info);
52975diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
52976index 88714ae..16c2e11 100644
52977--- a/drivers/video/via/via_clock.h
52978+++ b/drivers/video/via/via_clock.h
52979@@ -56,7 +56,7 @@ struct via_clock {
52980
52981 void (*set_engine_pll_state)(u8 state);
52982 void (*set_engine_pll)(struct via_pll_config config);
52983-};
52984+} __no_const;
52985
52986
52987 static inline u32 get_pll_internal_frequency(u32 ref_freq,
52988diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
52989index fef20db..d28b1ab 100644
52990--- a/drivers/xen/xenfs/xenstored.c
52991+++ b/drivers/xen/xenfs/xenstored.c
52992@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
52993 static int xsd_kva_open(struct inode *inode, struct file *file)
52994 {
52995 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
52996+#ifdef CONFIG_GRKERNSEC_HIDESYM
52997+ NULL);
52998+#else
52999 xen_store_interface);
53000+#endif
53001+
53002 if (!file->private_data)
53003 return -ENOMEM;
53004 return 0;
53005diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
53006index 055562c..fdfb10d 100644
53007--- a/fs/9p/vfs_addr.c
53008+++ b/fs/9p/vfs_addr.c
53009@@ -186,7 +186,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
53010
53011 retval = v9fs_file_write_internal(inode,
53012 v9inode->writeback_fid,
53013- (__force const char __user *)buffer,
53014+ (const char __force_user *)buffer,
53015 len, &offset, 0);
53016 if (retval > 0)
53017 retval = 0;
53018diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
53019index d86edc8..40ff2fb 100644
53020--- a/fs/9p/vfs_inode.c
53021+++ b/fs/9p/vfs_inode.c
53022@@ -1314,7 +1314,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
53023 void
53024 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53025 {
53026- char *s = nd_get_link(nd);
53027+ const char *s = nd_get_link(nd);
53028
53029 p9_debug(P9_DEBUG_VFS, " %s %s\n",
53030 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
53031diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
53032index 370b24c..ff0be7b 100644
53033--- a/fs/Kconfig.binfmt
53034+++ b/fs/Kconfig.binfmt
53035@@ -103,7 +103,7 @@ config HAVE_AOUT
53036
53037 config BINFMT_AOUT
53038 tristate "Kernel support for a.out and ECOFF binaries"
53039- depends on HAVE_AOUT
53040+ depends on HAVE_AOUT && BROKEN
53041 ---help---
53042 A.out (Assembler.OUTput) is a set of formats for libraries and
53043 executables used in the earliest versions of UNIX. Linux used
53044diff --git a/fs/afs/inode.c b/fs/afs/inode.c
53045index 789bc25..fafaeea 100644
53046--- a/fs/afs/inode.c
53047+++ b/fs/afs/inode.c
53048@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
53049 struct afs_vnode *vnode;
53050 struct super_block *sb;
53051 struct inode *inode;
53052- static atomic_t afs_autocell_ino;
53053+ static atomic_unchecked_t afs_autocell_ino;
53054
53055 _enter("{%x:%u},%*.*s,",
53056 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
53057@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
53058 data.fid.unique = 0;
53059 data.fid.vnode = 0;
53060
53061- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
53062+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
53063 afs_iget5_autocell_test, afs_iget5_set,
53064 &data);
53065 if (!inode) {
53066diff --git a/fs/aio.c b/fs/aio.c
53067index 2bbcacf..8614116 100644
53068--- a/fs/aio.c
53069+++ b/fs/aio.c
53070@@ -160,7 +160,7 @@ static int aio_setup_ring(struct kioctx *ctx)
53071 size += sizeof(struct io_event) * nr_events;
53072 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
53073
53074- if (nr_pages < 0)
53075+ if (nr_pages <= 0)
53076 return -EINVAL;
53077
53078 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
53079@@ -950,6 +950,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
53080 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
53081 {
53082 ssize_t ret;
53083+ struct iovec iovstack;
53084
53085 kiocb->ki_nr_segs = kiocb->ki_nbytes;
53086
53087@@ -957,17 +958,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
53088 if (compat)
53089 ret = compat_rw_copy_check_uvector(rw,
53090 (struct compat_iovec __user *)kiocb->ki_buf,
53091- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
53092+ kiocb->ki_nr_segs, 1, &iovstack,
53093 &kiocb->ki_iovec);
53094 else
53095 #endif
53096 ret = rw_copy_check_uvector(rw,
53097 (struct iovec __user *)kiocb->ki_buf,
53098- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
53099+ kiocb->ki_nr_segs, 1, &iovstack,
53100 &kiocb->ki_iovec);
53101 if (ret < 0)
53102 return ret;
53103
53104+ if (kiocb->ki_iovec == &iovstack) {
53105+ kiocb->ki_inline_vec = iovstack;
53106+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
53107+ }
53108+
53109 /* ki_nbytes now reflect bytes instead of segs */
53110 kiocb->ki_nbytes = ret;
53111 return 0;
53112diff --git a/fs/attr.c b/fs/attr.c
53113index 1449adb..a2038c2 100644
53114--- a/fs/attr.c
53115+++ b/fs/attr.c
53116@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
53117 unsigned long limit;
53118
53119 limit = rlimit(RLIMIT_FSIZE);
53120+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
53121 if (limit != RLIM_INFINITY && offset > limit)
53122 goto out_sig;
53123 if (offset > inode->i_sb->s_maxbytes)
53124diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
53125index 3db70da..7aeec5b 100644
53126--- a/fs/autofs4/waitq.c
53127+++ b/fs/autofs4/waitq.c
53128@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
53129 {
53130 unsigned long sigpipe, flags;
53131 mm_segment_t fs;
53132- const char *data = (const char *)addr;
53133+ const char __user *data = (const char __force_user *)addr;
53134 ssize_t wr = 0;
53135
53136 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
53137@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
53138 return 1;
53139 }
53140
53141+#ifdef CONFIG_GRKERNSEC_HIDESYM
53142+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
53143+#endif
53144+
53145 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
53146 enum autofs_notify notify)
53147 {
53148@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
53149
53150 /* If this is a direct mount request create a dummy name */
53151 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
53152+#ifdef CONFIG_GRKERNSEC_HIDESYM
53153+ /* this name does get written to userland via autofs4_write() */
53154+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
53155+#else
53156 qstr.len = sprintf(name, "%p", dentry);
53157+#endif
53158 else {
53159 qstr.len = autofs4_getpath(sbi, dentry, &name);
53160 if (!qstr.len) {
53161diff --git a/fs/befs/endian.h b/fs/befs/endian.h
53162index 2722387..c8dd2a7 100644
53163--- a/fs/befs/endian.h
53164+++ b/fs/befs/endian.h
53165@@ -11,7 +11,7 @@
53166
53167 #include <asm/byteorder.h>
53168
53169-static inline u64
53170+static inline u64 __intentional_overflow(-1)
53171 fs64_to_cpu(const struct super_block *sb, fs64 n)
53172 {
53173 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
53174@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
53175 return (__force fs64)cpu_to_be64(n);
53176 }
53177
53178-static inline u32
53179+static inline u32 __intentional_overflow(-1)
53180 fs32_to_cpu(const struct super_block *sb, fs32 n)
53181 {
53182 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
53183diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
53184index f95dddc..b1e2c1c 100644
53185--- a/fs/befs/linuxvfs.c
53186+++ b/fs/befs/linuxvfs.c
53187@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53188 {
53189 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
53190 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
53191- char *link = nd_get_link(nd);
53192+ const char *link = nd_get_link(nd);
53193 if (!IS_ERR(link))
53194 kfree(link);
53195 }
53196diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
53197index bce8769..7fc7544 100644
53198--- a/fs/binfmt_aout.c
53199+++ b/fs/binfmt_aout.c
53200@@ -16,6 +16,7 @@
53201 #include <linux/string.h>
53202 #include <linux/fs.h>
53203 #include <linux/file.h>
53204+#include <linux/security.h>
53205 #include <linux/stat.h>
53206 #include <linux/fcntl.h>
53207 #include <linux/ptrace.h>
53208@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
53209 #endif
53210 # define START_STACK(u) ((void __user *)u.start_stack)
53211
53212+ memset(&dump, 0, sizeof(dump));
53213+
53214 fs = get_fs();
53215 set_fs(KERNEL_DS);
53216 has_dumped = 1;
53217@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
53218
53219 /* If the size of the dump file exceeds the rlimit, then see what would happen
53220 if we wrote the stack, but not the data area. */
53221+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
53222 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
53223 dump.u_dsize = 0;
53224
53225 /* Make sure we have enough room to write the stack and data areas. */
53226+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
53227 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
53228 dump.u_ssize = 0;
53229
53230@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
53231 rlim = rlimit(RLIMIT_DATA);
53232 if (rlim >= RLIM_INFINITY)
53233 rlim = ~0;
53234+
53235+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
53236 if (ex.a_data + ex.a_bss > rlim)
53237 return -ENOMEM;
53238
53239@@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
53240
53241 install_exec_creds(bprm);
53242
53243+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53244+ current->mm->pax_flags = 0UL;
53245+#endif
53246+
53247+#ifdef CONFIG_PAX_PAGEEXEC
53248+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
53249+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
53250+
53251+#ifdef CONFIG_PAX_EMUTRAMP
53252+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
53253+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
53254+#endif
53255+
53256+#ifdef CONFIG_PAX_MPROTECT
53257+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
53258+ current->mm->pax_flags |= MF_PAX_MPROTECT;
53259+#endif
53260+
53261+ }
53262+#endif
53263+
53264 if (N_MAGIC(ex) == OMAGIC) {
53265 unsigned long text_addr, map_size;
53266 loff_t pos;
53267@@ -324,7 +352,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
53268 }
53269
53270 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
53271- PROT_READ | PROT_WRITE | PROT_EXEC,
53272+ PROT_READ | PROT_WRITE,
53273 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
53274 fd_offset + ex.a_text);
53275 if (error != N_DATADDR(ex)) {
53276diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
53277index f8a0b0e..6f036ed 100644
53278--- a/fs/binfmt_elf.c
53279+++ b/fs/binfmt_elf.c
53280@@ -34,6 +34,7 @@
53281 #include <linux/utsname.h>
53282 #include <linux/coredump.h>
53283 #include <linux/sched.h>
53284+#include <linux/xattr.h>
53285 #include <asm/uaccess.h>
53286 #include <asm/param.h>
53287 #include <asm/page.h>
53288@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
53289 #define elf_core_dump NULL
53290 #endif
53291
53292+#ifdef CONFIG_PAX_MPROTECT
53293+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
53294+#endif
53295+
53296+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53297+static void elf_handle_mmap(struct file *file);
53298+#endif
53299+
53300 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
53301 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
53302 #else
53303@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
53304 .load_binary = load_elf_binary,
53305 .load_shlib = load_elf_library,
53306 .core_dump = elf_core_dump,
53307+
53308+#ifdef CONFIG_PAX_MPROTECT
53309+ .handle_mprotect= elf_handle_mprotect,
53310+#endif
53311+
53312+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53313+ .handle_mmap = elf_handle_mmap,
53314+#endif
53315+
53316 .min_coredump = ELF_EXEC_PAGESIZE,
53317 };
53318
53319@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
53320
53321 static int set_brk(unsigned long start, unsigned long end)
53322 {
53323+ unsigned long e = end;
53324+
53325 start = ELF_PAGEALIGN(start);
53326 end = ELF_PAGEALIGN(end);
53327 if (end > start) {
53328@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
53329 if (BAD_ADDR(addr))
53330 return addr;
53331 }
53332- current->mm->start_brk = current->mm->brk = end;
53333+ current->mm->start_brk = current->mm->brk = e;
53334 return 0;
53335 }
53336
53337@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
53338 elf_addr_t __user *u_rand_bytes;
53339 const char *k_platform = ELF_PLATFORM;
53340 const char *k_base_platform = ELF_BASE_PLATFORM;
53341- unsigned char k_rand_bytes[16];
53342+ u32 k_rand_bytes[4];
53343 int items;
53344 elf_addr_t *elf_info;
53345 int ei_index = 0;
53346 const struct cred *cred = current_cred();
53347 struct vm_area_struct *vma;
53348+ unsigned long saved_auxv[AT_VECTOR_SIZE];
53349
53350 /*
53351 * In some cases (e.g. Hyper-Threading), we want to avoid L1
53352@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
53353 * Generate 16 random bytes for userspace PRNG seeding.
53354 */
53355 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
53356- u_rand_bytes = (elf_addr_t __user *)
53357- STACK_ALLOC(p, sizeof(k_rand_bytes));
53358+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
53359+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
53360+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
53361+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
53362+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
53363+ u_rand_bytes = (elf_addr_t __user *) p;
53364 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
53365 return -EFAULT;
53366
53367@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
53368 return -EFAULT;
53369 current->mm->env_end = p;
53370
53371+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
53372+
53373 /* Put the elf_info on the stack in the right place. */
53374 sp = (elf_addr_t __user *)envp + 1;
53375- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
53376+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
53377 return -EFAULT;
53378 return 0;
53379 }
53380@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
53381 an ELF header */
53382
53383 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53384- struct file *interpreter, unsigned long *interp_map_addr,
53385- unsigned long no_base)
53386+ struct file *interpreter, unsigned long no_base)
53387 {
53388 struct elf_phdr *elf_phdata;
53389 struct elf_phdr *eppnt;
53390- unsigned long load_addr = 0;
53391+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
53392 int load_addr_set = 0;
53393 unsigned long last_bss = 0, elf_bss = 0;
53394- unsigned long error = ~0UL;
53395+ unsigned long error = -EINVAL;
53396 unsigned long total_size;
53397 int retval, i, size;
53398
53399@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53400 goto out_close;
53401 }
53402
53403+#ifdef CONFIG_PAX_SEGMEXEC
53404+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
53405+ pax_task_size = SEGMEXEC_TASK_SIZE;
53406+#endif
53407+
53408 eppnt = elf_phdata;
53409 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
53410 if (eppnt->p_type == PT_LOAD) {
53411@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53412 map_addr = elf_map(interpreter, load_addr + vaddr,
53413 eppnt, elf_prot, elf_type, total_size);
53414 total_size = 0;
53415- if (!*interp_map_addr)
53416- *interp_map_addr = map_addr;
53417 error = map_addr;
53418 if (BAD_ADDR(map_addr))
53419 goto out_close;
53420@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53421 k = load_addr + eppnt->p_vaddr;
53422 if (BAD_ADDR(k) ||
53423 eppnt->p_filesz > eppnt->p_memsz ||
53424- eppnt->p_memsz > TASK_SIZE ||
53425- TASK_SIZE - eppnt->p_memsz < k) {
53426+ eppnt->p_memsz > pax_task_size ||
53427+ pax_task_size - eppnt->p_memsz < k) {
53428 error = -ENOMEM;
53429 goto out_close;
53430 }
53431@@ -538,6 +567,315 @@ out:
53432 return error;
53433 }
53434
53435+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53436+#ifdef CONFIG_PAX_SOFTMODE
53437+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
53438+{
53439+ unsigned long pax_flags = 0UL;
53440+
53441+#ifdef CONFIG_PAX_PAGEEXEC
53442+ if (elf_phdata->p_flags & PF_PAGEEXEC)
53443+ pax_flags |= MF_PAX_PAGEEXEC;
53444+#endif
53445+
53446+#ifdef CONFIG_PAX_SEGMEXEC
53447+ if (elf_phdata->p_flags & PF_SEGMEXEC)
53448+ pax_flags |= MF_PAX_SEGMEXEC;
53449+#endif
53450+
53451+#ifdef CONFIG_PAX_EMUTRAMP
53452+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
53453+ pax_flags |= MF_PAX_EMUTRAMP;
53454+#endif
53455+
53456+#ifdef CONFIG_PAX_MPROTECT
53457+ if (elf_phdata->p_flags & PF_MPROTECT)
53458+ pax_flags |= MF_PAX_MPROTECT;
53459+#endif
53460+
53461+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53462+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
53463+ pax_flags |= MF_PAX_RANDMMAP;
53464+#endif
53465+
53466+ return pax_flags;
53467+}
53468+#endif
53469+
53470+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
53471+{
53472+ unsigned long pax_flags = 0UL;
53473+
53474+#ifdef CONFIG_PAX_PAGEEXEC
53475+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
53476+ pax_flags |= MF_PAX_PAGEEXEC;
53477+#endif
53478+
53479+#ifdef CONFIG_PAX_SEGMEXEC
53480+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
53481+ pax_flags |= MF_PAX_SEGMEXEC;
53482+#endif
53483+
53484+#ifdef CONFIG_PAX_EMUTRAMP
53485+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
53486+ pax_flags |= MF_PAX_EMUTRAMP;
53487+#endif
53488+
53489+#ifdef CONFIG_PAX_MPROTECT
53490+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
53491+ pax_flags |= MF_PAX_MPROTECT;
53492+#endif
53493+
53494+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53495+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
53496+ pax_flags |= MF_PAX_RANDMMAP;
53497+#endif
53498+
53499+ return pax_flags;
53500+}
53501+#endif
53502+
53503+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
53504+#ifdef CONFIG_PAX_SOFTMODE
53505+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
53506+{
53507+ unsigned long pax_flags = 0UL;
53508+
53509+#ifdef CONFIG_PAX_PAGEEXEC
53510+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
53511+ pax_flags |= MF_PAX_PAGEEXEC;
53512+#endif
53513+
53514+#ifdef CONFIG_PAX_SEGMEXEC
53515+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
53516+ pax_flags |= MF_PAX_SEGMEXEC;
53517+#endif
53518+
53519+#ifdef CONFIG_PAX_EMUTRAMP
53520+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
53521+ pax_flags |= MF_PAX_EMUTRAMP;
53522+#endif
53523+
53524+#ifdef CONFIG_PAX_MPROTECT
53525+ if (pax_flags_softmode & MF_PAX_MPROTECT)
53526+ pax_flags |= MF_PAX_MPROTECT;
53527+#endif
53528+
53529+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53530+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
53531+ pax_flags |= MF_PAX_RANDMMAP;
53532+#endif
53533+
53534+ return pax_flags;
53535+}
53536+#endif
53537+
53538+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
53539+{
53540+ unsigned long pax_flags = 0UL;
53541+
53542+#ifdef CONFIG_PAX_PAGEEXEC
53543+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
53544+ pax_flags |= MF_PAX_PAGEEXEC;
53545+#endif
53546+
53547+#ifdef CONFIG_PAX_SEGMEXEC
53548+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
53549+ pax_flags |= MF_PAX_SEGMEXEC;
53550+#endif
53551+
53552+#ifdef CONFIG_PAX_EMUTRAMP
53553+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
53554+ pax_flags |= MF_PAX_EMUTRAMP;
53555+#endif
53556+
53557+#ifdef CONFIG_PAX_MPROTECT
53558+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
53559+ pax_flags |= MF_PAX_MPROTECT;
53560+#endif
53561+
53562+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53563+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
53564+ pax_flags |= MF_PAX_RANDMMAP;
53565+#endif
53566+
53567+ return pax_flags;
53568+}
53569+#endif
53570+
53571+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53572+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
53573+{
53574+ unsigned long pax_flags = 0UL;
53575+
53576+#ifdef CONFIG_PAX_EI_PAX
53577+
53578+#ifdef CONFIG_PAX_PAGEEXEC
53579+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
53580+ pax_flags |= MF_PAX_PAGEEXEC;
53581+#endif
53582+
53583+#ifdef CONFIG_PAX_SEGMEXEC
53584+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
53585+ pax_flags |= MF_PAX_SEGMEXEC;
53586+#endif
53587+
53588+#ifdef CONFIG_PAX_EMUTRAMP
53589+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
53590+ pax_flags |= MF_PAX_EMUTRAMP;
53591+#endif
53592+
53593+#ifdef CONFIG_PAX_MPROTECT
53594+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
53595+ pax_flags |= MF_PAX_MPROTECT;
53596+#endif
53597+
53598+#ifdef CONFIG_PAX_ASLR
53599+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
53600+ pax_flags |= MF_PAX_RANDMMAP;
53601+#endif
53602+
53603+#else
53604+
53605+#ifdef CONFIG_PAX_PAGEEXEC
53606+ pax_flags |= MF_PAX_PAGEEXEC;
53607+#endif
53608+
53609+#ifdef CONFIG_PAX_SEGMEXEC
53610+ pax_flags |= MF_PAX_SEGMEXEC;
53611+#endif
53612+
53613+#ifdef CONFIG_PAX_MPROTECT
53614+ pax_flags |= MF_PAX_MPROTECT;
53615+#endif
53616+
53617+#ifdef CONFIG_PAX_RANDMMAP
53618+ if (randomize_va_space)
53619+ pax_flags |= MF_PAX_RANDMMAP;
53620+#endif
53621+
53622+#endif
53623+
53624+ return pax_flags;
53625+}
53626+
53627+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
53628+{
53629+
53630+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53631+ unsigned long i;
53632+
53633+ for (i = 0UL; i < elf_ex->e_phnum; i++)
53634+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
53635+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
53636+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
53637+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
53638+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
53639+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
53640+ return ~0UL;
53641+
53642+#ifdef CONFIG_PAX_SOFTMODE
53643+ if (pax_softmode)
53644+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
53645+ else
53646+#endif
53647+
53648+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
53649+ break;
53650+ }
53651+#endif
53652+
53653+ return ~0UL;
53654+}
53655+
53656+static unsigned long pax_parse_xattr_pax(struct file * const file)
53657+{
53658+
53659+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
53660+ ssize_t xattr_size, i;
53661+ unsigned char xattr_value[sizeof("pemrs") - 1];
53662+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
53663+
53664+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
53665+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
53666+ return ~0UL;
53667+
53668+ for (i = 0; i < xattr_size; i++)
53669+ switch (xattr_value[i]) {
53670+ default:
53671+ return ~0UL;
53672+
53673+#define parse_flag(option1, option2, flag) \
53674+ case option1: \
53675+ if (pax_flags_hardmode & MF_PAX_##flag) \
53676+ return ~0UL; \
53677+ pax_flags_hardmode |= MF_PAX_##flag; \
53678+ break; \
53679+ case option2: \
53680+ if (pax_flags_softmode & MF_PAX_##flag) \
53681+ return ~0UL; \
53682+ pax_flags_softmode |= MF_PAX_##flag; \
53683+ break;
53684+
53685+ parse_flag('p', 'P', PAGEEXEC);
53686+ parse_flag('e', 'E', EMUTRAMP);
53687+ parse_flag('m', 'M', MPROTECT);
53688+ parse_flag('r', 'R', RANDMMAP);
53689+ parse_flag('s', 'S', SEGMEXEC);
53690+
53691+#undef parse_flag
53692+ }
53693+
53694+ if (pax_flags_hardmode & pax_flags_softmode)
53695+ return ~0UL;
53696+
53697+#ifdef CONFIG_PAX_SOFTMODE
53698+ if (pax_softmode)
53699+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
53700+ else
53701+#endif
53702+
53703+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
53704+#else
53705+ return ~0UL;
53706+#endif
53707+
53708+}
53709+
53710+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
53711+{
53712+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
53713+
53714+ pax_flags = pax_parse_ei_pax(elf_ex);
53715+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
53716+ xattr_pax_flags = pax_parse_xattr_pax(file);
53717+
53718+ if (pt_pax_flags == ~0UL)
53719+ pt_pax_flags = xattr_pax_flags;
53720+ else if (xattr_pax_flags == ~0UL)
53721+ xattr_pax_flags = pt_pax_flags;
53722+ if (pt_pax_flags != xattr_pax_flags)
53723+ return -EINVAL;
53724+ if (pt_pax_flags != ~0UL)
53725+ pax_flags = pt_pax_flags;
53726+
53727+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
53728+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53729+ if ((__supported_pte_mask & _PAGE_NX))
53730+ pax_flags &= ~MF_PAX_SEGMEXEC;
53731+ else
53732+ pax_flags &= ~MF_PAX_PAGEEXEC;
53733+ }
53734+#endif
53735+
53736+ if (0 > pax_check_flags(&pax_flags))
53737+ return -EINVAL;
53738+
53739+ current->mm->pax_flags = pax_flags;
53740+ return 0;
53741+}
53742+#endif
53743+
53744 /*
53745 * These are the functions used to load ELF style executables and shared
53746 * libraries. There is no binary dependent code anywhere else.
53747@@ -554,6 +892,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
53748 {
53749 unsigned int random_variable = 0;
53750
53751+#ifdef CONFIG_PAX_RANDUSTACK
53752+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
53753+ return stack_top - current->mm->delta_stack;
53754+#endif
53755+
53756 if ((current->flags & PF_RANDOMIZE) &&
53757 !(current->personality & ADDR_NO_RANDOMIZE)) {
53758 random_variable = get_random_int() & STACK_RND_MASK;
53759@@ -572,7 +915,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
53760 unsigned long load_addr = 0, load_bias = 0;
53761 int load_addr_set = 0;
53762 char * elf_interpreter = NULL;
53763- unsigned long error;
53764+ unsigned long error = 0;
53765 struct elf_phdr *elf_ppnt, *elf_phdata;
53766 unsigned long elf_bss, elf_brk;
53767 int retval, i;
53768@@ -582,12 +925,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
53769 unsigned long start_code, end_code, start_data, end_data;
53770 unsigned long reloc_func_desc __maybe_unused = 0;
53771 int executable_stack = EXSTACK_DEFAULT;
53772- unsigned long def_flags = 0;
53773 struct pt_regs *regs = current_pt_regs();
53774 struct {
53775 struct elfhdr elf_ex;
53776 struct elfhdr interp_elf_ex;
53777 } *loc;
53778+ unsigned long pax_task_size = TASK_SIZE;
53779
53780 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
53781 if (!loc) {
53782@@ -723,11 +1066,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
53783 goto out_free_dentry;
53784
53785 /* OK, This is the point of no return */
53786- current->mm->def_flags = def_flags;
53787+
53788+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53789+ current->mm->pax_flags = 0UL;
53790+#endif
53791+
53792+#ifdef CONFIG_PAX_DLRESOLVE
53793+ current->mm->call_dl_resolve = 0UL;
53794+#endif
53795+
53796+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
53797+ current->mm->call_syscall = 0UL;
53798+#endif
53799+
53800+#ifdef CONFIG_PAX_ASLR
53801+ current->mm->delta_mmap = 0UL;
53802+ current->mm->delta_stack = 0UL;
53803+#endif
53804+
53805+ current->mm->def_flags = 0;
53806+
53807+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53808+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
53809+ send_sig(SIGKILL, current, 0);
53810+ goto out_free_dentry;
53811+ }
53812+#endif
53813+
53814+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
53815+ pax_set_initial_flags(bprm);
53816+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
53817+ if (pax_set_initial_flags_func)
53818+ (pax_set_initial_flags_func)(bprm);
53819+#endif
53820+
53821+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53822+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
53823+ current->mm->context.user_cs_limit = PAGE_SIZE;
53824+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
53825+ }
53826+#endif
53827+
53828+#ifdef CONFIG_PAX_SEGMEXEC
53829+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
53830+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
53831+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
53832+ pax_task_size = SEGMEXEC_TASK_SIZE;
53833+ current->mm->def_flags |= VM_NOHUGEPAGE;
53834+ }
53835+#endif
53836+
53837+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
53838+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53839+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
53840+ put_cpu();
53841+ }
53842+#endif
53843
53844 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
53845 may depend on the personality. */
53846 SET_PERSONALITY(loc->elf_ex);
53847+
53848+#ifdef CONFIG_PAX_ASLR
53849+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53850+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
53851+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
53852+ }
53853+#endif
53854+
53855+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
53856+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53857+ executable_stack = EXSTACK_DISABLE_X;
53858+ current->personality &= ~READ_IMPLIES_EXEC;
53859+ } else
53860+#endif
53861+
53862 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
53863 current->personality |= READ_IMPLIES_EXEC;
53864
53865@@ -819,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
53866 #else
53867 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
53868 #endif
53869+
53870+#ifdef CONFIG_PAX_RANDMMAP
53871+ /* PaX: randomize base address at the default exe base if requested */
53872+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
53873+#ifdef CONFIG_SPARC64
53874+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
53875+#else
53876+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
53877+#endif
53878+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
53879+ elf_flags |= MAP_FIXED;
53880+ }
53881+#endif
53882+
53883 }
53884
53885 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
53886@@ -851,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
53887 * allowed task size. Note that p_filesz must always be
53888 * <= p_memsz so it is only necessary to check p_memsz.
53889 */
53890- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53891- elf_ppnt->p_memsz > TASK_SIZE ||
53892- TASK_SIZE - elf_ppnt->p_memsz < k) {
53893+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53894+ elf_ppnt->p_memsz > pax_task_size ||
53895+ pax_task_size - elf_ppnt->p_memsz < k) {
53896 /* set_brk can never work. Avoid overflows. */
53897 send_sig(SIGKILL, current, 0);
53898 retval = -EINVAL;
53899@@ -892,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
53900 goto out_free_dentry;
53901 }
53902 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
53903- send_sig(SIGSEGV, current, 0);
53904- retval = -EFAULT; /* Nobody gets to see this, but.. */
53905- goto out_free_dentry;
53906+ /*
53907+ * This bss-zeroing can fail if the ELF
53908+ * file specifies odd protections. So
53909+ * we don't check the return value
53910+ */
53911 }
53912
53913+#ifdef CONFIG_PAX_RANDMMAP
53914+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53915+ unsigned long start, size, flags;
53916+ vm_flags_t vm_flags;
53917+
53918+ start = ELF_PAGEALIGN(elf_brk);
53919+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
53920+ flags = MAP_FIXED | MAP_PRIVATE;
53921+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
53922+
53923+ down_write(&current->mm->mmap_sem);
53924+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
53925+ retval = -ENOMEM;
53926+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
53927+// if (current->personality & ADDR_NO_RANDOMIZE)
53928+// vm_flags |= VM_READ | VM_MAYREAD;
53929+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
53930+ retval = IS_ERR_VALUE(start) ? start : 0;
53931+ }
53932+ up_write(&current->mm->mmap_sem);
53933+ if (retval == 0)
53934+ retval = set_brk(start + size, start + size + PAGE_SIZE);
53935+ if (retval < 0) {
53936+ send_sig(SIGKILL, current, 0);
53937+ goto out_free_dentry;
53938+ }
53939+ }
53940+#endif
53941+
53942 if (elf_interpreter) {
53943- unsigned long interp_map_addr = 0;
53944-
53945 elf_entry = load_elf_interp(&loc->interp_elf_ex,
53946 interpreter,
53947- &interp_map_addr,
53948 load_bias);
53949 if (!IS_ERR((void *)elf_entry)) {
53950 /*
53951@@ -1124,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
53952 * Decide what to dump of a segment, part, all or none.
53953 */
53954 static unsigned long vma_dump_size(struct vm_area_struct *vma,
53955- unsigned long mm_flags)
53956+ unsigned long mm_flags, long signr)
53957 {
53958 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
53959
53960@@ -1162,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
53961 if (vma->vm_file == NULL)
53962 return 0;
53963
53964- if (FILTER(MAPPED_PRIVATE))
53965+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
53966 goto whole;
53967
53968 /*
53969@@ -1387,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
53970 {
53971 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
53972 int i = 0;
53973- do
53974+ do {
53975 i += 2;
53976- while (auxv[i - 2] != AT_NULL);
53977+ } while (auxv[i - 2] != AT_NULL);
53978 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
53979 }
53980
53981@@ -1398,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
53982 {
53983 mm_segment_t old_fs = get_fs();
53984 set_fs(KERNEL_DS);
53985- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
53986+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
53987 set_fs(old_fs);
53988 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
53989 }
53990@@ -2019,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
53991 }
53992
53993 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
53994- unsigned long mm_flags)
53995+ struct coredump_params *cprm)
53996 {
53997 struct vm_area_struct *vma;
53998 size_t size = 0;
53999
54000 for (vma = first_vma(current, gate_vma); vma != NULL;
54001 vma = next_vma(vma, gate_vma))
54002- size += vma_dump_size(vma, mm_flags);
54003+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
54004 return size;
54005 }
54006
54007@@ -2119,7 +2574,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54008
54009 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
54010
54011- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
54012+ offset += elf_core_vma_data_size(gate_vma, cprm);
54013 offset += elf_core_extra_data_size();
54014 e_shoff = offset;
54015
54016@@ -2133,10 +2588,12 @@ static int elf_core_dump(struct coredump_params *cprm)
54017 offset = dataoff;
54018
54019 size += sizeof(*elf);
54020+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54021 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
54022 goto end_coredump;
54023
54024 size += sizeof(*phdr4note);
54025+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54026 if (size > cprm->limit
54027 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
54028 goto end_coredump;
54029@@ -2150,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54030 phdr.p_offset = offset;
54031 phdr.p_vaddr = vma->vm_start;
54032 phdr.p_paddr = 0;
54033- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
54034+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
54035 phdr.p_memsz = vma->vm_end - vma->vm_start;
54036 offset += phdr.p_filesz;
54037 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
54038@@ -2161,6 +2618,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54039 phdr.p_align = ELF_EXEC_PAGESIZE;
54040
54041 size += sizeof(phdr);
54042+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54043 if (size > cprm->limit
54044 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
54045 goto end_coredump;
54046@@ -2185,7 +2643,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54047 unsigned long addr;
54048 unsigned long end;
54049
54050- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
54051+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
54052
54053 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
54054 struct page *page;
54055@@ -2194,6 +2652,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54056 page = get_dump_page(addr);
54057 if (page) {
54058 void *kaddr = kmap(page);
54059+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
54060 stop = ((size += PAGE_SIZE) > cprm->limit) ||
54061 !dump_write(cprm->file, kaddr,
54062 PAGE_SIZE);
54063@@ -2211,6 +2670,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54064
54065 if (e_phnum == PN_XNUM) {
54066 size += sizeof(*shdr4extnum);
54067+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54068 if (size > cprm->limit
54069 || !dump_write(cprm->file, shdr4extnum,
54070 sizeof(*shdr4extnum)))
54071@@ -2231,6 +2691,167 @@ out:
54072
54073 #endif /* CONFIG_ELF_CORE */
54074
54075+#ifdef CONFIG_PAX_MPROTECT
54076+/* PaX: non-PIC ELF libraries need relocations on their executable segments
54077+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
54078+ * we'll remove VM_MAYWRITE for good on RELRO segments.
54079+ *
54080+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
54081+ * basis because we want to allow the common case and not the special ones.
54082+ */
54083+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
54084+{
54085+ struct elfhdr elf_h;
54086+ struct elf_phdr elf_p;
54087+ unsigned long i;
54088+ unsigned long oldflags;
54089+ bool is_textrel_rw, is_textrel_rx, is_relro;
54090+
54091+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
54092+ return;
54093+
54094+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
54095+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
54096+
54097+#ifdef CONFIG_PAX_ELFRELOCS
54098+ /* possible TEXTREL */
54099+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
54100+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
54101+#else
54102+ is_textrel_rw = false;
54103+ is_textrel_rx = false;
54104+#endif
54105+
54106+ /* possible RELRO */
54107+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
54108+
54109+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
54110+ return;
54111+
54112+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
54113+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
54114+
54115+#ifdef CONFIG_PAX_ETEXECRELOCS
54116+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
54117+#else
54118+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
54119+#endif
54120+
54121+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
54122+ !elf_check_arch(&elf_h) ||
54123+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
54124+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
54125+ return;
54126+
54127+ for (i = 0UL; i < elf_h.e_phnum; i++) {
54128+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
54129+ return;
54130+ switch (elf_p.p_type) {
54131+ case PT_DYNAMIC:
54132+ if (!is_textrel_rw && !is_textrel_rx)
54133+ continue;
54134+ i = 0UL;
54135+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
54136+ elf_dyn dyn;
54137+
54138+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
54139+ break;
54140+ if (dyn.d_tag == DT_NULL)
54141+ break;
54142+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
54143+ gr_log_textrel(vma);
54144+ if (is_textrel_rw)
54145+ vma->vm_flags |= VM_MAYWRITE;
54146+ else
54147+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
54148+ vma->vm_flags &= ~VM_MAYWRITE;
54149+ break;
54150+ }
54151+ i++;
54152+ }
54153+ is_textrel_rw = false;
54154+ is_textrel_rx = false;
54155+ continue;
54156+
54157+ case PT_GNU_RELRO:
54158+ if (!is_relro)
54159+ continue;
54160+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
54161+ vma->vm_flags &= ~VM_MAYWRITE;
54162+ is_relro = false;
54163+ continue;
54164+
54165+#ifdef CONFIG_PAX_PT_PAX_FLAGS
54166+ case PT_PAX_FLAGS: {
54167+ const char *msg_mprotect = "", *msg_emutramp = "";
54168+ char *buffer_lib, *buffer_exe;
54169+
54170+ if (elf_p.p_flags & PF_NOMPROTECT)
54171+ msg_mprotect = "MPROTECT disabled";
54172+
54173+#ifdef CONFIG_PAX_EMUTRAMP
54174+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
54175+ msg_emutramp = "EMUTRAMP enabled";
54176+#endif
54177+
54178+ if (!msg_mprotect[0] && !msg_emutramp[0])
54179+ continue;
54180+
54181+ if (!printk_ratelimit())
54182+ continue;
54183+
54184+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
54185+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
54186+ if (buffer_lib && buffer_exe) {
54187+ char *path_lib, *path_exe;
54188+
54189+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
54190+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
54191+
54192+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
54193+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
54194+
54195+ }
54196+ free_page((unsigned long)buffer_exe);
54197+ free_page((unsigned long)buffer_lib);
54198+ continue;
54199+ }
54200+#endif
54201+
54202+ }
54203+ }
54204+}
54205+#endif
54206+
54207+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
54208+
54209+extern int grsec_enable_log_rwxmaps;
54210+
54211+static void elf_handle_mmap(struct file *file)
54212+{
54213+ struct elfhdr elf_h;
54214+ struct elf_phdr elf_p;
54215+ unsigned long i;
54216+
54217+ if (!grsec_enable_log_rwxmaps)
54218+ return;
54219+
54220+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
54221+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
54222+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
54223+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
54224+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
54225+ return;
54226+
54227+ for (i = 0UL; i < elf_h.e_phnum; i++) {
54228+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
54229+ return;
54230+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
54231+ gr_log_ptgnustack(file);
54232+ }
54233+}
54234+#endif
54235+
54236 static int __init init_elf_binfmt(void)
54237 {
54238 register_binfmt(&elf_format);
54239diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
54240index d50bbe5..af3b649 100644
54241--- a/fs/binfmt_flat.c
54242+++ b/fs/binfmt_flat.c
54243@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
54244 realdatastart = (unsigned long) -ENOMEM;
54245 printk("Unable to allocate RAM for process data, errno %d\n",
54246 (int)-realdatastart);
54247+ down_write(&current->mm->mmap_sem);
54248 vm_munmap(textpos, text_len);
54249+ up_write(&current->mm->mmap_sem);
54250 ret = realdatastart;
54251 goto err;
54252 }
54253@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
54254 }
54255 if (IS_ERR_VALUE(result)) {
54256 printk("Unable to read data+bss, errno %d\n", (int)-result);
54257+ down_write(&current->mm->mmap_sem);
54258 vm_munmap(textpos, text_len);
54259 vm_munmap(realdatastart, len);
54260+ up_write(&current->mm->mmap_sem);
54261 ret = result;
54262 goto err;
54263 }
54264@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
54265 }
54266 if (IS_ERR_VALUE(result)) {
54267 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
54268+ down_write(&current->mm->mmap_sem);
54269 vm_munmap(textpos, text_len + data_len + extra +
54270 MAX_SHARED_LIBS * sizeof(unsigned long));
54271+ up_write(&current->mm->mmap_sem);
54272 ret = result;
54273 goto err;
54274 }
54275diff --git a/fs/bio.c b/fs/bio.c
54276index c5eae72..599e3cf 100644
54277--- a/fs/bio.c
54278+++ b/fs/bio.c
54279@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
54280 /*
54281 * Overflow, abort
54282 */
54283- if (end < start)
54284+ if (end < start || end - start > INT_MAX - nr_pages)
54285 return ERR_PTR(-EINVAL);
54286
54287 nr_pages += end - start;
54288@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
54289 /*
54290 * Overflow, abort
54291 */
54292- if (end < start)
54293+ if (end < start || end - start > INT_MAX - nr_pages)
54294 return ERR_PTR(-EINVAL);
54295
54296 nr_pages += end - start;
54297@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
54298 const int read = bio_data_dir(bio) == READ;
54299 struct bio_map_data *bmd = bio->bi_private;
54300 int i;
54301- char *p = bmd->sgvecs[0].iov_base;
54302+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
54303
54304 bio_for_each_segment_all(bvec, bio, i) {
54305 char *addr = page_address(bvec->bv_page);
54306diff --git a/fs/block_dev.c b/fs/block_dev.c
54307index 85f5c85..d6f0b1a 100644
54308--- a/fs/block_dev.c
54309+++ b/fs/block_dev.c
54310@@ -658,7 +658,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
54311 else if (bdev->bd_contains == bdev)
54312 return true; /* is a whole device which isn't held */
54313
54314- else if (whole->bd_holder == bd_may_claim)
54315+ else if (whole->bd_holder == (void *)bd_may_claim)
54316 return true; /* is a partition of a device that is being partitioned */
54317 else if (whole->bd_holder != NULL)
54318 return false; /* is a partition of a held device */
54319diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
54320index 7fb054b..ad36c67 100644
54321--- a/fs/btrfs/ctree.c
54322+++ b/fs/btrfs/ctree.c
54323@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
54324 free_extent_buffer(buf);
54325 add_root_to_dirty_list(root);
54326 } else {
54327- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
54328- parent_start = parent->start;
54329- else
54330+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
54331+ if (parent)
54332+ parent_start = parent->start;
54333+ else
54334+ parent_start = 0;
54335+ } else
54336 parent_start = 0;
54337
54338 WARN_ON(trans->transid != btrfs_header_generation(parent));
54339diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
54340index f26f38c..3d0f149 100644
54341--- a/fs/btrfs/delayed-inode.c
54342+++ b/fs/btrfs/delayed-inode.c
54343@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
54344
54345 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
54346 {
54347- int seq = atomic_inc_return(&delayed_root->items_seq);
54348+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
54349 if ((atomic_dec_return(&delayed_root->items) <
54350 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
54351 waitqueue_active(&delayed_root->wait))
54352@@ -1391,7 +1391,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
54353 static int refs_newer(struct btrfs_delayed_root *delayed_root,
54354 int seq, int count)
54355 {
54356- int val = atomic_read(&delayed_root->items_seq);
54357+ int val = atomic_read_unchecked(&delayed_root->items_seq);
54358
54359 if (val < seq || val >= seq + count)
54360 return 1;
54361@@ -1408,7 +1408,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
54362 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
54363 return;
54364
54365- seq = atomic_read(&delayed_root->items_seq);
54366+ seq = atomic_read_unchecked(&delayed_root->items_seq);
54367
54368 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
54369 int ret;
54370diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
54371index 1d5c5f7..0ba0afc 100644
54372--- a/fs/btrfs/delayed-inode.h
54373+++ b/fs/btrfs/delayed-inode.h
54374@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
54375 */
54376 struct list_head prepare_list;
54377 atomic_t items; /* for delayed items */
54378- atomic_t items_seq; /* for delayed items */
54379+ atomic_unchecked_t items_seq; /* for delayed items */
54380 int nodes; /* for delayed nodes */
54381 wait_queue_head_t wait;
54382 };
54383@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
54384 struct btrfs_delayed_root *delayed_root)
54385 {
54386 atomic_set(&delayed_root->items, 0);
54387- atomic_set(&delayed_root->items_seq, 0);
54388+ atomic_set_unchecked(&delayed_root->items_seq, 0);
54389 delayed_root->nodes = 0;
54390 spin_lock_init(&delayed_root->lock);
54391 init_waitqueue_head(&delayed_root->wait);
54392diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
54393index 0f81d67..0ad55fe 100644
54394--- a/fs/btrfs/ioctl.c
54395+++ b/fs/btrfs/ioctl.c
54396@@ -3084,9 +3084,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
54397 for (i = 0; i < num_types; i++) {
54398 struct btrfs_space_info *tmp;
54399
54400+ /* Don't copy in more than we allocated */
54401 if (!slot_count)
54402 break;
54403
54404+ slot_count--;
54405+
54406 info = NULL;
54407 rcu_read_lock();
54408 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
54409@@ -3108,10 +3111,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
54410 memcpy(dest, &space, sizeof(space));
54411 dest++;
54412 space_args.total_spaces++;
54413- slot_count--;
54414 }
54415- if (!slot_count)
54416- break;
54417 }
54418 up_read(&info->groups_sem);
54419 }
54420diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
54421index f0857e0..e7023c5 100644
54422--- a/fs/btrfs/super.c
54423+++ b/fs/btrfs/super.c
54424@@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
54425 function, line, errstr);
54426 return;
54427 }
54428- ACCESS_ONCE(trans->transaction->aborted) = errno;
54429+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
54430 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
54431 }
54432 /*
54433diff --git a/fs/buffer.c b/fs/buffer.c
54434index d2a4d1b..df798ca 100644
54435--- a/fs/buffer.c
54436+++ b/fs/buffer.c
54437@@ -3367,7 +3367,7 @@ void __init buffer_init(void)
54438 bh_cachep = kmem_cache_create("buffer_head",
54439 sizeof(struct buffer_head), 0,
54440 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
54441- SLAB_MEM_SPREAD),
54442+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
54443 NULL);
54444
54445 /*
54446diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
54447index 622f469..e8d2d55 100644
54448--- a/fs/cachefiles/bind.c
54449+++ b/fs/cachefiles/bind.c
54450@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
54451 args);
54452
54453 /* start by checking things over */
54454- ASSERT(cache->fstop_percent >= 0 &&
54455- cache->fstop_percent < cache->fcull_percent &&
54456+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
54457 cache->fcull_percent < cache->frun_percent &&
54458 cache->frun_percent < 100);
54459
54460- ASSERT(cache->bstop_percent >= 0 &&
54461- cache->bstop_percent < cache->bcull_percent &&
54462+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
54463 cache->bcull_percent < cache->brun_percent &&
54464 cache->brun_percent < 100);
54465
54466diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
54467index 0a1467b..6a53245 100644
54468--- a/fs/cachefiles/daemon.c
54469+++ b/fs/cachefiles/daemon.c
54470@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
54471 if (n > buflen)
54472 return -EMSGSIZE;
54473
54474- if (copy_to_user(_buffer, buffer, n) != 0)
54475+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
54476 return -EFAULT;
54477
54478 return n;
54479@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
54480 if (test_bit(CACHEFILES_DEAD, &cache->flags))
54481 return -EIO;
54482
54483- if (datalen < 0 || datalen > PAGE_SIZE - 1)
54484+ if (datalen > PAGE_SIZE - 1)
54485 return -EOPNOTSUPP;
54486
54487 /* drag the command string into the kernel so we can parse it */
54488@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
54489 if (args[0] != '%' || args[1] != '\0')
54490 return -EINVAL;
54491
54492- if (fstop < 0 || fstop >= cache->fcull_percent)
54493+ if (fstop >= cache->fcull_percent)
54494 return cachefiles_daemon_range_error(cache, args);
54495
54496 cache->fstop_percent = fstop;
54497@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
54498 if (args[0] != '%' || args[1] != '\0')
54499 return -EINVAL;
54500
54501- if (bstop < 0 || bstop >= cache->bcull_percent)
54502+ if (bstop >= cache->bcull_percent)
54503 return cachefiles_daemon_range_error(cache, args);
54504
54505 cache->bstop_percent = bstop;
54506diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
54507index 4938251..7e01445 100644
54508--- a/fs/cachefiles/internal.h
54509+++ b/fs/cachefiles/internal.h
54510@@ -59,7 +59,7 @@ struct cachefiles_cache {
54511 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
54512 struct rb_root active_nodes; /* active nodes (can't be culled) */
54513 rwlock_t active_lock; /* lock for active_nodes */
54514- atomic_t gravecounter; /* graveyard uniquifier */
54515+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
54516 unsigned frun_percent; /* when to stop culling (% files) */
54517 unsigned fcull_percent; /* when to start culling (% files) */
54518 unsigned fstop_percent; /* when to stop allocating (% files) */
54519@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
54520 * proc.c
54521 */
54522 #ifdef CONFIG_CACHEFILES_HISTOGRAM
54523-extern atomic_t cachefiles_lookup_histogram[HZ];
54524-extern atomic_t cachefiles_mkdir_histogram[HZ];
54525-extern atomic_t cachefiles_create_histogram[HZ];
54526+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
54527+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
54528+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
54529
54530 extern int __init cachefiles_proc_init(void);
54531 extern void cachefiles_proc_cleanup(void);
54532 static inline
54533-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
54534+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
54535 {
54536 unsigned long jif = jiffies - start_jif;
54537 if (jif >= HZ)
54538 jif = HZ - 1;
54539- atomic_inc(&histogram[jif]);
54540+ atomic_inc_unchecked(&histogram[jif]);
54541 }
54542
54543 #else
54544diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
54545index 8c01c5fc..15f982e 100644
54546--- a/fs/cachefiles/namei.c
54547+++ b/fs/cachefiles/namei.c
54548@@ -317,7 +317,7 @@ try_again:
54549 /* first step is to make up a grave dentry in the graveyard */
54550 sprintf(nbuffer, "%08x%08x",
54551 (uint32_t) get_seconds(),
54552- (uint32_t) atomic_inc_return(&cache->gravecounter));
54553+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
54554
54555 /* do the multiway lock magic */
54556 trap = lock_rename(cache->graveyard, dir);
54557diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
54558index eccd339..4c1d995 100644
54559--- a/fs/cachefiles/proc.c
54560+++ b/fs/cachefiles/proc.c
54561@@ -14,9 +14,9 @@
54562 #include <linux/seq_file.h>
54563 #include "internal.h"
54564
54565-atomic_t cachefiles_lookup_histogram[HZ];
54566-atomic_t cachefiles_mkdir_histogram[HZ];
54567-atomic_t cachefiles_create_histogram[HZ];
54568+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
54569+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
54570+atomic_unchecked_t cachefiles_create_histogram[HZ];
54571
54572 /*
54573 * display the latency histogram
54574@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
54575 return 0;
54576 default:
54577 index = (unsigned long) v - 3;
54578- x = atomic_read(&cachefiles_lookup_histogram[index]);
54579- y = atomic_read(&cachefiles_mkdir_histogram[index]);
54580- z = atomic_read(&cachefiles_create_histogram[index]);
54581+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
54582+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
54583+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
54584 if (x == 0 && y == 0 && z == 0)
54585 return 0;
54586
54587diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
54588index 317f9ee..3d24511 100644
54589--- a/fs/cachefiles/rdwr.c
54590+++ b/fs/cachefiles/rdwr.c
54591@@ -966,7 +966,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
54592 old_fs = get_fs();
54593 set_fs(KERNEL_DS);
54594 ret = file->f_op->write(
54595- file, (const void __user *) data, len, &pos);
54596+ file, (const void __force_user *) data, len, &pos);
54597 set_fs(old_fs);
54598 kunmap(page);
54599 file_end_write(file);
54600diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
54601index f02d82b..2632cf86 100644
54602--- a/fs/ceph/dir.c
54603+++ b/fs/ceph/dir.c
54604@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
54605 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
54606 struct ceph_mds_client *mdsc = fsc->mdsc;
54607 unsigned frag = fpos_frag(filp->f_pos);
54608- int off = fpos_off(filp->f_pos);
54609+ unsigned int off = fpos_off(filp->f_pos);
54610 int err;
54611 u32 ftype;
54612 struct ceph_mds_reply_info_parsed *rinfo;
54613diff --git a/fs/ceph/super.c b/fs/ceph/super.c
54614index 7d377c9..3fb6559 100644
54615--- a/fs/ceph/super.c
54616+++ b/fs/ceph/super.c
54617@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
54618 /*
54619 * construct our own bdi so we can control readahead, etc.
54620 */
54621-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
54622+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
54623
54624 static int ceph_register_bdi(struct super_block *sb,
54625 struct ceph_fs_client *fsc)
54626@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
54627 default_backing_dev_info.ra_pages;
54628
54629 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
54630- atomic_long_inc_return(&bdi_seq));
54631+ atomic_long_inc_return_unchecked(&bdi_seq));
54632 if (!err)
54633 sb->s_bdi = &fsc->backing_dev_info;
54634 return err;
54635diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
54636index d597483..747901b 100644
54637--- a/fs/cifs/cifs_debug.c
54638+++ b/fs/cifs/cifs_debug.c
54639@@ -284,8 +284,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
54640
54641 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
54642 #ifdef CONFIG_CIFS_STATS2
54643- atomic_set(&totBufAllocCount, 0);
54644- atomic_set(&totSmBufAllocCount, 0);
54645+ atomic_set_unchecked(&totBufAllocCount, 0);
54646+ atomic_set_unchecked(&totSmBufAllocCount, 0);
54647 #endif /* CONFIG_CIFS_STATS2 */
54648 spin_lock(&cifs_tcp_ses_lock);
54649 list_for_each(tmp1, &cifs_tcp_ses_list) {
54650@@ -298,7 +298,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
54651 tcon = list_entry(tmp3,
54652 struct cifs_tcon,
54653 tcon_list);
54654- atomic_set(&tcon->num_smbs_sent, 0);
54655+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
54656 if (server->ops->clear_stats)
54657 server->ops->clear_stats(tcon);
54658 }
54659@@ -330,8 +330,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
54660 smBufAllocCount.counter, cifs_min_small);
54661 #ifdef CONFIG_CIFS_STATS2
54662 seq_printf(m, "Total Large %d Small %d Allocations\n",
54663- atomic_read(&totBufAllocCount),
54664- atomic_read(&totSmBufAllocCount));
54665+ atomic_read_unchecked(&totBufAllocCount),
54666+ atomic_read_unchecked(&totSmBufAllocCount));
54667 #endif /* CONFIG_CIFS_STATS2 */
54668
54669 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
54670@@ -360,7 +360,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
54671 if (tcon->need_reconnect)
54672 seq_puts(m, "\tDISCONNECTED ");
54673 seq_printf(m, "\nSMBs: %d",
54674- atomic_read(&tcon->num_smbs_sent));
54675+ atomic_read_unchecked(&tcon->num_smbs_sent));
54676 if (server->ops->print_stats)
54677 server->ops->print_stats(m, tcon);
54678 }
54679diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
54680index 3752b9f..8db5569 100644
54681--- a/fs/cifs/cifsfs.c
54682+++ b/fs/cifs/cifsfs.c
54683@@ -1035,7 +1035,7 @@ cifs_init_request_bufs(void)
54684 */
54685 cifs_req_cachep = kmem_cache_create("cifs_request",
54686 CIFSMaxBufSize + max_hdr_size, 0,
54687- SLAB_HWCACHE_ALIGN, NULL);
54688+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
54689 if (cifs_req_cachep == NULL)
54690 return -ENOMEM;
54691
54692@@ -1062,7 +1062,7 @@ cifs_init_request_bufs(void)
54693 efficient to alloc 1 per page off the slab compared to 17K (5page)
54694 alloc of large cifs buffers even when page debugging is on */
54695 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
54696- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
54697+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
54698 NULL);
54699 if (cifs_sm_req_cachep == NULL) {
54700 mempool_destroy(cifs_req_poolp);
54701@@ -1147,8 +1147,8 @@ init_cifs(void)
54702 atomic_set(&bufAllocCount, 0);
54703 atomic_set(&smBufAllocCount, 0);
54704 #ifdef CONFIG_CIFS_STATS2
54705- atomic_set(&totBufAllocCount, 0);
54706- atomic_set(&totSmBufAllocCount, 0);
54707+ atomic_set_unchecked(&totBufAllocCount, 0);
54708+ atomic_set_unchecked(&totSmBufAllocCount, 0);
54709 #endif /* CONFIG_CIFS_STATS2 */
54710
54711 atomic_set(&midCount, 0);
54712diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
54713index ea3a0b3..0194e39 100644
54714--- a/fs/cifs/cifsglob.h
54715+++ b/fs/cifs/cifsglob.h
54716@@ -752,35 +752,35 @@ struct cifs_tcon {
54717 __u16 Flags; /* optional support bits */
54718 enum statusEnum tidStatus;
54719 #ifdef CONFIG_CIFS_STATS
54720- atomic_t num_smbs_sent;
54721+ atomic_unchecked_t num_smbs_sent;
54722 union {
54723 struct {
54724- atomic_t num_writes;
54725- atomic_t num_reads;
54726- atomic_t num_flushes;
54727- atomic_t num_oplock_brks;
54728- atomic_t num_opens;
54729- atomic_t num_closes;
54730- atomic_t num_deletes;
54731- atomic_t num_mkdirs;
54732- atomic_t num_posixopens;
54733- atomic_t num_posixmkdirs;
54734- atomic_t num_rmdirs;
54735- atomic_t num_renames;
54736- atomic_t num_t2renames;
54737- atomic_t num_ffirst;
54738- atomic_t num_fnext;
54739- atomic_t num_fclose;
54740- atomic_t num_hardlinks;
54741- atomic_t num_symlinks;
54742- atomic_t num_locks;
54743- atomic_t num_acl_get;
54744- atomic_t num_acl_set;
54745+ atomic_unchecked_t num_writes;
54746+ atomic_unchecked_t num_reads;
54747+ atomic_unchecked_t num_flushes;
54748+ atomic_unchecked_t num_oplock_brks;
54749+ atomic_unchecked_t num_opens;
54750+ atomic_unchecked_t num_closes;
54751+ atomic_unchecked_t num_deletes;
54752+ atomic_unchecked_t num_mkdirs;
54753+ atomic_unchecked_t num_posixopens;
54754+ atomic_unchecked_t num_posixmkdirs;
54755+ atomic_unchecked_t num_rmdirs;
54756+ atomic_unchecked_t num_renames;
54757+ atomic_unchecked_t num_t2renames;
54758+ atomic_unchecked_t num_ffirst;
54759+ atomic_unchecked_t num_fnext;
54760+ atomic_unchecked_t num_fclose;
54761+ atomic_unchecked_t num_hardlinks;
54762+ atomic_unchecked_t num_symlinks;
54763+ atomic_unchecked_t num_locks;
54764+ atomic_unchecked_t num_acl_get;
54765+ atomic_unchecked_t num_acl_set;
54766 } cifs_stats;
54767 #ifdef CONFIG_CIFS_SMB2
54768 struct {
54769- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
54770- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
54771+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
54772+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
54773 } smb2_stats;
54774 #endif /* CONFIG_CIFS_SMB2 */
54775 } stats;
54776@@ -1081,7 +1081,7 @@ convert_delimiter(char *path, char delim)
54777 }
54778
54779 #ifdef CONFIG_CIFS_STATS
54780-#define cifs_stats_inc atomic_inc
54781+#define cifs_stats_inc atomic_inc_unchecked
54782
54783 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
54784 unsigned int bytes)
54785@@ -1446,8 +1446,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
54786 /* Various Debug counters */
54787 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
54788 #ifdef CONFIG_CIFS_STATS2
54789-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
54790-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
54791+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
54792+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
54793 #endif
54794 GLOBAL_EXTERN atomic_t smBufAllocCount;
54795 GLOBAL_EXTERN atomic_t midCount;
54796diff --git a/fs/cifs/link.c b/fs/cifs/link.c
54797index b83c3f5..6437caa 100644
54798--- a/fs/cifs/link.c
54799+++ b/fs/cifs/link.c
54800@@ -616,7 +616,7 @@ symlink_exit:
54801
54802 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
54803 {
54804- char *p = nd_get_link(nd);
54805+ const char *p = nd_get_link(nd);
54806 if (!IS_ERR(p))
54807 kfree(p);
54808 }
54809diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
54810index 1bec014..f329411 100644
54811--- a/fs/cifs/misc.c
54812+++ b/fs/cifs/misc.c
54813@@ -169,7 +169,7 @@ cifs_buf_get(void)
54814 memset(ret_buf, 0, buf_size + 3);
54815 atomic_inc(&bufAllocCount);
54816 #ifdef CONFIG_CIFS_STATS2
54817- atomic_inc(&totBufAllocCount);
54818+ atomic_inc_unchecked(&totBufAllocCount);
54819 #endif /* CONFIG_CIFS_STATS2 */
54820 }
54821
54822@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
54823 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
54824 atomic_inc(&smBufAllocCount);
54825 #ifdef CONFIG_CIFS_STATS2
54826- atomic_inc(&totSmBufAllocCount);
54827+ atomic_inc_unchecked(&totSmBufAllocCount);
54828 #endif /* CONFIG_CIFS_STATS2 */
54829
54830 }
54831diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
54832index 3efdb9d..e845a5e 100644
54833--- a/fs/cifs/smb1ops.c
54834+++ b/fs/cifs/smb1ops.c
54835@@ -591,27 +591,27 @@ static void
54836 cifs_clear_stats(struct cifs_tcon *tcon)
54837 {
54838 #ifdef CONFIG_CIFS_STATS
54839- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
54840- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
54841- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
54842- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54843- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
54844- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
54845- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54846- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
54847- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
54848- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
54849- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
54850- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
54851- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
54852- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
54853- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
54854- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
54855- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
54856- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
54857- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
54858- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
54859- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
54860+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
54861+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
54862+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
54863+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54864+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
54865+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
54866+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54867+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
54868+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
54869+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
54870+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
54871+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
54872+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
54873+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
54874+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
54875+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
54876+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
54877+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
54878+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
54879+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
54880+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
54881 #endif
54882 }
54883
54884@@ -620,36 +620,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54885 {
54886 #ifdef CONFIG_CIFS_STATS
54887 seq_printf(m, " Oplocks breaks: %d",
54888- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
54889+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
54890 seq_printf(m, "\nReads: %d Bytes: %llu",
54891- atomic_read(&tcon->stats.cifs_stats.num_reads),
54892+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
54893 (long long)(tcon->bytes_read));
54894 seq_printf(m, "\nWrites: %d Bytes: %llu",
54895- atomic_read(&tcon->stats.cifs_stats.num_writes),
54896+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
54897 (long long)(tcon->bytes_written));
54898 seq_printf(m, "\nFlushes: %d",
54899- atomic_read(&tcon->stats.cifs_stats.num_flushes));
54900+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
54901 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
54902- atomic_read(&tcon->stats.cifs_stats.num_locks),
54903- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
54904- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
54905+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
54906+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
54907+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
54908 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
54909- atomic_read(&tcon->stats.cifs_stats.num_opens),
54910- atomic_read(&tcon->stats.cifs_stats.num_closes),
54911- atomic_read(&tcon->stats.cifs_stats.num_deletes));
54912+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
54913+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
54914+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
54915 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
54916- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
54917- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
54918+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
54919+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
54920 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
54921- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
54922- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
54923+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
54924+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
54925 seq_printf(m, "\nRenames: %d T2 Renames %d",
54926- atomic_read(&tcon->stats.cifs_stats.num_renames),
54927- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
54928+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
54929+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
54930 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
54931- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
54932- atomic_read(&tcon->stats.cifs_stats.num_fnext),
54933- atomic_read(&tcon->stats.cifs_stats.num_fclose));
54934+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
54935+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
54936+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
54937 #endif
54938 }
54939
54940diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
54941index f2e76f3..c44fac7 100644
54942--- a/fs/cifs/smb2ops.c
54943+++ b/fs/cifs/smb2ops.c
54944@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
54945 #ifdef CONFIG_CIFS_STATS
54946 int i;
54947 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
54948- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54949- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54950+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54951+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54952 }
54953 #endif
54954 }
54955@@ -284,66 +284,66 @@ static void
54956 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54957 {
54958 #ifdef CONFIG_CIFS_STATS
54959- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54960- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54961+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54962+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54963 seq_printf(m, "\nNegotiates: %d sent %d failed",
54964- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
54965- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
54966+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
54967+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
54968 seq_printf(m, "\nSessionSetups: %d sent %d failed",
54969- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
54970- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
54971+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
54972+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
54973 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
54974 seq_printf(m, "\nLogoffs: %d sent %d failed",
54975- atomic_read(&sent[SMB2_LOGOFF_HE]),
54976- atomic_read(&failed[SMB2_LOGOFF_HE]));
54977+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
54978+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
54979 seq_printf(m, "\nTreeConnects: %d sent %d failed",
54980- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
54981- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
54982+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
54983+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
54984 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
54985- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
54986- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
54987+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
54988+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
54989 seq_printf(m, "\nCreates: %d sent %d failed",
54990- atomic_read(&sent[SMB2_CREATE_HE]),
54991- atomic_read(&failed[SMB2_CREATE_HE]));
54992+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
54993+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
54994 seq_printf(m, "\nCloses: %d sent %d failed",
54995- atomic_read(&sent[SMB2_CLOSE_HE]),
54996- atomic_read(&failed[SMB2_CLOSE_HE]));
54997+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
54998+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
54999 seq_printf(m, "\nFlushes: %d sent %d failed",
55000- atomic_read(&sent[SMB2_FLUSH_HE]),
55001- atomic_read(&failed[SMB2_FLUSH_HE]));
55002+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
55003+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
55004 seq_printf(m, "\nReads: %d sent %d failed",
55005- atomic_read(&sent[SMB2_READ_HE]),
55006- atomic_read(&failed[SMB2_READ_HE]));
55007+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
55008+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
55009 seq_printf(m, "\nWrites: %d sent %d failed",
55010- atomic_read(&sent[SMB2_WRITE_HE]),
55011- atomic_read(&failed[SMB2_WRITE_HE]));
55012+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
55013+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
55014 seq_printf(m, "\nLocks: %d sent %d failed",
55015- atomic_read(&sent[SMB2_LOCK_HE]),
55016- atomic_read(&failed[SMB2_LOCK_HE]));
55017+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
55018+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
55019 seq_printf(m, "\nIOCTLs: %d sent %d failed",
55020- atomic_read(&sent[SMB2_IOCTL_HE]),
55021- atomic_read(&failed[SMB2_IOCTL_HE]));
55022+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
55023+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
55024 seq_printf(m, "\nCancels: %d sent %d failed",
55025- atomic_read(&sent[SMB2_CANCEL_HE]),
55026- atomic_read(&failed[SMB2_CANCEL_HE]));
55027+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
55028+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
55029 seq_printf(m, "\nEchos: %d sent %d failed",
55030- atomic_read(&sent[SMB2_ECHO_HE]),
55031- atomic_read(&failed[SMB2_ECHO_HE]));
55032+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
55033+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
55034 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
55035- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
55036- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
55037+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
55038+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
55039 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
55040- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
55041- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
55042+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
55043+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
55044 seq_printf(m, "\nQueryInfos: %d sent %d failed",
55045- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
55046- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
55047+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
55048+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
55049 seq_printf(m, "\nSetInfos: %d sent %d failed",
55050- atomic_read(&sent[SMB2_SET_INFO_HE]),
55051- atomic_read(&failed[SMB2_SET_INFO_HE]));
55052+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
55053+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
55054 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
55055- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
55056- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
55057+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
55058+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
55059 #endif
55060 }
55061
55062diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
55063index 2b95ce2..d079d75 100644
55064--- a/fs/cifs/smb2pdu.c
55065+++ b/fs/cifs/smb2pdu.c
55066@@ -1760,8 +1760,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
55067 default:
55068 cifs_dbg(VFS, "info level %u isn't supported\n",
55069 srch_inf->info_level);
55070- rc = -EINVAL;
55071- goto qdir_exit;
55072+ return -EINVAL;
55073 }
55074
55075 req->FileIndex = cpu_to_le32(index);
55076diff --git a/fs/coda/cache.c b/fs/coda/cache.c
55077index 1da168c..8bc7ff6 100644
55078--- a/fs/coda/cache.c
55079+++ b/fs/coda/cache.c
55080@@ -24,7 +24,7 @@
55081 #include "coda_linux.h"
55082 #include "coda_cache.h"
55083
55084-static atomic_t permission_epoch = ATOMIC_INIT(0);
55085+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
55086
55087 /* replace or extend an acl cache hit */
55088 void coda_cache_enter(struct inode *inode, int mask)
55089@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
55090 struct coda_inode_info *cii = ITOC(inode);
55091
55092 spin_lock(&cii->c_lock);
55093- cii->c_cached_epoch = atomic_read(&permission_epoch);
55094+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
55095 if (!uid_eq(cii->c_uid, current_fsuid())) {
55096 cii->c_uid = current_fsuid();
55097 cii->c_cached_perm = mask;
55098@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
55099 {
55100 struct coda_inode_info *cii = ITOC(inode);
55101 spin_lock(&cii->c_lock);
55102- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
55103+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
55104 spin_unlock(&cii->c_lock);
55105 }
55106
55107 /* remove all acl caches */
55108 void coda_cache_clear_all(struct super_block *sb)
55109 {
55110- atomic_inc(&permission_epoch);
55111+ atomic_inc_unchecked(&permission_epoch);
55112 }
55113
55114
55115@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
55116 spin_lock(&cii->c_lock);
55117 hit = (mask & cii->c_cached_perm) == mask &&
55118 uid_eq(cii->c_uid, current_fsuid()) &&
55119- cii->c_cached_epoch == atomic_read(&permission_epoch);
55120+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
55121 spin_unlock(&cii->c_lock);
55122
55123 return hit;
55124diff --git a/fs/compat.c b/fs/compat.c
55125index fc3b55d..7b568ae 100644
55126--- a/fs/compat.c
55127+++ b/fs/compat.c
55128@@ -54,7 +54,7 @@
55129 #include <asm/ioctls.h>
55130 #include "internal.h"
55131
55132-int compat_log = 1;
55133+int compat_log = 0;
55134
55135 int compat_printk(const char *fmt, ...)
55136 {
55137@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
55138
55139 set_fs(KERNEL_DS);
55140 /* The __user pointer cast is valid because of the set_fs() */
55141- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
55142+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
55143 set_fs(oldfs);
55144 /* truncating is ok because it's a user address */
55145 if (!ret)
55146@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
55147 goto out;
55148
55149 ret = -EINVAL;
55150- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
55151+ if (nr_segs > UIO_MAXIOV)
55152 goto out;
55153 if (nr_segs > fast_segs) {
55154 ret = -ENOMEM;
55155@@ -833,6 +833,7 @@ struct compat_old_linux_dirent {
55156
55157 struct compat_readdir_callback {
55158 struct compat_old_linux_dirent __user *dirent;
55159+ struct file * file;
55160 int result;
55161 };
55162
55163@@ -850,6 +851,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
55164 buf->result = -EOVERFLOW;
55165 return -EOVERFLOW;
55166 }
55167+
55168+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55169+ return 0;
55170+
55171 buf->result++;
55172 dirent = buf->dirent;
55173 if (!access_ok(VERIFY_WRITE, dirent,
55174@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
55175
55176 buf.result = 0;
55177 buf.dirent = dirent;
55178+ buf.file = f.file;
55179
55180 error = vfs_readdir(f.file, compat_fillonedir, &buf);
55181 if (buf.result)
55182@@ -899,6 +905,7 @@ struct compat_linux_dirent {
55183 struct compat_getdents_callback {
55184 struct compat_linux_dirent __user *current_dir;
55185 struct compat_linux_dirent __user *previous;
55186+ struct file * file;
55187 int count;
55188 int error;
55189 };
55190@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
55191 buf->error = -EOVERFLOW;
55192 return -EOVERFLOW;
55193 }
55194+
55195+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55196+ return 0;
55197+
55198 dirent = buf->previous;
55199 if (dirent) {
55200 if (__put_user(offset, &dirent->d_off))
55201@@ -965,6 +976,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
55202 buf.previous = NULL;
55203 buf.count = count;
55204 buf.error = 0;
55205+ buf.file = f.file;
55206
55207 error = vfs_readdir(f.file, compat_filldir, &buf);
55208 if (error >= 0)
55209@@ -985,6 +997,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
55210 struct compat_getdents_callback64 {
55211 struct linux_dirent64 __user *current_dir;
55212 struct linux_dirent64 __user *previous;
55213+ struct file * file;
55214 int count;
55215 int error;
55216 };
55217@@ -1001,6 +1014,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
55218 buf->error = -EINVAL; /* only used if we fail.. */
55219 if (reclen > buf->count)
55220 return -EINVAL;
55221+
55222+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55223+ return 0;
55224+
55225 dirent = buf->previous;
55226
55227 if (dirent) {
55228@@ -1050,13 +1067,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
55229 buf.previous = NULL;
55230 buf.count = count;
55231 buf.error = 0;
55232+ buf.file = f.file;
55233
55234 error = vfs_readdir(f.file, compat_filldir64, &buf);
55235 if (error >= 0)
55236 error = buf.error;
55237 lastdirent = buf.previous;
55238 if (lastdirent) {
55239- typeof(lastdirent->d_off) d_off = f.file->f_pos;
55240+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55241 if (__put_user_unaligned(d_off, &lastdirent->d_off))
55242 error = -EFAULT;
55243 else
55244diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
55245index a81147e..20bf2b5 100644
55246--- a/fs/compat_binfmt_elf.c
55247+++ b/fs/compat_binfmt_elf.c
55248@@ -30,11 +30,13 @@
55249 #undef elf_phdr
55250 #undef elf_shdr
55251 #undef elf_note
55252+#undef elf_dyn
55253 #undef elf_addr_t
55254 #define elfhdr elf32_hdr
55255 #define elf_phdr elf32_phdr
55256 #define elf_shdr elf32_shdr
55257 #define elf_note elf32_note
55258+#define elf_dyn Elf32_Dyn
55259 #define elf_addr_t Elf32_Addr
55260
55261 /*
55262diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
55263index 996cdc5..15e2f33 100644
55264--- a/fs/compat_ioctl.c
55265+++ b/fs/compat_ioctl.c
55266@@ -622,7 +622,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
55267 return -EFAULT;
55268 if (__get_user(udata, &ss32->iomem_base))
55269 return -EFAULT;
55270- ss.iomem_base = compat_ptr(udata);
55271+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
55272 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
55273 __get_user(ss.port_high, &ss32->port_high))
55274 return -EFAULT;
55275@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
55276 for (i = 0; i < nmsgs; i++) {
55277 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
55278 return -EFAULT;
55279- if (get_user(datap, &umsgs[i].buf) ||
55280- put_user(compat_ptr(datap), &tmsgs[i].buf))
55281+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
55282+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
55283 return -EFAULT;
55284 }
55285 return sys_ioctl(fd, cmd, (unsigned long)tdata);
55286@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
55287 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
55288 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
55289 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
55290- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
55291+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
55292 return -EFAULT;
55293
55294 return ioctl_preallocate(file, p);
55295@@ -1619,8 +1619,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
55296 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
55297 {
55298 unsigned int a, b;
55299- a = *(unsigned int *)p;
55300- b = *(unsigned int *)q;
55301+ a = *(const unsigned int *)p;
55302+ b = *(const unsigned int *)q;
55303 if (a > b)
55304 return 1;
55305 if (a < b)
55306diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
55307index 7aabc6a..34c1197 100644
55308--- a/fs/configfs/dir.c
55309+++ b/fs/configfs/dir.c
55310@@ -1565,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
55311 }
55312 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
55313 struct configfs_dirent *next;
55314- const char * name;
55315+ const unsigned char * name;
55316+ char d_name[sizeof(next->s_dentry->d_iname)];
55317 int len;
55318 struct inode *inode = NULL;
55319
55320@@ -1575,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
55321 continue;
55322
55323 name = configfs_get_name(next);
55324- len = strlen(name);
55325+ if (next->s_dentry && name == next->s_dentry->d_iname) {
55326+ len = next->s_dentry->d_name.len;
55327+ memcpy(d_name, name, len);
55328+ name = d_name;
55329+ } else
55330+ len = strlen(name);
55331
55332 /*
55333 * We'll have a dentry and an inode for
55334diff --git a/fs/coredump.c b/fs/coredump.c
55335index dafafba..10b3b27 100644
55336--- a/fs/coredump.c
55337+++ b/fs/coredump.c
55338@@ -52,7 +52,7 @@ struct core_name {
55339 char *corename;
55340 int used, size;
55341 };
55342-static atomic_t call_count = ATOMIC_INIT(1);
55343+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
55344
55345 /* The maximal length of core_pattern is also specified in sysctl.c */
55346
55347@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
55348 {
55349 char *old_corename = cn->corename;
55350
55351- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
55352+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
55353 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
55354
55355 if (!cn->corename) {
55356@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
55357 int pid_in_pattern = 0;
55358 int err = 0;
55359
55360- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
55361+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
55362 cn->corename = kmalloc(cn->size, GFP_KERNEL);
55363 cn->used = 0;
55364
55365@@ -435,8 +435,8 @@ static void wait_for_dump_helpers(struct file *file)
55366 struct pipe_inode_info *pipe = file->private_data;
55367
55368 pipe_lock(pipe);
55369- pipe->readers++;
55370- pipe->writers--;
55371+ atomic_inc(&pipe->readers);
55372+ atomic_dec(&pipe->writers);
55373 wake_up_interruptible_sync(&pipe->wait);
55374 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
55375 pipe_unlock(pipe);
55376@@ -445,11 +445,11 @@ static void wait_for_dump_helpers(struct file *file)
55377 * We actually want wait_event_freezable() but then we need
55378 * to clear TIF_SIGPENDING and improve dump_interrupted().
55379 */
55380- wait_event_interruptible(pipe->wait, pipe->readers == 1);
55381+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
55382
55383 pipe_lock(pipe);
55384- pipe->readers--;
55385- pipe->writers++;
55386+ atomic_dec(&pipe->readers);
55387+ atomic_inc(&pipe->writers);
55388 pipe_unlock(pipe);
55389 }
55390
55391@@ -496,7 +496,8 @@ void do_coredump(siginfo_t *siginfo)
55392 struct files_struct *displaced;
55393 bool need_nonrelative = false;
55394 bool core_dumped = false;
55395- static atomic_t core_dump_count = ATOMIC_INIT(0);
55396+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
55397+ long signr = siginfo->si_signo;
55398 struct coredump_params cprm = {
55399 .siginfo = siginfo,
55400 .regs = signal_pt_regs(),
55401@@ -509,7 +510,10 @@ void do_coredump(siginfo_t *siginfo)
55402 .mm_flags = mm->flags,
55403 };
55404
55405- audit_core_dumps(siginfo->si_signo);
55406+ audit_core_dumps(signr);
55407+
55408+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
55409+ gr_handle_brute_attach(cprm.mm_flags);
55410
55411 binfmt = mm->binfmt;
55412 if (!binfmt || !binfmt->core_dump)
55413@@ -533,7 +537,7 @@ void do_coredump(siginfo_t *siginfo)
55414 need_nonrelative = true;
55415 }
55416
55417- retval = coredump_wait(siginfo->si_signo, &core_state);
55418+ retval = coredump_wait(signr, &core_state);
55419 if (retval < 0)
55420 goto fail_creds;
55421
55422@@ -576,7 +580,7 @@ void do_coredump(siginfo_t *siginfo)
55423 }
55424 cprm.limit = RLIM_INFINITY;
55425
55426- dump_count = atomic_inc_return(&core_dump_count);
55427+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
55428 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
55429 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
55430 task_tgid_vnr(current), current->comm);
55431@@ -608,6 +612,8 @@ void do_coredump(siginfo_t *siginfo)
55432 } else {
55433 struct inode *inode;
55434
55435+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
55436+
55437 if (cprm.limit < binfmt->min_coredump)
55438 goto fail_unlock;
55439
55440@@ -666,7 +672,7 @@ close_fail:
55441 filp_close(cprm.file, NULL);
55442 fail_dropcount:
55443 if (ispipe)
55444- atomic_dec(&core_dump_count);
55445+ atomic_dec_unchecked(&core_dump_count);
55446 fail_unlock:
55447 kfree(cn.corename);
55448 fail_corename:
55449@@ -687,7 +693,7 @@ int dump_write(struct file *file, const void *addr, int nr)
55450 {
55451 return !dump_interrupted() &&
55452 access_ok(VERIFY_READ, addr, nr) &&
55453- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
55454+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
55455 }
55456 EXPORT_SYMBOL(dump_write);
55457
55458diff --git a/fs/dcache.c b/fs/dcache.c
55459index f09b908..04b9690 100644
55460--- a/fs/dcache.c
55461+++ b/fs/dcache.c
55462@@ -3086,7 +3086,8 @@ void __init vfs_caches_init(unsigned long mempages)
55463 mempages -= reserve;
55464
55465 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
55466- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
55467+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
55468+ SLAB_NO_SANITIZE, NULL);
55469
55470 dcache_init();
55471 inode_init();
55472diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
55473index c7c83ff..bda9461 100644
55474--- a/fs/debugfs/inode.c
55475+++ b/fs/debugfs/inode.c
55476@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
55477 */
55478 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
55479 {
55480+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55481+ return __create_file(name, S_IFDIR | S_IRWXU,
55482+#else
55483 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
55484+#endif
55485 parent, NULL, NULL);
55486 }
55487 EXPORT_SYMBOL_GPL(debugfs_create_dir);
55488diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
55489index 5eab400..810a3f5 100644
55490--- a/fs/ecryptfs/inode.c
55491+++ b/fs/ecryptfs/inode.c
55492@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
55493 old_fs = get_fs();
55494 set_fs(get_ds());
55495 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
55496- (char __user *)lower_buf,
55497+ (char __force_user *)lower_buf,
55498 PATH_MAX);
55499 set_fs(old_fs);
55500 if (rc < 0)
55501@@ -706,7 +706,7 @@ out:
55502 static void
55503 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
55504 {
55505- char *buf = nd_get_link(nd);
55506+ const char *buf = nd_get_link(nd);
55507 if (!IS_ERR(buf)) {
55508 /* Free the char* */
55509 kfree(buf);
55510diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
55511index e4141f2..d8263e8 100644
55512--- a/fs/ecryptfs/miscdev.c
55513+++ b/fs/ecryptfs/miscdev.c
55514@@ -304,7 +304,7 @@ check_list:
55515 goto out_unlock_msg_ctx;
55516 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
55517 if (msg_ctx->msg) {
55518- if (copy_to_user(&buf[i], packet_length, packet_length_size))
55519+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
55520 goto out_unlock_msg_ctx;
55521 i += packet_length_size;
55522 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
55523diff --git a/fs/exec.c b/fs/exec.c
55524index 1f44670..3c84660 100644
55525--- a/fs/exec.c
55526+++ b/fs/exec.c
55527@@ -55,8 +55,20 @@
55528 #include <linux/pipe_fs_i.h>
55529 #include <linux/oom.h>
55530 #include <linux/compat.h>
55531+#include <linux/random.h>
55532+#include <linux/seq_file.h>
55533+#include <linux/coredump.h>
55534+#include <linux/mman.h>
55535+
55536+#ifdef CONFIG_PAX_REFCOUNT
55537+#include <linux/kallsyms.h>
55538+#include <linux/kdebug.h>
55539+#endif
55540+
55541+#include <trace/events/fs.h>
55542
55543 #include <asm/uaccess.h>
55544+#include <asm/sections.h>
55545 #include <asm/mmu_context.h>
55546 #include <asm/tlb.h>
55547
55548@@ -66,17 +78,32 @@
55549
55550 #include <trace/events/sched.h>
55551
55552+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55553+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
55554+{
55555+ 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");
55556+}
55557+#endif
55558+
55559+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
55560+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
55561+EXPORT_SYMBOL(pax_set_initial_flags_func);
55562+#endif
55563+
55564 int suid_dumpable = 0;
55565
55566 static LIST_HEAD(formats);
55567 static DEFINE_RWLOCK(binfmt_lock);
55568
55569+extern int gr_process_kernel_exec_ban(void);
55570+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
55571+
55572 void __register_binfmt(struct linux_binfmt * fmt, int insert)
55573 {
55574 BUG_ON(!fmt);
55575 write_lock(&binfmt_lock);
55576- insert ? list_add(&fmt->lh, &formats) :
55577- list_add_tail(&fmt->lh, &formats);
55578+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
55579+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
55580 write_unlock(&binfmt_lock);
55581 }
55582
55583@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
55584 void unregister_binfmt(struct linux_binfmt * fmt)
55585 {
55586 write_lock(&binfmt_lock);
55587- list_del(&fmt->lh);
55588+ pax_list_del((struct list_head *)&fmt->lh);
55589 write_unlock(&binfmt_lock);
55590 }
55591
55592@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
55593 int write)
55594 {
55595 struct page *page;
55596- int ret;
55597
55598-#ifdef CONFIG_STACK_GROWSUP
55599- if (write) {
55600- ret = expand_downwards(bprm->vma, pos);
55601- if (ret < 0)
55602- return NULL;
55603- }
55604-#endif
55605- ret = get_user_pages(current, bprm->mm, pos,
55606- 1, write, 1, &page, NULL);
55607- if (ret <= 0)
55608+ if (0 > expand_downwards(bprm->vma, pos))
55609+ return NULL;
55610+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
55611 return NULL;
55612
55613 if (write) {
55614@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
55615 if (size <= ARG_MAX)
55616 return page;
55617
55618+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55619+ // only allow 512KB for argv+env on suid/sgid binaries
55620+ // to prevent easy ASLR exhaustion
55621+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
55622+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
55623+ (size > (512 * 1024))) {
55624+ put_page(page);
55625+ return NULL;
55626+ }
55627+#endif
55628+
55629 /*
55630 * Limit to 1/4-th the stack size for the argv+env strings.
55631 * This ensures that:
55632@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
55633 vma->vm_end = STACK_TOP_MAX;
55634 vma->vm_start = vma->vm_end - PAGE_SIZE;
55635 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
55636+
55637+#ifdef CONFIG_PAX_SEGMEXEC
55638+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
55639+#endif
55640+
55641 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
55642 INIT_LIST_HEAD(&vma->anon_vma_chain);
55643
55644@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
55645 mm->stack_vm = mm->total_vm = 1;
55646 up_write(&mm->mmap_sem);
55647 bprm->p = vma->vm_end - sizeof(void *);
55648+
55649+#ifdef CONFIG_PAX_RANDUSTACK
55650+ if (randomize_va_space)
55651+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
55652+#endif
55653+
55654 return 0;
55655 err:
55656 up_write(&mm->mmap_sem);
55657@@ -396,7 +437,7 @@ struct user_arg_ptr {
55658 } ptr;
55659 };
55660
55661-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55662+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55663 {
55664 const char __user *native;
55665
55666@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55667 compat_uptr_t compat;
55668
55669 if (get_user(compat, argv.ptr.compat + nr))
55670- return ERR_PTR(-EFAULT);
55671+ return (const char __force_user *)ERR_PTR(-EFAULT);
55672
55673 return compat_ptr(compat);
55674 }
55675 #endif
55676
55677 if (get_user(native, argv.ptr.native + nr))
55678- return ERR_PTR(-EFAULT);
55679+ return (const char __force_user *)ERR_PTR(-EFAULT);
55680
55681 return native;
55682 }
55683@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
55684 if (!p)
55685 break;
55686
55687- if (IS_ERR(p))
55688+ if (IS_ERR((const char __force_kernel *)p))
55689 return -EFAULT;
55690
55691 if (i >= max)
55692@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
55693
55694 ret = -EFAULT;
55695 str = get_user_arg_ptr(argv, argc);
55696- if (IS_ERR(str))
55697+ if (IS_ERR((const char __force_kernel *)str))
55698 goto out;
55699
55700 len = strnlen_user(str, MAX_ARG_STRLEN);
55701@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
55702 int r;
55703 mm_segment_t oldfs = get_fs();
55704 struct user_arg_ptr argv = {
55705- .ptr.native = (const char __user *const __user *)__argv,
55706+ .ptr.native = (const char __force_user * const __force_user *)__argv,
55707 };
55708
55709 set_fs(KERNEL_DS);
55710@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
55711 unsigned long new_end = old_end - shift;
55712 struct mmu_gather tlb;
55713
55714- BUG_ON(new_start > new_end);
55715+ if (new_start >= new_end || new_start < mmap_min_addr)
55716+ return -ENOMEM;
55717
55718 /*
55719 * ensure there are no vmas between where we want to go
55720@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
55721 if (vma != find_vma(mm, new_start))
55722 return -EFAULT;
55723
55724+#ifdef CONFIG_PAX_SEGMEXEC
55725+ BUG_ON(pax_find_mirror_vma(vma));
55726+#endif
55727+
55728 /*
55729 * cover the whole range: [new_start, old_end)
55730 */
55731@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
55732 stack_top = arch_align_stack(stack_top);
55733 stack_top = PAGE_ALIGN(stack_top);
55734
55735- if (unlikely(stack_top < mmap_min_addr) ||
55736- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
55737- return -ENOMEM;
55738-
55739 stack_shift = vma->vm_end - stack_top;
55740
55741 bprm->p -= stack_shift;
55742@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
55743 bprm->exec -= stack_shift;
55744
55745 down_write(&mm->mmap_sem);
55746+
55747+ /* Move stack pages down in memory. */
55748+ if (stack_shift) {
55749+ ret = shift_arg_pages(vma, stack_shift);
55750+ if (ret)
55751+ goto out_unlock;
55752+ }
55753+
55754 vm_flags = VM_STACK_FLAGS;
55755
55756+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55757+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55758+ vm_flags &= ~VM_EXEC;
55759+
55760+#ifdef CONFIG_PAX_MPROTECT
55761+ if (mm->pax_flags & MF_PAX_MPROTECT)
55762+ vm_flags &= ~VM_MAYEXEC;
55763+#endif
55764+
55765+ }
55766+#endif
55767+
55768 /*
55769 * Adjust stack execute permissions; explicitly enable for
55770 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
55771@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
55772 goto out_unlock;
55773 BUG_ON(prev != vma);
55774
55775- /* Move stack pages down in memory. */
55776- if (stack_shift) {
55777- ret = shift_arg_pages(vma, stack_shift);
55778- if (ret)
55779- goto out_unlock;
55780- }
55781-
55782 /* mprotect_fixup is overkill to remove the temporary stack flags */
55783 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
55784
55785@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
55786 #endif
55787 current->mm->start_stack = bprm->p;
55788 ret = expand_stack(vma, stack_base);
55789+
55790+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
55791+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
55792+ unsigned long size;
55793+ vm_flags_t vm_flags;
55794+
55795+ size = STACK_TOP - vma->vm_end;
55796+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
55797+
55798+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
55799+
55800+#ifdef CONFIG_X86
55801+ if (!ret) {
55802+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
55803+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
55804+ }
55805+#endif
55806+
55807+ }
55808+#endif
55809+
55810 if (ret)
55811 ret = -EFAULT;
55812
55813@@ -772,6 +848,8 @@ struct file *open_exec(const char *name)
55814
55815 fsnotify_open(file);
55816
55817+ trace_open_exec(name);
55818+
55819 err = deny_write_access(file);
55820 if (err)
55821 goto exit;
55822@@ -795,7 +873,7 @@ int kernel_read(struct file *file, loff_t offset,
55823 old_fs = get_fs();
55824 set_fs(get_ds());
55825 /* The cast to a user pointer is valid due to the set_fs() */
55826- result = vfs_read(file, (void __user *)addr, count, &pos);
55827+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
55828 set_fs(old_fs);
55829 return result;
55830 }
55831@@ -1251,7 +1329,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
55832 }
55833 rcu_read_unlock();
55834
55835- if (p->fs->users > n_fs) {
55836+ if (atomic_read(&p->fs->users) > n_fs) {
55837 bprm->unsafe |= LSM_UNSAFE_SHARE;
55838 } else {
55839 res = -EAGAIN;
55840@@ -1451,6 +1529,31 @@ int search_binary_handler(struct linux_binprm *bprm)
55841
55842 EXPORT_SYMBOL(search_binary_handler);
55843
55844+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55845+static DEFINE_PER_CPU(u64, exec_counter);
55846+static int __init init_exec_counters(void)
55847+{
55848+ unsigned int cpu;
55849+
55850+ for_each_possible_cpu(cpu) {
55851+ per_cpu(exec_counter, cpu) = (u64)cpu;
55852+ }
55853+
55854+ return 0;
55855+}
55856+early_initcall(init_exec_counters);
55857+static inline void increment_exec_counter(void)
55858+{
55859+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
55860+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
55861+}
55862+#else
55863+static inline void increment_exec_counter(void) {}
55864+#endif
55865+
55866+extern void gr_handle_exec_args(struct linux_binprm *bprm,
55867+ struct user_arg_ptr argv);
55868+
55869 /*
55870 * sys_execve() executes a new program.
55871 */
55872@@ -1458,6 +1561,11 @@ static int do_execve_common(const char *filename,
55873 struct user_arg_ptr argv,
55874 struct user_arg_ptr envp)
55875 {
55876+#ifdef CONFIG_GRKERNSEC
55877+ struct file *old_exec_file;
55878+ struct acl_subject_label *old_acl;
55879+ struct rlimit old_rlim[RLIM_NLIMITS];
55880+#endif
55881 struct linux_binprm *bprm;
55882 struct file *file;
55883 struct files_struct *displaced;
55884@@ -1465,6 +1573,8 @@ static int do_execve_common(const char *filename,
55885 int retval;
55886 const struct cred *cred = current_cred();
55887
55888+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&cred->user->processes), 1);
55889+
55890 /*
55891 * We move the actual failure in case of RLIMIT_NPROC excess from
55892 * set*uid() to execve() because too many poorly written programs
55893@@ -1505,12 +1615,22 @@ static int do_execve_common(const char *filename,
55894 if (IS_ERR(file))
55895 goto out_unmark;
55896
55897+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
55898+ retval = -EPERM;
55899+ goto out_file;
55900+ }
55901+
55902 sched_exec();
55903
55904 bprm->file = file;
55905 bprm->filename = filename;
55906 bprm->interp = filename;
55907
55908+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
55909+ retval = -EACCES;
55910+ goto out_file;
55911+ }
55912+
55913 retval = bprm_mm_init(bprm);
55914 if (retval)
55915 goto out_file;
55916@@ -1527,24 +1647,70 @@ static int do_execve_common(const char *filename,
55917 if (retval < 0)
55918 goto out;
55919
55920+#ifdef CONFIG_GRKERNSEC
55921+ old_acl = current->acl;
55922+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
55923+ old_exec_file = current->exec_file;
55924+ get_file(file);
55925+ current->exec_file = file;
55926+#endif
55927+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55928+ /* limit suid stack to 8MB
55929+ * we saved the old limits above and will restore them if this exec fails
55930+ */
55931+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
55932+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
55933+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
55934+#endif
55935+
55936+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
55937+ retval = -EPERM;
55938+ goto out_fail;
55939+ }
55940+
55941+ if (!gr_tpe_allow(file)) {
55942+ retval = -EACCES;
55943+ goto out_fail;
55944+ }
55945+
55946+ if (gr_check_crash_exec(file)) {
55947+ retval = -EACCES;
55948+ goto out_fail;
55949+ }
55950+
55951+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
55952+ bprm->unsafe);
55953+ if (retval < 0)
55954+ goto out_fail;
55955+
55956 retval = copy_strings_kernel(1, &bprm->filename, bprm);
55957 if (retval < 0)
55958- goto out;
55959+ goto out_fail;
55960
55961 bprm->exec = bprm->p;
55962 retval = copy_strings(bprm->envc, envp, bprm);
55963 if (retval < 0)
55964- goto out;
55965+ goto out_fail;
55966
55967 retval = copy_strings(bprm->argc, argv, bprm);
55968 if (retval < 0)
55969- goto out;
55970+ goto out_fail;
55971+
55972+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
55973+
55974+ gr_handle_exec_args(bprm, argv);
55975
55976 retval = search_binary_handler(bprm);
55977 if (retval < 0)
55978- goto out;
55979+ goto out_fail;
55980+#ifdef CONFIG_GRKERNSEC
55981+ if (old_exec_file)
55982+ fput(old_exec_file);
55983+#endif
55984
55985 /* execve succeeded */
55986+
55987+ increment_exec_counter();
55988 current->fs->in_exec = 0;
55989 current->in_execve = 0;
55990 acct_update_integrals(current);
55991@@ -1553,6 +1719,14 @@ static int do_execve_common(const char *filename,
55992 put_files_struct(displaced);
55993 return retval;
55994
55995+out_fail:
55996+#ifdef CONFIG_GRKERNSEC
55997+ current->acl = old_acl;
55998+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
55999+ fput(current->exec_file);
56000+ current->exec_file = old_exec_file;
56001+#endif
56002+
56003 out:
56004 if (bprm->mm) {
56005 acct_arg_size(bprm, 0);
56006@@ -1701,3 +1875,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
56007 return error;
56008 }
56009 #endif
56010+
56011+int pax_check_flags(unsigned long *flags)
56012+{
56013+ int retval = 0;
56014+
56015+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
56016+ if (*flags & MF_PAX_SEGMEXEC)
56017+ {
56018+ *flags &= ~MF_PAX_SEGMEXEC;
56019+ retval = -EINVAL;
56020+ }
56021+#endif
56022+
56023+ if ((*flags & MF_PAX_PAGEEXEC)
56024+
56025+#ifdef CONFIG_PAX_PAGEEXEC
56026+ && (*flags & MF_PAX_SEGMEXEC)
56027+#endif
56028+
56029+ )
56030+ {
56031+ *flags &= ~MF_PAX_PAGEEXEC;
56032+ retval = -EINVAL;
56033+ }
56034+
56035+ if ((*flags & MF_PAX_MPROTECT)
56036+
56037+#ifdef CONFIG_PAX_MPROTECT
56038+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
56039+#endif
56040+
56041+ )
56042+ {
56043+ *flags &= ~MF_PAX_MPROTECT;
56044+ retval = -EINVAL;
56045+ }
56046+
56047+ if ((*flags & MF_PAX_EMUTRAMP)
56048+
56049+#ifdef CONFIG_PAX_EMUTRAMP
56050+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
56051+#endif
56052+
56053+ )
56054+ {
56055+ *flags &= ~MF_PAX_EMUTRAMP;
56056+ retval = -EINVAL;
56057+ }
56058+
56059+ return retval;
56060+}
56061+
56062+EXPORT_SYMBOL(pax_check_flags);
56063+
56064+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56065+char *pax_get_path(const struct path *path, char *buf, int buflen)
56066+{
56067+ char *pathname = d_path(path, buf, buflen);
56068+
56069+ if (IS_ERR(pathname))
56070+ goto toolong;
56071+
56072+ pathname = mangle_path(buf, pathname, "\t\n\\");
56073+ if (!pathname)
56074+ goto toolong;
56075+
56076+ *pathname = 0;
56077+ return buf;
56078+
56079+toolong:
56080+ return "<path too long>";
56081+}
56082+EXPORT_SYMBOL(pax_get_path);
56083+
56084+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
56085+{
56086+ struct task_struct *tsk = current;
56087+ struct mm_struct *mm = current->mm;
56088+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
56089+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
56090+ char *path_exec = NULL;
56091+ char *path_fault = NULL;
56092+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
56093+ siginfo_t info = { };
56094+
56095+ if (buffer_exec && buffer_fault) {
56096+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
56097+
56098+ down_read(&mm->mmap_sem);
56099+ vma = mm->mmap;
56100+ while (vma && (!vma_exec || !vma_fault)) {
56101+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
56102+ vma_exec = vma;
56103+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
56104+ vma_fault = vma;
56105+ vma = vma->vm_next;
56106+ }
56107+ if (vma_exec)
56108+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
56109+ if (vma_fault) {
56110+ start = vma_fault->vm_start;
56111+ end = vma_fault->vm_end;
56112+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
56113+ if (vma_fault->vm_file)
56114+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
56115+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
56116+ path_fault = "<heap>";
56117+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
56118+ path_fault = "<stack>";
56119+ else
56120+ path_fault = "<anonymous mapping>";
56121+ }
56122+ up_read(&mm->mmap_sem);
56123+ }
56124+ if (tsk->signal->curr_ip)
56125+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
56126+ else
56127+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
56128+ 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),
56129+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
56130+ free_page((unsigned long)buffer_exec);
56131+ free_page((unsigned long)buffer_fault);
56132+ pax_report_insns(regs, pc, sp);
56133+ info.si_signo = SIGKILL;
56134+ info.si_errno = 0;
56135+ info.si_code = SI_KERNEL;
56136+ info.si_pid = 0;
56137+ info.si_uid = 0;
56138+ do_coredump(&info);
56139+}
56140+#endif
56141+
56142+#ifdef CONFIG_PAX_REFCOUNT
56143+void pax_report_refcount_overflow(struct pt_regs *regs)
56144+{
56145+ if (current->signal->curr_ip)
56146+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
56147+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
56148+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
56149+ else
56150+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
56151+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
56152+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
56153+ preempt_disable();
56154+ show_regs(regs);
56155+ preempt_enable();
56156+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
56157+}
56158+#endif
56159+
56160+#ifdef CONFIG_PAX_USERCOPY
56161+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
56162+static noinline int check_stack_object(const void *obj, unsigned long len)
56163+{
56164+ const void * const stack = task_stack_page(current);
56165+ const void * const stackend = stack + THREAD_SIZE;
56166+
56167+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
56168+ const void *frame = NULL;
56169+ const void *oldframe;
56170+#endif
56171+
56172+ if (obj + len < obj)
56173+ return -1;
56174+
56175+ if (obj + len <= stack || stackend <= obj)
56176+ return 0;
56177+
56178+ if (obj < stack || stackend < obj + len)
56179+ return -1;
56180+
56181+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
56182+ oldframe = __builtin_frame_address(1);
56183+ if (oldframe)
56184+ frame = __builtin_frame_address(2);
56185+ /*
56186+ low ----------------------------------------------> high
56187+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
56188+ ^----------------^
56189+ allow copies only within here
56190+ */
56191+ while (stack <= frame && frame < stackend) {
56192+ /* if obj + len extends past the last frame, this
56193+ check won't pass and the next frame will be 0,
56194+ causing us to bail out and correctly report
56195+ the copy as invalid
56196+ */
56197+ if (obj + len <= frame)
56198+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
56199+ oldframe = frame;
56200+ frame = *(const void * const *)frame;
56201+ }
56202+ return -1;
56203+#else
56204+ return 1;
56205+#endif
56206+}
56207+
56208+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
56209+{
56210+ if (current->signal->curr_ip)
56211+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
56212+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
56213+ else
56214+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
56215+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
56216+ dump_stack();
56217+ gr_handle_kernel_exploit();
56218+ do_group_exit(SIGKILL);
56219+}
56220+#endif
56221+
56222+#ifdef CONFIG_PAX_USERCOPY
56223+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
56224+{
56225+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
56226+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
56227+#ifdef CONFIG_MODULES
56228+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
56229+#else
56230+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
56231+#endif
56232+
56233+#else
56234+ unsigned long textlow = (unsigned long)_stext;
56235+ unsigned long texthigh = (unsigned long)_etext;
56236+#endif
56237+
56238+ if (high <= textlow || low > texthigh)
56239+ return false;
56240+ else
56241+ return true;
56242+}
56243+#endif
56244+
56245+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
56246+{
56247+
56248+#ifdef CONFIG_PAX_USERCOPY
56249+ const char *type;
56250+
56251+ if (!n)
56252+ return;
56253+
56254+ type = check_heap_object(ptr, n);
56255+ if (!type) {
56256+ int ret = check_stack_object(ptr, n);
56257+ if (ret == 1 || ret == 2)
56258+ return;
56259+ if (ret == 0) {
56260+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
56261+ type = "<kernel text>";
56262+ else
56263+ return;
56264+ } else
56265+ type = "<process stack>";
56266+ }
56267+
56268+ pax_report_usercopy(ptr, n, to_user, type);
56269+#endif
56270+
56271+}
56272+EXPORT_SYMBOL(__check_object_size);
56273+
56274+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
56275+void pax_track_stack(void)
56276+{
56277+ unsigned long sp = (unsigned long)&sp;
56278+ if (sp < current_thread_info()->lowest_stack &&
56279+ sp > (unsigned long)task_stack_page(current))
56280+ current_thread_info()->lowest_stack = sp;
56281+}
56282+EXPORT_SYMBOL(pax_track_stack);
56283+#endif
56284+
56285+#ifdef CONFIG_PAX_SIZE_OVERFLOW
56286+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
56287+{
56288+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
56289+ dump_stack();
56290+ do_group_exit(SIGKILL);
56291+}
56292+EXPORT_SYMBOL(report_size_overflow);
56293+#endif
56294diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
56295index 9f9992b..8b59411 100644
56296--- a/fs/ext2/balloc.c
56297+++ b/fs/ext2/balloc.c
56298@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
56299
56300 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
56301 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
56302- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
56303+ if (free_blocks < root_blocks + 1 &&
56304 !uid_eq(sbi->s_resuid, current_fsuid()) &&
56305 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
56306- !in_group_p (sbi->s_resgid))) {
56307+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
56308 return 0;
56309 }
56310 return 1;
56311diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
56312index 22548f5..41521d8 100644
56313--- a/fs/ext3/balloc.c
56314+++ b/fs/ext3/balloc.c
56315@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
56316
56317 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
56318 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
56319- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
56320+ if (free_blocks < root_blocks + 1 &&
56321 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
56322 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
56323- !in_group_p (sbi->s_resgid))) {
56324+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
56325 return 0;
56326 }
56327 return 1;
56328diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
56329index 3742e4c..69a797f 100644
56330--- a/fs/ext4/balloc.c
56331+++ b/fs/ext4/balloc.c
56332@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
56333 /* Hm, nope. Are (enough) root reserved clusters available? */
56334 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
56335 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
56336- capable(CAP_SYS_RESOURCE) ||
56337- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
56338+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
56339+ capable_nolog(CAP_SYS_RESOURCE)) {
56340
56341 if (free_clusters >= (nclusters + dirty_clusters +
56342 resv_clusters))
56343diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
56344index 5aae3d1..b5da7f8 100644
56345--- a/fs/ext4/ext4.h
56346+++ b/fs/ext4/ext4.h
56347@@ -1252,19 +1252,19 @@ struct ext4_sb_info {
56348 unsigned long s_mb_last_start;
56349
56350 /* stats for buddy allocator */
56351- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
56352- atomic_t s_bal_success; /* we found long enough chunks */
56353- atomic_t s_bal_allocated; /* in blocks */
56354- atomic_t s_bal_ex_scanned; /* total extents scanned */
56355- atomic_t s_bal_goals; /* goal hits */
56356- atomic_t s_bal_breaks; /* too long searches */
56357- atomic_t s_bal_2orders; /* 2^order hits */
56358+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
56359+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
56360+ atomic_unchecked_t s_bal_allocated; /* in blocks */
56361+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
56362+ atomic_unchecked_t s_bal_goals; /* goal hits */
56363+ atomic_unchecked_t s_bal_breaks; /* too long searches */
56364+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
56365 spinlock_t s_bal_lock;
56366 unsigned long s_mb_buddies_generated;
56367 unsigned long long s_mb_generation_time;
56368- atomic_t s_mb_lost_chunks;
56369- atomic_t s_mb_preallocated;
56370- atomic_t s_mb_discarded;
56371+ atomic_unchecked_t s_mb_lost_chunks;
56372+ atomic_unchecked_t s_mb_preallocated;
56373+ atomic_unchecked_t s_mb_discarded;
56374 atomic_t s_lock_busy;
56375
56376 /* locality groups */
56377diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
56378index 59c6750..a549154 100644
56379--- a/fs/ext4/mballoc.c
56380+++ b/fs/ext4/mballoc.c
56381@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
56382 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
56383
56384 if (EXT4_SB(sb)->s_mb_stats)
56385- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
56386+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
56387
56388 break;
56389 }
56390@@ -2170,7 +2170,7 @@ repeat:
56391 ac->ac_status = AC_STATUS_CONTINUE;
56392 ac->ac_flags |= EXT4_MB_HINT_FIRST;
56393 cr = 3;
56394- atomic_inc(&sbi->s_mb_lost_chunks);
56395+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
56396 goto repeat;
56397 }
56398 }
56399@@ -2678,25 +2678,25 @@ int ext4_mb_release(struct super_block *sb)
56400 if (sbi->s_mb_stats) {
56401 ext4_msg(sb, KERN_INFO,
56402 "mballoc: %u blocks %u reqs (%u success)",
56403- atomic_read(&sbi->s_bal_allocated),
56404- atomic_read(&sbi->s_bal_reqs),
56405- atomic_read(&sbi->s_bal_success));
56406+ atomic_read_unchecked(&sbi->s_bal_allocated),
56407+ atomic_read_unchecked(&sbi->s_bal_reqs),
56408+ atomic_read_unchecked(&sbi->s_bal_success));
56409 ext4_msg(sb, KERN_INFO,
56410 "mballoc: %u extents scanned, %u goal hits, "
56411 "%u 2^N hits, %u breaks, %u lost",
56412- atomic_read(&sbi->s_bal_ex_scanned),
56413- atomic_read(&sbi->s_bal_goals),
56414- atomic_read(&sbi->s_bal_2orders),
56415- atomic_read(&sbi->s_bal_breaks),
56416- atomic_read(&sbi->s_mb_lost_chunks));
56417+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
56418+ atomic_read_unchecked(&sbi->s_bal_goals),
56419+ atomic_read_unchecked(&sbi->s_bal_2orders),
56420+ atomic_read_unchecked(&sbi->s_bal_breaks),
56421+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
56422 ext4_msg(sb, KERN_INFO,
56423 "mballoc: %lu generated and it took %Lu",
56424 sbi->s_mb_buddies_generated,
56425 sbi->s_mb_generation_time);
56426 ext4_msg(sb, KERN_INFO,
56427 "mballoc: %u preallocated, %u discarded",
56428- atomic_read(&sbi->s_mb_preallocated),
56429- atomic_read(&sbi->s_mb_discarded));
56430+ atomic_read_unchecked(&sbi->s_mb_preallocated),
56431+ atomic_read_unchecked(&sbi->s_mb_discarded));
56432 }
56433
56434 free_percpu(sbi->s_locality_groups);
56435@@ -3150,16 +3150,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
56436 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
56437
56438 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
56439- atomic_inc(&sbi->s_bal_reqs);
56440- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
56441+ atomic_inc_unchecked(&sbi->s_bal_reqs);
56442+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
56443 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
56444- atomic_inc(&sbi->s_bal_success);
56445- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
56446+ atomic_inc_unchecked(&sbi->s_bal_success);
56447+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
56448 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
56449 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
56450- atomic_inc(&sbi->s_bal_goals);
56451+ atomic_inc_unchecked(&sbi->s_bal_goals);
56452 if (ac->ac_found > sbi->s_mb_max_to_scan)
56453- atomic_inc(&sbi->s_bal_breaks);
56454+ atomic_inc_unchecked(&sbi->s_bal_breaks);
56455 }
56456
56457 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
56458@@ -3559,7 +3559,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
56459 trace_ext4_mb_new_inode_pa(ac, pa);
56460
56461 ext4_mb_use_inode_pa(ac, pa);
56462- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
56463+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
56464
56465 ei = EXT4_I(ac->ac_inode);
56466 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
56467@@ -3619,7 +3619,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
56468 trace_ext4_mb_new_group_pa(ac, pa);
56469
56470 ext4_mb_use_group_pa(ac, pa);
56471- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
56472+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
56473
56474 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
56475 lg = ac->ac_lg;
56476@@ -3708,7 +3708,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
56477 * from the bitmap and continue.
56478 */
56479 }
56480- atomic_add(free, &sbi->s_mb_discarded);
56481+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
56482
56483 return err;
56484 }
56485@@ -3726,7 +3726,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
56486 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
56487 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
56488 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
56489- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
56490+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
56491 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
56492
56493 return 0;
56494diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
56495index 214461e..3614c89 100644
56496--- a/fs/ext4/mmp.c
56497+++ b/fs/ext4/mmp.c
56498@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
56499 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
56500 const char *function, unsigned int line, const char *msg)
56501 {
56502- __ext4_warning(sb, function, line, msg);
56503+ __ext4_warning(sb, function, line, "%s", msg);
56504 __ext4_warning(sb, function, line,
56505 "MMP failure info: last update time: %llu, last update "
56506 "node: %s, last update device: %s\n",
56507diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
56508index 49d3c01..9579efd 100644
56509--- a/fs/ext4/resize.c
56510+++ b/fs/ext4/resize.c
56511@@ -79,12 +79,20 @@ static int verify_group_input(struct super_block *sb,
56512 ext4_fsblk_t end = start + input->blocks_count;
56513 ext4_group_t group = input->group;
56514 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
56515- unsigned overhead = ext4_group_overhead_blocks(sb, group);
56516- ext4_fsblk_t metaend = start + overhead;
56517+ unsigned overhead;
56518+ ext4_fsblk_t metaend;
56519 struct buffer_head *bh = NULL;
56520 ext4_grpblk_t free_blocks_count, offset;
56521 int err = -EINVAL;
56522
56523+ if (group != sbi->s_groups_count) {
56524+ ext4_warning(sb, "Cannot add at group %u (only %u groups)",
56525+ input->group, sbi->s_groups_count);
56526+ return -EINVAL;
56527+ }
56528+
56529+ overhead = ext4_group_overhead_blocks(sb, group);
56530+ metaend = start + overhead;
56531 input->free_blocks_count = free_blocks_count =
56532 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
56533
56534@@ -96,10 +104,7 @@ static int verify_group_input(struct super_block *sb,
56535 free_blocks_count, input->reserved_blocks);
56536
56537 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
56538- if (group != sbi->s_groups_count)
56539- ext4_warning(sb, "Cannot add at group %u (only %u groups)",
56540- input->group, sbi->s_groups_count);
56541- else if (offset != 0)
56542+ if (offset != 0)
56543 ext4_warning(sb, "Last group not full");
56544 else if (input->reserved_blocks > input->blocks_count / 5)
56545 ext4_warning(sb, "Reserved blocks too high (%u)",
56546diff --git a/fs/ext4/super.c b/fs/ext4/super.c
56547index 3f7c39e..227f24f 100644
56548--- a/fs/ext4/super.c
56549+++ b/fs/ext4/super.c
56550@@ -1236,7 +1236,7 @@ static ext4_fsblk_t get_sb_block(void **data)
56551 }
56552
56553 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
56554-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
56555+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
56556 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
56557
56558 #ifdef CONFIG_QUOTA
56559@@ -2372,7 +2372,7 @@ struct ext4_attr {
56560 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
56561 const char *, size_t);
56562 int offset;
56563-};
56564+} __do_const;
56565
56566 static int parse_strtoull(const char *buf,
56567 unsigned long long max, unsigned long long *value)
56568diff --git a/fs/fcntl.c b/fs/fcntl.c
56569index 6599222..e7bf0de 100644
56570--- a/fs/fcntl.c
56571+++ b/fs/fcntl.c
56572@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
56573 if (err)
56574 return err;
56575
56576+ if (gr_handle_chroot_fowner(pid, type))
56577+ return -ENOENT;
56578+ if (gr_check_protected_task_fowner(pid, type))
56579+ return -EACCES;
56580+
56581 f_modown(filp, pid, type, force);
56582 return 0;
56583 }
56584diff --git a/fs/fhandle.c b/fs/fhandle.c
56585index 999ff5c..41f4109 100644
56586--- a/fs/fhandle.c
56587+++ b/fs/fhandle.c
56588@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
56589 } else
56590 retval = 0;
56591 /* copy the mount id */
56592- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
56593- sizeof(*mnt_id)) ||
56594+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
56595 copy_to_user(ufh, handle,
56596 sizeof(struct file_handle) + handle_bytes))
56597 retval = -EFAULT;
56598diff --git a/fs/file.c b/fs/file.c
56599index 4a78f98..9447397 100644
56600--- a/fs/file.c
56601+++ b/fs/file.c
56602@@ -16,6 +16,7 @@
56603 #include <linux/slab.h>
56604 #include <linux/vmalloc.h>
56605 #include <linux/file.h>
56606+#include <linux/security.h>
56607 #include <linux/fdtable.h>
56608 #include <linux/bitops.h>
56609 #include <linux/interrupt.h>
56610@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
56611 if (!file)
56612 return __close_fd(files, fd);
56613
56614+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
56615 if (fd >= rlimit(RLIMIT_NOFILE))
56616 return -EBADF;
56617
56618@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
56619 if (unlikely(oldfd == newfd))
56620 return -EINVAL;
56621
56622+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
56623 if (newfd >= rlimit(RLIMIT_NOFILE))
56624 return -EBADF;
56625
56626@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
56627 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
56628 {
56629 int err;
56630+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
56631 if (from >= rlimit(RLIMIT_NOFILE))
56632 return -EINVAL;
56633 err = alloc_fd(from, flags);
56634diff --git a/fs/filesystems.c b/fs/filesystems.c
56635index 92567d9..fcd8cbf 100644
56636--- a/fs/filesystems.c
56637+++ b/fs/filesystems.c
56638@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
56639 int len = dot ? dot - name : strlen(name);
56640
56641 fs = __get_fs_type(name, len);
56642+#ifdef CONFIG_GRKERNSEC_MODHARDEN
56643+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
56644+#else
56645 if (!fs && (request_module("fs-%.*s", len, name) == 0))
56646+#endif
56647 fs = __get_fs_type(name, len);
56648
56649 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
56650diff --git a/fs/fs_struct.c b/fs/fs_struct.c
56651index d8ac61d..79a36f0 100644
56652--- a/fs/fs_struct.c
56653+++ b/fs/fs_struct.c
56654@@ -4,6 +4,7 @@
56655 #include <linux/path.h>
56656 #include <linux/slab.h>
56657 #include <linux/fs_struct.h>
56658+#include <linux/grsecurity.h>
56659 #include "internal.h"
56660
56661 /*
56662@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
56663 write_seqcount_begin(&fs->seq);
56664 old_root = fs->root;
56665 fs->root = *path;
56666+ gr_set_chroot_entries(current, path);
56667 write_seqcount_end(&fs->seq);
56668 spin_unlock(&fs->lock);
56669 if (old_root.dentry)
56670@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
56671 int hits = 0;
56672 spin_lock(&fs->lock);
56673 write_seqcount_begin(&fs->seq);
56674+ /* this root replacement is only done by pivot_root,
56675+ leave grsec's chroot tagging alone for this task
56676+ so that a pivoted root isn't treated as a chroot
56677+ */
56678 hits += replace_path(&fs->root, old_root, new_root);
56679 hits += replace_path(&fs->pwd, old_root, new_root);
56680 write_seqcount_end(&fs->seq);
56681@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
56682 task_lock(tsk);
56683 spin_lock(&fs->lock);
56684 tsk->fs = NULL;
56685- kill = !--fs->users;
56686+ gr_clear_chroot_entries(tsk);
56687+ kill = !atomic_dec_return(&fs->users);
56688 spin_unlock(&fs->lock);
56689 task_unlock(tsk);
56690 if (kill)
56691@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
56692 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
56693 /* We don't need to lock fs - think why ;-) */
56694 if (fs) {
56695- fs->users = 1;
56696+ atomic_set(&fs->users, 1);
56697 fs->in_exec = 0;
56698 spin_lock_init(&fs->lock);
56699 seqcount_init(&fs->seq);
56700@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
56701 spin_lock(&old->lock);
56702 fs->root = old->root;
56703 path_get(&fs->root);
56704+ /* instead of calling gr_set_chroot_entries here,
56705+ we call it from every caller of this function
56706+ */
56707 fs->pwd = old->pwd;
56708 path_get(&fs->pwd);
56709 spin_unlock(&old->lock);
56710@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
56711
56712 task_lock(current);
56713 spin_lock(&fs->lock);
56714- kill = !--fs->users;
56715+ kill = !atomic_dec_return(&fs->users);
56716 current->fs = new_fs;
56717+ gr_set_chroot_entries(current, &new_fs->root);
56718 spin_unlock(&fs->lock);
56719 task_unlock(current);
56720
56721@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
56722
56723 int current_umask(void)
56724 {
56725- return current->fs->umask;
56726+ return current->fs->umask | gr_acl_umask();
56727 }
56728 EXPORT_SYMBOL(current_umask);
56729
56730 /* to be mentioned only in INIT_TASK */
56731 struct fs_struct init_fs = {
56732- .users = 1,
56733+ .users = ATOMIC_INIT(1),
56734 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
56735 .seq = SEQCNT_ZERO,
56736 .umask = 0022,
56737diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
56738index e2cba1f..20319c5 100644
56739--- a/fs/fscache/cookie.c
56740+++ b/fs/fscache/cookie.c
56741@@ -19,7 +19,7 @@
56742
56743 struct kmem_cache *fscache_cookie_jar;
56744
56745-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
56746+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
56747
56748 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
56749 static int fscache_alloc_object(struct fscache_cache *cache,
56750@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
56751 parent ? (char *) parent->def->name : "<no-parent>",
56752 def->name, netfs_data);
56753
56754- fscache_stat(&fscache_n_acquires);
56755+ fscache_stat_unchecked(&fscache_n_acquires);
56756
56757 /* if there's no parent cookie, then we don't create one here either */
56758 if (!parent) {
56759- fscache_stat(&fscache_n_acquires_null);
56760+ fscache_stat_unchecked(&fscache_n_acquires_null);
56761 _leave(" [no parent]");
56762 return NULL;
56763 }
56764@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
56765 /* allocate and initialise a cookie */
56766 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
56767 if (!cookie) {
56768- fscache_stat(&fscache_n_acquires_oom);
56769+ fscache_stat_unchecked(&fscache_n_acquires_oom);
56770 _leave(" [ENOMEM]");
56771 return NULL;
56772 }
56773@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
56774
56775 switch (cookie->def->type) {
56776 case FSCACHE_COOKIE_TYPE_INDEX:
56777- fscache_stat(&fscache_n_cookie_index);
56778+ fscache_stat_unchecked(&fscache_n_cookie_index);
56779 break;
56780 case FSCACHE_COOKIE_TYPE_DATAFILE:
56781- fscache_stat(&fscache_n_cookie_data);
56782+ fscache_stat_unchecked(&fscache_n_cookie_data);
56783 break;
56784 default:
56785- fscache_stat(&fscache_n_cookie_special);
56786+ fscache_stat_unchecked(&fscache_n_cookie_special);
56787 break;
56788 }
56789
56790@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
56791 if (fscache_acquire_non_index_cookie(cookie) < 0) {
56792 atomic_dec(&parent->n_children);
56793 __fscache_cookie_put(cookie);
56794- fscache_stat(&fscache_n_acquires_nobufs);
56795+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
56796 _leave(" = NULL");
56797 return NULL;
56798 }
56799 }
56800
56801- fscache_stat(&fscache_n_acquires_ok);
56802+ fscache_stat_unchecked(&fscache_n_acquires_ok);
56803 _leave(" = %p", cookie);
56804 return cookie;
56805 }
56806@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
56807 cache = fscache_select_cache_for_object(cookie->parent);
56808 if (!cache) {
56809 up_read(&fscache_addremove_sem);
56810- fscache_stat(&fscache_n_acquires_no_cache);
56811+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
56812 _leave(" = -ENOMEDIUM [no cache]");
56813 return -ENOMEDIUM;
56814 }
56815@@ -255,14 +255,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
56816 object = cache->ops->alloc_object(cache, cookie);
56817 fscache_stat_d(&fscache_n_cop_alloc_object);
56818 if (IS_ERR(object)) {
56819- fscache_stat(&fscache_n_object_no_alloc);
56820+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
56821 ret = PTR_ERR(object);
56822 goto error;
56823 }
56824
56825- fscache_stat(&fscache_n_object_alloc);
56826+ fscache_stat_unchecked(&fscache_n_object_alloc);
56827
56828- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
56829+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
56830
56831 _debug("ALLOC OBJ%x: %s {%lx}",
56832 object->debug_id, cookie->def->name, object->events);
56833@@ -376,7 +376,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
56834
56835 _enter("{%s}", cookie->def->name);
56836
56837- fscache_stat(&fscache_n_invalidates);
56838+ fscache_stat_unchecked(&fscache_n_invalidates);
56839
56840 /* Only permit invalidation of data files. Invalidating an index will
56841 * require the caller to release all its attachments to the tree rooted
56842@@ -434,10 +434,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
56843 {
56844 struct fscache_object *object;
56845
56846- fscache_stat(&fscache_n_updates);
56847+ fscache_stat_unchecked(&fscache_n_updates);
56848
56849 if (!cookie) {
56850- fscache_stat(&fscache_n_updates_null);
56851+ fscache_stat_unchecked(&fscache_n_updates_null);
56852 _leave(" [no cookie]");
56853 return;
56854 }
56855@@ -471,12 +471,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
56856 struct fscache_object *object;
56857 unsigned long event;
56858
56859- fscache_stat(&fscache_n_relinquishes);
56860+ fscache_stat_unchecked(&fscache_n_relinquishes);
56861 if (retire)
56862- fscache_stat(&fscache_n_relinquishes_retire);
56863+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
56864
56865 if (!cookie) {
56866- fscache_stat(&fscache_n_relinquishes_null);
56867+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
56868 _leave(" [no cookie]");
56869 return;
56870 }
56871@@ -492,7 +492,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
56872
56873 /* wait for the cookie to finish being instantiated (or to fail) */
56874 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
56875- fscache_stat(&fscache_n_relinquishes_waitcrt);
56876+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
56877 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
56878 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
56879 }
56880diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
56881index ee38fef..0a326d4 100644
56882--- a/fs/fscache/internal.h
56883+++ b/fs/fscache/internal.h
56884@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
56885 * stats.c
56886 */
56887 #ifdef CONFIG_FSCACHE_STATS
56888-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
56889-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
56890+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
56891+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
56892
56893-extern atomic_t fscache_n_op_pend;
56894-extern atomic_t fscache_n_op_run;
56895-extern atomic_t fscache_n_op_enqueue;
56896-extern atomic_t fscache_n_op_deferred_release;
56897-extern atomic_t fscache_n_op_release;
56898-extern atomic_t fscache_n_op_gc;
56899-extern atomic_t fscache_n_op_cancelled;
56900-extern atomic_t fscache_n_op_rejected;
56901+extern atomic_unchecked_t fscache_n_op_pend;
56902+extern atomic_unchecked_t fscache_n_op_run;
56903+extern atomic_unchecked_t fscache_n_op_enqueue;
56904+extern atomic_unchecked_t fscache_n_op_deferred_release;
56905+extern atomic_unchecked_t fscache_n_op_release;
56906+extern atomic_unchecked_t fscache_n_op_gc;
56907+extern atomic_unchecked_t fscache_n_op_cancelled;
56908+extern atomic_unchecked_t fscache_n_op_rejected;
56909
56910-extern atomic_t fscache_n_attr_changed;
56911-extern atomic_t fscache_n_attr_changed_ok;
56912-extern atomic_t fscache_n_attr_changed_nobufs;
56913-extern atomic_t fscache_n_attr_changed_nomem;
56914-extern atomic_t fscache_n_attr_changed_calls;
56915+extern atomic_unchecked_t fscache_n_attr_changed;
56916+extern atomic_unchecked_t fscache_n_attr_changed_ok;
56917+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
56918+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
56919+extern atomic_unchecked_t fscache_n_attr_changed_calls;
56920
56921-extern atomic_t fscache_n_allocs;
56922-extern atomic_t fscache_n_allocs_ok;
56923-extern atomic_t fscache_n_allocs_wait;
56924-extern atomic_t fscache_n_allocs_nobufs;
56925-extern atomic_t fscache_n_allocs_intr;
56926-extern atomic_t fscache_n_allocs_object_dead;
56927-extern atomic_t fscache_n_alloc_ops;
56928-extern atomic_t fscache_n_alloc_op_waits;
56929+extern atomic_unchecked_t fscache_n_allocs;
56930+extern atomic_unchecked_t fscache_n_allocs_ok;
56931+extern atomic_unchecked_t fscache_n_allocs_wait;
56932+extern atomic_unchecked_t fscache_n_allocs_nobufs;
56933+extern atomic_unchecked_t fscache_n_allocs_intr;
56934+extern atomic_unchecked_t fscache_n_allocs_object_dead;
56935+extern atomic_unchecked_t fscache_n_alloc_ops;
56936+extern atomic_unchecked_t fscache_n_alloc_op_waits;
56937
56938-extern atomic_t fscache_n_retrievals;
56939-extern atomic_t fscache_n_retrievals_ok;
56940-extern atomic_t fscache_n_retrievals_wait;
56941-extern atomic_t fscache_n_retrievals_nodata;
56942-extern atomic_t fscache_n_retrievals_nobufs;
56943-extern atomic_t fscache_n_retrievals_intr;
56944-extern atomic_t fscache_n_retrievals_nomem;
56945-extern atomic_t fscache_n_retrievals_object_dead;
56946-extern atomic_t fscache_n_retrieval_ops;
56947-extern atomic_t fscache_n_retrieval_op_waits;
56948+extern atomic_unchecked_t fscache_n_retrievals;
56949+extern atomic_unchecked_t fscache_n_retrievals_ok;
56950+extern atomic_unchecked_t fscache_n_retrievals_wait;
56951+extern atomic_unchecked_t fscache_n_retrievals_nodata;
56952+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
56953+extern atomic_unchecked_t fscache_n_retrievals_intr;
56954+extern atomic_unchecked_t fscache_n_retrievals_nomem;
56955+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
56956+extern atomic_unchecked_t fscache_n_retrieval_ops;
56957+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
56958
56959-extern atomic_t fscache_n_stores;
56960-extern atomic_t fscache_n_stores_ok;
56961-extern atomic_t fscache_n_stores_again;
56962-extern atomic_t fscache_n_stores_nobufs;
56963-extern atomic_t fscache_n_stores_oom;
56964-extern atomic_t fscache_n_store_ops;
56965-extern atomic_t fscache_n_store_calls;
56966-extern atomic_t fscache_n_store_pages;
56967-extern atomic_t fscache_n_store_radix_deletes;
56968-extern atomic_t fscache_n_store_pages_over_limit;
56969+extern atomic_unchecked_t fscache_n_stores;
56970+extern atomic_unchecked_t fscache_n_stores_ok;
56971+extern atomic_unchecked_t fscache_n_stores_again;
56972+extern atomic_unchecked_t fscache_n_stores_nobufs;
56973+extern atomic_unchecked_t fscache_n_stores_oom;
56974+extern atomic_unchecked_t fscache_n_store_ops;
56975+extern atomic_unchecked_t fscache_n_store_calls;
56976+extern atomic_unchecked_t fscache_n_store_pages;
56977+extern atomic_unchecked_t fscache_n_store_radix_deletes;
56978+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
56979
56980-extern atomic_t fscache_n_store_vmscan_not_storing;
56981-extern atomic_t fscache_n_store_vmscan_gone;
56982-extern atomic_t fscache_n_store_vmscan_busy;
56983-extern atomic_t fscache_n_store_vmscan_cancelled;
56984-extern atomic_t fscache_n_store_vmscan_wait;
56985+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56986+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
56987+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
56988+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56989+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
56990
56991-extern atomic_t fscache_n_marks;
56992-extern atomic_t fscache_n_uncaches;
56993+extern atomic_unchecked_t fscache_n_marks;
56994+extern atomic_unchecked_t fscache_n_uncaches;
56995
56996-extern atomic_t fscache_n_acquires;
56997-extern atomic_t fscache_n_acquires_null;
56998-extern atomic_t fscache_n_acquires_no_cache;
56999-extern atomic_t fscache_n_acquires_ok;
57000-extern atomic_t fscache_n_acquires_nobufs;
57001-extern atomic_t fscache_n_acquires_oom;
57002+extern atomic_unchecked_t fscache_n_acquires;
57003+extern atomic_unchecked_t fscache_n_acquires_null;
57004+extern atomic_unchecked_t fscache_n_acquires_no_cache;
57005+extern atomic_unchecked_t fscache_n_acquires_ok;
57006+extern atomic_unchecked_t fscache_n_acquires_nobufs;
57007+extern atomic_unchecked_t fscache_n_acquires_oom;
57008
57009-extern atomic_t fscache_n_invalidates;
57010-extern atomic_t fscache_n_invalidates_run;
57011+extern atomic_unchecked_t fscache_n_invalidates;
57012+extern atomic_unchecked_t fscache_n_invalidates_run;
57013
57014-extern atomic_t fscache_n_updates;
57015-extern atomic_t fscache_n_updates_null;
57016-extern atomic_t fscache_n_updates_run;
57017+extern atomic_unchecked_t fscache_n_updates;
57018+extern atomic_unchecked_t fscache_n_updates_null;
57019+extern atomic_unchecked_t fscache_n_updates_run;
57020
57021-extern atomic_t fscache_n_relinquishes;
57022-extern atomic_t fscache_n_relinquishes_null;
57023-extern atomic_t fscache_n_relinquishes_waitcrt;
57024-extern atomic_t fscache_n_relinquishes_retire;
57025+extern atomic_unchecked_t fscache_n_relinquishes;
57026+extern atomic_unchecked_t fscache_n_relinquishes_null;
57027+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
57028+extern atomic_unchecked_t fscache_n_relinquishes_retire;
57029
57030-extern atomic_t fscache_n_cookie_index;
57031-extern atomic_t fscache_n_cookie_data;
57032-extern atomic_t fscache_n_cookie_special;
57033+extern atomic_unchecked_t fscache_n_cookie_index;
57034+extern atomic_unchecked_t fscache_n_cookie_data;
57035+extern atomic_unchecked_t fscache_n_cookie_special;
57036
57037-extern atomic_t fscache_n_object_alloc;
57038-extern atomic_t fscache_n_object_no_alloc;
57039-extern atomic_t fscache_n_object_lookups;
57040-extern atomic_t fscache_n_object_lookups_negative;
57041-extern atomic_t fscache_n_object_lookups_positive;
57042-extern atomic_t fscache_n_object_lookups_timed_out;
57043-extern atomic_t fscache_n_object_created;
57044-extern atomic_t fscache_n_object_avail;
57045-extern atomic_t fscache_n_object_dead;
57046+extern atomic_unchecked_t fscache_n_object_alloc;
57047+extern atomic_unchecked_t fscache_n_object_no_alloc;
57048+extern atomic_unchecked_t fscache_n_object_lookups;
57049+extern atomic_unchecked_t fscache_n_object_lookups_negative;
57050+extern atomic_unchecked_t fscache_n_object_lookups_positive;
57051+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
57052+extern atomic_unchecked_t fscache_n_object_created;
57053+extern atomic_unchecked_t fscache_n_object_avail;
57054+extern atomic_unchecked_t fscache_n_object_dead;
57055
57056-extern atomic_t fscache_n_checkaux_none;
57057-extern atomic_t fscache_n_checkaux_okay;
57058-extern atomic_t fscache_n_checkaux_update;
57059-extern atomic_t fscache_n_checkaux_obsolete;
57060+extern atomic_unchecked_t fscache_n_checkaux_none;
57061+extern atomic_unchecked_t fscache_n_checkaux_okay;
57062+extern atomic_unchecked_t fscache_n_checkaux_update;
57063+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
57064
57065 extern atomic_t fscache_n_cop_alloc_object;
57066 extern atomic_t fscache_n_cop_lookup_object;
57067@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
57068 atomic_inc(stat);
57069 }
57070
57071+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
57072+{
57073+ atomic_inc_unchecked(stat);
57074+}
57075+
57076 static inline void fscache_stat_d(atomic_t *stat)
57077 {
57078 atomic_dec(stat);
57079@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
57080
57081 #define __fscache_stat(stat) (NULL)
57082 #define fscache_stat(stat) do {} while (0)
57083+#define fscache_stat_unchecked(stat) do {} while (0)
57084 #define fscache_stat_d(stat) do {} while (0)
57085 #endif
57086
57087diff --git a/fs/fscache/object.c b/fs/fscache/object.c
57088index 50d41c1..10ee117 100644
57089--- a/fs/fscache/object.c
57090+++ b/fs/fscache/object.c
57091@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
57092 /* Invalidate an object on disk */
57093 case FSCACHE_OBJECT_INVALIDATING:
57094 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
57095- fscache_stat(&fscache_n_invalidates_run);
57096+ fscache_stat_unchecked(&fscache_n_invalidates_run);
57097 fscache_stat(&fscache_n_cop_invalidate_object);
57098 fscache_invalidate_object(object);
57099 fscache_stat_d(&fscache_n_cop_invalidate_object);
57100@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
57101 /* update the object metadata on disk */
57102 case FSCACHE_OBJECT_UPDATING:
57103 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
57104- fscache_stat(&fscache_n_updates_run);
57105+ fscache_stat_unchecked(&fscache_n_updates_run);
57106 fscache_stat(&fscache_n_cop_update_object);
57107 object->cache->ops->update_object(object);
57108 fscache_stat_d(&fscache_n_cop_update_object);
57109@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
57110 spin_lock(&object->lock);
57111 object->state = FSCACHE_OBJECT_DEAD;
57112 spin_unlock(&object->lock);
57113- fscache_stat(&fscache_n_object_dead);
57114+ fscache_stat_unchecked(&fscache_n_object_dead);
57115 goto terminal_transit;
57116
57117 /* handle the parent cache of this object being withdrawn from
57118@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
57119 spin_lock(&object->lock);
57120 object->state = FSCACHE_OBJECT_DEAD;
57121 spin_unlock(&object->lock);
57122- fscache_stat(&fscache_n_object_dead);
57123+ fscache_stat_unchecked(&fscache_n_object_dead);
57124 goto terminal_transit;
57125
57126 /* complain about the object being woken up once it is
57127@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
57128 parent->cookie->def->name, cookie->def->name,
57129 object->cache->tag->name);
57130
57131- fscache_stat(&fscache_n_object_lookups);
57132+ fscache_stat_unchecked(&fscache_n_object_lookups);
57133 fscache_stat(&fscache_n_cop_lookup_object);
57134 ret = object->cache->ops->lookup_object(object);
57135 fscache_stat_d(&fscache_n_cop_lookup_object);
57136@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
57137 if (ret == -ETIMEDOUT) {
57138 /* probably stuck behind another object, so move this one to
57139 * the back of the queue */
57140- fscache_stat(&fscache_n_object_lookups_timed_out);
57141+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
57142 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
57143 }
57144
57145@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
57146
57147 spin_lock(&object->lock);
57148 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
57149- fscache_stat(&fscache_n_object_lookups_negative);
57150+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
57151
57152 /* transit here to allow write requests to begin stacking up
57153 * and read requests to begin returning ENODATA */
57154@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
57155 * result, in which case there may be data available */
57156 spin_lock(&object->lock);
57157 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
57158- fscache_stat(&fscache_n_object_lookups_positive);
57159+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
57160
57161 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
57162
57163@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
57164 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
57165 } else {
57166 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
57167- fscache_stat(&fscache_n_object_created);
57168+ fscache_stat_unchecked(&fscache_n_object_created);
57169
57170 object->state = FSCACHE_OBJECT_AVAILABLE;
57171 spin_unlock(&object->lock);
57172@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
57173 fscache_enqueue_dependents(object);
57174
57175 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
57176- fscache_stat(&fscache_n_object_avail);
57177+ fscache_stat_unchecked(&fscache_n_object_avail);
57178
57179 _leave("");
57180 }
57181@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
57182 enum fscache_checkaux result;
57183
57184 if (!object->cookie->def->check_aux) {
57185- fscache_stat(&fscache_n_checkaux_none);
57186+ fscache_stat_unchecked(&fscache_n_checkaux_none);
57187 return FSCACHE_CHECKAUX_OKAY;
57188 }
57189
57190@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
57191 switch (result) {
57192 /* entry okay as is */
57193 case FSCACHE_CHECKAUX_OKAY:
57194- fscache_stat(&fscache_n_checkaux_okay);
57195+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
57196 break;
57197
57198 /* entry requires update */
57199 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
57200- fscache_stat(&fscache_n_checkaux_update);
57201+ fscache_stat_unchecked(&fscache_n_checkaux_update);
57202 break;
57203
57204 /* entry requires deletion */
57205 case FSCACHE_CHECKAUX_OBSOLETE:
57206- fscache_stat(&fscache_n_checkaux_obsolete);
57207+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
57208 break;
57209
57210 default:
57211diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
57212index 762a9ec..2023284 100644
57213--- a/fs/fscache/operation.c
57214+++ b/fs/fscache/operation.c
57215@@ -17,7 +17,7 @@
57216 #include <linux/slab.h>
57217 #include "internal.h"
57218
57219-atomic_t fscache_op_debug_id;
57220+atomic_unchecked_t fscache_op_debug_id;
57221 EXPORT_SYMBOL(fscache_op_debug_id);
57222
57223 /**
57224@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
57225 ASSERTCMP(atomic_read(&op->usage), >, 0);
57226 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
57227
57228- fscache_stat(&fscache_n_op_enqueue);
57229+ fscache_stat_unchecked(&fscache_n_op_enqueue);
57230 switch (op->flags & FSCACHE_OP_TYPE) {
57231 case FSCACHE_OP_ASYNC:
57232 _debug("queue async");
57233@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
57234 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
57235 if (op->processor)
57236 fscache_enqueue_operation(op);
57237- fscache_stat(&fscache_n_op_run);
57238+ fscache_stat_unchecked(&fscache_n_op_run);
57239 }
57240
57241 /*
57242@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
57243 if (object->n_in_progress > 0) {
57244 atomic_inc(&op->usage);
57245 list_add_tail(&op->pend_link, &object->pending_ops);
57246- fscache_stat(&fscache_n_op_pend);
57247+ fscache_stat_unchecked(&fscache_n_op_pend);
57248 } else if (!list_empty(&object->pending_ops)) {
57249 atomic_inc(&op->usage);
57250 list_add_tail(&op->pend_link, &object->pending_ops);
57251- fscache_stat(&fscache_n_op_pend);
57252+ fscache_stat_unchecked(&fscache_n_op_pend);
57253 fscache_start_operations(object);
57254 } else {
57255 ASSERTCMP(object->n_in_progress, ==, 0);
57256@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
57257 object->n_exclusive++; /* reads and writes must wait */
57258 atomic_inc(&op->usage);
57259 list_add_tail(&op->pend_link, &object->pending_ops);
57260- fscache_stat(&fscache_n_op_pend);
57261+ fscache_stat_unchecked(&fscache_n_op_pend);
57262 ret = 0;
57263 } else {
57264 /* If we're in any other state, there must have been an I/O
57265@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
57266 if (object->n_exclusive > 0) {
57267 atomic_inc(&op->usage);
57268 list_add_tail(&op->pend_link, &object->pending_ops);
57269- fscache_stat(&fscache_n_op_pend);
57270+ fscache_stat_unchecked(&fscache_n_op_pend);
57271 } else if (!list_empty(&object->pending_ops)) {
57272 atomic_inc(&op->usage);
57273 list_add_tail(&op->pend_link, &object->pending_ops);
57274- fscache_stat(&fscache_n_op_pend);
57275+ fscache_stat_unchecked(&fscache_n_op_pend);
57276 fscache_start_operations(object);
57277 } else {
57278 ASSERTCMP(object->n_exclusive, ==, 0);
57279@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
57280 object->n_ops++;
57281 atomic_inc(&op->usage);
57282 list_add_tail(&op->pend_link, &object->pending_ops);
57283- fscache_stat(&fscache_n_op_pend);
57284+ fscache_stat_unchecked(&fscache_n_op_pend);
57285 ret = 0;
57286 } else if (object->state == FSCACHE_OBJECT_DYING ||
57287 object->state == FSCACHE_OBJECT_LC_DYING ||
57288 object->state == FSCACHE_OBJECT_WITHDRAWING) {
57289- fscache_stat(&fscache_n_op_rejected);
57290+ fscache_stat_unchecked(&fscache_n_op_rejected);
57291 op->state = FSCACHE_OP_ST_CANCELLED;
57292 ret = -ENOBUFS;
57293 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
57294@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
57295 ret = -EBUSY;
57296 if (op->state == FSCACHE_OP_ST_PENDING) {
57297 ASSERT(!list_empty(&op->pend_link));
57298- fscache_stat(&fscache_n_op_cancelled);
57299+ fscache_stat_unchecked(&fscache_n_op_cancelled);
57300 list_del_init(&op->pend_link);
57301 if (do_cancel)
57302 do_cancel(op);
57303@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
57304 while (!list_empty(&object->pending_ops)) {
57305 op = list_entry(object->pending_ops.next,
57306 struct fscache_operation, pend_link);
57307- fscache_stat(&fscache_n_op_cancelled);
57308+ fscache_stat_unchecked(&fscache_n_op_cancelled);
57309 list_del_init(&op->pend_link);
57310
57311 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
57312@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
57313 op->state, ==, FSCACHE_OP_ST_CANCELLED);
57314 op->state = FSCACHE_OP_ST_DEAD;
57315
57316- fscache_stat(&fscache_n_op_release);
57317+ fscache_stat_unchecked(&fscache_n_op_release);
57318
57319 if (op->release) {
57320 op->release(op);
57321@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
57322 * lock, and defer it otherwise */
57323 if (!spin_trylock(&object->lock)) {
57324 _debug("defer put");
57325- fscache_stat(&fscache_n_op_deferred_release);
57326+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
57327
57328 cache = object->cache;
57329 spin_lock(&cache->op_gc_list_lock);
57330@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
57331
57332 _debug("GC DEFERRED REL OBJ%x OP%x",
57333 object->debug_id, op->debug_id);
57334- fscache_stat(&fscache_n_op_gc);
57335+ fscache_stat_unchecked(&fscache_n_op_gc);
57336
57337 ASSERTCMP(atomic_read(&op->usage), ==, 0);
57338 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
57339diff --git a/fs/fscache/page.c b/fs/fscache/page.c
57340index ff000e5..c44ec6d 100644
57341--- a/fs/fscache/page.c
57342+++ b/fs/fscache/page.c
57343@@ -61,7 +61,7 @@ try_again:
57344 val = radix_tree_lookup(&cookie->stores, page->index);
57345 if (!val) {
57346 rcu_read_unlock();
57347- fscache_stat(&fscache_n_store_vmscan_not_storing);
57348+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
57349 __fscache_uncache_page(cookie, page);
57350 return true;
57351 }
57352@@ -91,11 +91,11 @@ try_again:
57353 spin_unlock(&cookie->stores_lock);
57354
57355 if (xpage) {
57356- fscache_stat(&fscache_n_store_vmscan_cancelled);
57357- fscache_stat(&fscache_n_store_radix_deletes);
57358+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
57359+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
57360 ASSERTCMP(xpage, ==, page);
57361 } else {
57362- fscache_stat(&fscache_n_store_vmscan_gone);
57363+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
57364 }
57365
57366 wake_up_bit(&cookie->flags, 0);
57367@@ -110,11 +110,11 @@ page_busy:
57368 * sleeping on memory allocation, so we may need to impose a timeout
57369 * too. */
57370 if (!(gfp & __GFP_WAIT)) {
57371- fscache_stat(&fscache_n_store_vmscan_busy);
57372+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
57373 return false;
57374 }
57375
57376- fscache_stat(&fscache_n_store_vmscan_wait);
57377+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
57378 __fscache_wait_on_page_write(cookie, page);
57379 gfp &= ~__GFP_WAIT;
57380 goto try_again;
57381@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
57382 FSCACHE_COOKIE_STORING_TAG);
57383 if (!radix_tree_tag_get(&cookie->stores, page->index,
57384 FSCACHE_COOKIE_PENDING_TAG)) {
57385- fscache_stat(&fscache_n_store_radix_deletes);
57386+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
57387 xpage = radix_tree_delete(&cookie->stores, page->index);
57388 }
57389 spin_unlock(&cookie->stores_lock);
57390@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
57391
57392 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
57393
57394- fscache_stat(&fscache_n_attr_changed_calls);
57395+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
57396
57397 if (fscache_object_is_active(object)) {
57398 fscache_stat(&fscache_n_cop_attr_changed);
57399@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57400
57401 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
57402
57403- fscache_stat(&fscache_n_attr_changed);
57404+ fscache_stat_unchecked(&fscache_n_attr_changed);
57405
57406 op = kzalloc(sizeof(*op), GFP_KERNEL);
57407 if (!op) {
57408- fscache_stat(&fscache_n_attr_changed_nomem);
57409+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
57410 _leave(" = -ENOMEM");
57411 return -ENOMEM;
57412 }
57413@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57414 if (fscache_submit_exclusive_op(object, op) < 0)
57415 goto nobufs;
57416 spin_unlock(&cookie->lock);
57417- fscache_stat(&fscache_n_attr_changed_ok);
57418+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
57419 fscache_put_operation(op);
57420 _leave(" = 0");
57421 return 0;
57422@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57423 nobufs:
57424 spin_unlock(&cookie->lock);
57425 kfree(op);
57426- fscache_stat(&fscache_n_attr_changed_nobufs);
57427+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
57428 _leave(" = %d", -ENOBUFS);
57429 return -ENOBUFS;
57430 }
57431@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
57432 /* allocate a retrieval operation and attempt to submit it */
57433 op = kzalloc(sizeof(*op), GFP_NOIO);
57434 if (!op) {
57435- fscache_stat(&fscache_n_retrievals_nomem);
57436+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57437 return NULL;
57438 }
57439
57440@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
57441 return 0;
57442 }
57443
57444- fscache_stat(&fscache_n_retrievals_wait);
57445+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
57446
57447 jif = jiffies;
57448 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
57449 fscache_wait_bit_interruptible,
57450 TASK_INTERRUPTIBLE) != 0) {
57451- fscache_stat(&fscache_n_retrievals_intr);
57452+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57453 _leave(" = -ERESTARTSYS");
57454 return -ERESTARTSYS;
57455 }
57456@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
57457 */
57458 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
57459 struct fscache_retrieval *op,
57460- atomic_t *stat_op_waits,
57461- atomic_t *stat_object_dead)
57462+ atomic_unchecked_t *stat_op_waits,
57463+ atomic_unchecked_t *stat_object_dead)
57464 {
57465 int ret;
57466
57467@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
57468 goto check_if_dead;
57469
57470 _debug(">>> WT");
57471- fscache_stat(stat_op_waits);
57472+ fscache_stat_unchecked(stat_op_waits);
57473 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
57474 fscache_wait_bit_interruptible,
57475 TASK_INTERRUPTIBLE) != 0) {
57476@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
57477
57478 check_if_dead:
57479 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
57480- fscache_stat(stat_object_dead);
57481+ fscache_stat_unchecked(stat_object_dead);
57482 _leave(" = -ENOBUFS [cancelled]");
57483 return -ENOBUFS;
57484 }
57485 if (unlikely(fscache_object_is_dead(object))) {
57486 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
57487 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
57488- fscache_stat(stat_object_dead);
57489+ fscache_stat_unchecked(stat_object_dead);
57490 return -ENOBUFS;
57491 }
57492 return 0;
57493@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57494
57495 _enter("%p,%p,,,", cookie, page);
57496
57497- fscache_stat(&fscache_n_retrievals);
57498+ fscache_stat_unchecked(&fscache_n_retrievals);
57499
57500 if (hlist_empty(&cookie->backing_objects))
57501 goto nobufs;
57502@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57503 goto nobufs_unlock_dec;
57504 spin_unlock(&cookie->lock);
57505
57506- fscache_stat(&fscache_n_retrieval_ops);
57507+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
57508
57509 /* pin the netfs read context in case we need to do the actual netfs
57510 * read because we've encountered a cache read failure */
57511@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57512
57513 error:
57514 if (ret == -ENOMEM)
57515- fscache_stat(&fscache_n_retrievals_nomem);
57516+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57517 else if (ret == -ERESTARTSYS)
57518- fscache_stat(&fscache_n_retrievals_intr);
57519+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57520 else if (ret == -ENODATA)
57521- fscache_stat(&fscache_n_retrievals_nodata);
57522+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
57523 else if (ret < 0)
57524- fscache_stat(&fscache_n_retrievals_nobufs);
57525+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57526 else
57527- fscache_stat(&fscache_n_retrievals_ok);
57528+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
57529
57530 fscache_put_retrieval(op);
57531 _leave(" = %d", ret);
57532@@ -467,7 +467,7 @@ nobufs_unlock:
57533 spin_unlock(&cookie->lock);
57534 kfree(op);
57535 nobufs:
57536- fscache_stat(&fscache_n_retrievals_nobufs);
57537+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57538 _leave(" = -ENOBUFS");
57539 return -ENOBUFS;
57540 }
57541@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57542
57543 _enter("%p,,%d,,,", cookie, *nr_pages);
57544
57545- fscache_stat(&fscache_n_retrievals);
57546+ fscache_stat_unchecked(&fscache_n_retrievals);
57547
57548 if (hlist_empty(&cookie->backing_objects))
57549 goto nobufs;
57550@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57551 goto nobufs_unlock_dec;
57552 spin_unlock(&cookie->lock);
57553
57554- fscache_stat(&fscache_n_retrieval_ops);
57555+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
57556
57557 /* pin the netfs read context in case we need to do the actual netfs
57558 * read because we've encountered a cache read failure */
57559@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57560
57561 error:
57562 if (ret == -ENOMEM)
57563- fscache_stat(&fscache_n_retrievals_nomem);
57564+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57565 else if (ret == -ERESTARTSYS)
57566- fscache_stat(&fscache_n_retrievals_intr);
57567+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57568 else if (ret == -ENODATA)
57569- fscache_stat(&fscache_n_retrievals_nodata);
57570+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
57571 else if (ret < 0)
57572- fscache_stat(&fscache_n_retrievals_nobufs);
57573+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57574 else
57575- fscache_stat(&fscache_n_retrievals_ok);
57576+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
57577
57578 fscache_put_retrieval(op);
57579 _leave(" = %d", ret);
57580@@ -591,7 +591,7 @@ nobufs_unlock:
57581 spin_unlock(&cookie->lock);
57582 kfree(op);
57583 nobufs:
57584- fscache_stat(&fscache_n_retrievals_nobufs);
57585+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57586 _leave(" = -ENOBUFS");
57587 return -ENOBUFS;
57588 }
57589@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57590
57591 _enter("%p,%p,,,", cookie, page);
57592
57593- fscache_stat(&fscache_n_allocs);
57594+ fscache_stat_unchecked(&fscache_n_allocs);
57595
57596 if (hlist_empty(&cookie->backing_objects))
57597 goto nobufs;
57598@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57599 goto nobufs_unlock;
57600 spin_unlock(&cookie->lock);
57601
57602- fscache_stat(&fscache_n_alloc_ops);
57603+ fscache_stat_unchecked(&fscache_n_alloc_ops);
57604
57605 ret = fscache_wait_for_retrieval_activation(
57606 object, op,
57607@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57608
57609 error:
57610 if (ret == -ERESTARTSYS)
57611- fscache_stat(&fscache_n_allocs_intr);
57612+ fscache_stat_unchecked(&fscache_n_allocs_intr);
57613 else if (ret < 0)
57614- fscache_stat(&fscache_n_allocs_nobufs);
57615+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
57616 else
57617- fscache_stat(&fscache_n_allocs_ok);
57618+ fscache_stat_unchecked(&fscache_n_allocs_ok);
57619
57620 fscache_put_retrieval(op);
57621 _leave(" = %d", ret);
57622@@ -677,7 +677,7 @@ nobufs_unlock:
57623 spin_unlock(&cookie->lock);
57624 kfree(op);
57625 nobufs:
57626- fscache_stat(&fscache_n_allocs_nobufs);
57627+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
57628 _leave(" = -ENOBUFS");
57629 return -ENOBUFS;
57630 }
57631@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57632
57633 spin_lock(&cookie->stores_lock);
57634
57635- fscache_stat(&fscache_n_store_calls);
57636+ fscache_stat_unchecked(&fscache_n_store_calls);
57637
57638 /* find a page to store */
57639 page = NULL;
57640@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57641 page = results[0];
57642 _debug("gang %d [%lx]", n, page->index);
57643 if (page->index > op->store_limit) {
57644- fscache_stat(&fscache_n_store_pages_over_limit);
57645+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
57646 goto superseded;
57647 }
57648
57649@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57650 spin_unlock(&cookie->stores_lock);
57651 spin_unlock(&object->lock);
57652
57653- fscache_stat(&fscache_n_store_pages);
57654+ fscache_stat_unchecked(&fscache_n_store_pages);
57655 fscache_stat(&fscache_n_cop_write_page);
57656 ret = object->cache->ops->write_page(op, page);
57657 fscache_stat_d(&fscache_n_cop_write_page);
57658@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57659 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
57660 ASSERT(PageFsCache(page));
57661
57662- fscache_stat(&fscache_n_stores);
57663+ fscache_stat_unchecked(&fscache_n_stores);
57664
57665 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
57666 _leave(" = -ENOBUFS [invalidating]");
57667@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57668 spin_unlock(&cookie->stores_lock);
57669 spin_unlock(&object->lock);
57670
57671- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
57672+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
57673 op->store_limit = object->store_limit;
57674
57675 if (fscache_submit_op(object, &op->op) < 0)
57676@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57677
57678 spin_unlock(&cookie->lock);
57679 radix_tree_preload_end();
57680- fscache_stat(&fscache_n_store_ops);
57681- fscache_stat(&fscache_n_stores_ok);
57682+ fscache_stat_unchecked(&fscache_n_store_ops);
57683+ fscache_stat_unchecked(&fscache_n_stores_ok);
57684
57685 /* the work queue now carries its own ref on the object */
57686 fscache_put_operation(&op->op);
57687@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57688 return 0;
57689
57690 already_queued:
57691- fscache_stat(&fscache_n_stores_again);
57692+ fscache_stat_unchecked(&fscache_n_stores_again);
57693 already_pending:
57694 spin_unlock(&cookie->stores_lock);
57695 spin_unlock(&object->lock);
57696 spin_unlock(&cookie->lock);
57697 radix_tree_preload_end();
57698 kfree(op);
57699- fscache_stat(&fscache_n_stores_ok);
57700+ fscache_stat_unchecked(&fscache_n_stores_ok);
57701 _leave(" = 0");
57702 return 0;
57703
57704@@ -959,14 +959,14 @@ nobufs:
57705 spin_unlock(&cookie->lock);
57706 radix_tree_preload_end();
57707 kfree(op);
57708- fscache_stat(&fscache_n_stores_nobufs);
57709+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
57710 _leave(" = -ENOBUFS");
57711 return -ENOBUFS;
57712
57713 nomem_free:
57714 kfree(op);
57715 nomem:
57716- fscache_stat(&fscache_n_stores_oom);
57717+ fscache_stat_unchecked(&fscache_n_stores_oom);
57718 _leave(" = -ENOMEM");
57719 return -ENOMEM;
57720 }
57721@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
57722 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
57723 ASSERTCMP(page, !=, NULL);
57724
57725- fscache_stat(&fscache_n_uncaches);
57726+ fscache_stat_unchecked(&fscache_n_uncaches);
57727
57728 /* cache withdrawal may beat us to it */
57729 if (!PageFsCache(page))
57730@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
57731 struct fscache_cookie *cookie = op->op.object->cookie;
57732
57733 #ifdef CONFIG_FSCACHE_STATS
57734- atomic_inc(&fscache_n_marks);
57735+ atomic_inc_unchecked(&fscache_n_marks);
57736 #endif
57737
57738 _debug("- mark %p{%lx}", page, page->index);
57739diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
57740index 40d13c7..ddf52b9 100644
57741--- a/fs/fscache/stats.c
57742+++ b/fs/fscache/stats.c
57743@@ -18,99 +18,99 @@
57744 /*
57745 * operation counters
57746 */
57747-atomic_t fscache_n_op_pend;
57748-atomic_t fscache_n_op_run;
57749-atomic_t fscache_n_op_enqueue;
57750-atomic_t fscache_n_op_requeue;
57751-atomic_t fscache_n_op_deferred_release;
57752-atomic_t fscache_n_op_release;
57753-atomic_t fscache_n_op_gc;
57754-atomic_t fscache_n_op_cancelled;
57755-atomic_t fscache_n_op_rejected;
57756+atomic_unchecked_t fscache_n_op_pend;
57757+atomic_unchecked_t fscache_n_op_run;
57758+atomic_unchecked_t fscache_n_op_enqueue;
57759+atomic_unchecked_t fscache_n_op_requeue;
57760+atomic_unchecked_t fscache_n_op_deferred_release;
57761+atomic_unchecked_t fscache_n_op_release;
57762+atomic_unchecked_t fscache_n_op_gc;
57763+atomic_unchecked_t fscache_n_op_cancelled;
57764+atomic_unchecked_t fscache_n_op_rejected;
57765
57766-atomic_t fscache_n_attr_changed;
57767-atomic_t fscache_n_attr_changed_ok;
57768-atomic_t fscache_n_attr_changed_nobufs;
57769-atomic_t fscache_n_attr_changed_nomem;
57770-atomic_t fscache_n_attr_changed_calls;
57771+atomic_unchecked_t fscache_n_attr_changed;
57772+atomic_unchecked_t fscache_n_attr_changed_ok;
57773+atomic_unchecked_t fscache_n_attr_changed_nobufs;
57774+atomic_unchecked_t fscache_n_attr_changed_nomem;
57775+atomic_unchecked_t fscache_n_attr_changed_calls;
57776
57777-atomic_t fscache_n_allocs;
57778-atomic_t fscache_n_allocs_ok;
57779-atomic_t fscache_n_allocs_wait;
57780-atomic_t fscache_n_allocs_nobufs;
57781-atomic_t fscache_n_allocs_intr;
57782-atomic_t fscache_n_allocs_object_dead;
57783-atomic_t fscache_n_alloc_ops;
57784-atomic_t fscache_n_alloc_op_waits;
57785+atomic_unchecked_t fscache_n_allocs;
57786+atomic_unchecked_t fscache_n_allocs_ok;
57787+atomic_unchecked_t fscache_n_allocs_wait;
57788+atomic_unchecked_t fscache_n_allocs_nobufs;
57789+atomic_unchecked_t fscache_n_allocs_intr;
57790+atomic_unchecked_t fscache_n_allocs_object_dead;
57791+atomic_unchecked_t fscache_n_alloc_ops;
57792+atomic_unchecked_t fscache_n_alloc_op_waits;
57793
57794-atomic_t fscache_n_retrievals;
57795-atomic_t fscache_n_retrievals_ok;
57796-atomic_t fscache_n_retrievals_wait;
57797-atomic_t fscache_n_retrievals_nodata;
57798-atomic_t fscache_n_retrievals_nobufs;
57799-atomic_t fscache_n_retrievals_intr;
57800-atomic_t fscache_n_retrievals_nomem;
57801-atomic_t fscache_n_retrievals_object_dead;
57802-atomic_t fscache_n_retrieval_ops;
57803-atomic_t fscache_n_retrieval_op_waits;
57804+atomic_unchecked_t fscache_n_retrievals;
57805+atomic_unchecked_t fscache_n_retrievals_ok;
57806+atomic_unchecked_t fscache_n_retrievals_wait;
57807+atomic_unchecked_t fscache_n_retrievals_nodata;
57808+atomic_unchecked_t fscache_n_retrievals_nobufs;
57809+atomic_unchecked_t fscache_n_retrievals_intr;
57810+atomic_unchecked_t fscache_n_retrievals_nomem;
57811+atomic_unchecked_t fscache_n_retrievals_object_dead;
57812+atomic_unchecked_t fscache_n_retrieval_ops;
57813+atomic_unchecked_t fscache_n_retrieval_op_waits;
57814
57815-atomic_t fscache_n_stores;
57816-atomic_t fscache_n_stores_ok;
57817-atomic_t fscache_n_stores_again;
57818-atomic_t fscache_n_stores_nobufs;
57819-atomic_t fscache_n_stores_oom;
57820-atomic_t fscache_n_store_ops;
57821-atomic_t fscache_n_store_calls;
57822-atomic_t fscache_n_store_pages;
57823-atomic_t fscache_n_store_radix_deletes;
57824-atomic_t fscache_n_store_pages_over_limit;
57825+atomic_unchecked_t fscache_n_stores;
57826+atomic_unchecked_t fscache_n_stores_ok;
57827+atomic_unchecked_t fscache_n_stores_again;
57828+atomic_unchecked_t fscache_n_stores_nobufs;
57829+atomic_unchecked_t fscache_n_stores_oom;
57830+atomic_unchecked_t fscache_n_store_ops;
57831+atomic_unchecked_t fscache_n_store_calls;
57832+atomic_unchecked_t fscache_n_store_pages;
57833+atomic_unchecked_t fscache_n_store_radix_deletes;
57834+atomic_unchecked_t fscache_n_store_pages_over_limit;
57835
57836-atomic_t fscache_n_store_vmscan_not_storing;
57837-atomic_t fscache_n_store_vmscan_gone;
57838-atomic_t fscache_n_store_vmscan_busy;
57839-atomic_t fscache_n_store_vmscan_cancelled;
57840-atomic_t fscache_n_store_vmscan_wait;
57841+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
57842+atomic_unchecked_t fscache_n_store_vmscan_gone;
57843+atomic_unchecked_t fscache_n_store_vmscan_busy;
57844+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
57845+atomic_unchecked_t fscache_n_store_vmscan_wait;
57846
57847-atomic_t fscache_n_marks;
57848-atomic_t fscache_n_uncaches;
57849+atomic_unchecked_t fscache_n_marks;
57850+atomic_unchecked_t fscache_n_uncaches;
57851
57852-atomic_t fscache_n_acquires;
57853-atomic_t fscache_n_acquires_null;
57854-atomic_t fscache_n_acquires_no_cache;
57855-atomic_t fscache_n_acquires_ok;
57856-atomic_t fscache_n_acquires_nobufs;
57857-atomic_t fscache_n_acquires_oom;
57858+atomic_unchecked_t fscache_n_acquires;
57859+atomic_unchecked_t fscache_n_acquires_null;
57860+atomic_unchecked_t fscache_n_acquires_no_cache;
57861+atomic_unchecked_t fscache_n_acquires_ok;
57862+atomic_unchecked_t fscache_n_acquires_nobufs;
57863+atomic_unchecked_t fscache_n_acquires_oom;
57864
57865-atomic_t fscache_n_invalidates;
57866-atomic_t fscache_n_invalidates_run;
57867+atomic_unchecked_t fscache_n_invalidates;
57868+atomic_unchecked_t fscache_n_invalidates_run;
57869
57870-atomic_t fscache_n_updates;
57871-atomic_t fscache_n_updates_null;
57872-atomic_t fscache_n_updates_run;
57873+atomic_unchecked_t fscache_n_updates;
57874+atomic_unchecked_t fscache_n_updates_null;
57875+atomic_unchecked_t fscache_n_updates_run;
57876
57877-atomic_t fscache_n_relinquishes;
57878-atomic_t fscache_n_relinquishes_null;
57879-atomic_t fscache_n_relinquishes_waitcrt;
57880-atomic_t fscache_n_relinquishes_retire;
57881+atomic_unchecked_t fscache_n_relinquishes;
57882+atomic_unchecked_t fscache_n_relinquishes_null;
57883+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
57884+atomic_unchecked_t fscache_n_relinquishes_retire;
57885
57886-atomic_t fscache_n_cookie_index;
57887-atomic_t fscache_n_cookie_data;
57888-atomic_t fscache_n_cookie_special;
57889+atomic_unchecked_t fscache_n_cookie_index;
57890+atomic_unchecked_t fscache_n_cookie_data;
57891+atomic_unchecked_t fscache_n_cookie_special;
57892
57893-atomic_t fscache_n_object_alloc;
57894-atomic_t fscache_n_object_no_alloc;
57895-atomic_t fscache_n_object_lookups;
57896-atomic_t fscache_n_object_lookups_negative;
57897-atomic_t fscache_n_object_lookups_positive;
57898-atomic_t fscache_n_object_lookups_timed_out;
57899-atomic_t fscache_n_object_created;
57900-atomic_t fscache_n_object_avail;
57901-atomic_t fscache_n_object_dead;
57902+atomic_unchecked_t fscache_n_object_alloc;
57903+atomic_unchecked_t fscache_n_object_no_alloc;
57904+atomic_unchecked_t fscache_n_object_lookups;
57905+atomic_unchecked_t fscache_n_object_lookups_negative;
57906+atomic_unchecked_t fscache_n_object_lookups_positive;
57907+atomic_unchecked_t fscache_n_object_lookups_timed_out;
57908+atomic_unchecked_t fscache_n_object_created;
57909+atomic_unchecked_t fscache_n_object_avail;
57910+atomic_unchecked_t fscache_n_object_dead;
57911
57912-atomic_t fscache_n_checkaux_none;
57913-atomic_t fscache_n_checkaux_okay;
57914-atomic_t fscache_n_checkaux_update;
57915-atomic_t fscache_n_checkaux_obsolete;
57916+atomic_unchecked_t fscache_n_checkaux_none;
57917+atomic_unchecked_t fscache_n_checkaux_okay;
57918+atomic_unchecked_t fscache_n_checkaux_update;
57919+atomic_unchecked_t fscache_n_checkaux_obsolete;
57920
57921 atomic_t fscache_n_cop_alloc_object;
57922 atomic_t fscache_n_cop_lookup_object;
57923@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
57924 seq_puts(m, "FS-Cache statistics\n");
57925
57926 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
57927- atomic_read(&fscache_n_cookie_index),
57928- atomic_read(&fscache_n_cookie_data),
57929- atomic_read(&fscache_n_cookie_special));
57930+ atomic_read_unchecked(&fscache_n_cookie_index),
57931+ atomic_read_unchecked(&fscache_n_cookie_data),
57932+ atomic_read_unchecked(&fscache_n_cookie_special));
57933
57934 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
57935- atomic_read(&fscache_n_object_alloc),
57936- atomic_read(&fscache_n_object_no_alloc),
57937- atomic_read(&fscache_n_object_avail),
57938- atomic_read(&fscache_n_object_dead));
57939+ atomic_read_unchecked(&fscache_n_object_alloc),
57940+ atomic_read_unchecked(&fscache_n_object_no_alloc),
57941+ atomic_read_unchecked(&fscache_n_object_avail),
57942+ atomic_read_unchecked(&fscache_n_object_dead));
57943 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
57944- atomic_read(&fscache_n_checkaux_none),
57945- atomic_read(&fscache_n_checkaux_okay),
57946- atomic_read(&fscache_n_checkaux_update),
57947- atomic_read(&fscache_n_checkaux_obsolete));
57948+ atomic_read_unchecked(&fscache_n_checkaux_none),
57949+ atomic_read_unchecked(&fscache_n_checkaux_okay),
57950+ atomic_read_unchecked(&fscache_n_checkaux_update),
57951+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
57952
57953 seq_printf(m, "Pages : mrk=%u unc=%u\n",
57954- atomic_read(&fscache_n_marks),
57955- atomic_read(&fscache_n_uncaches));
57956+ atomic_read_unchecked(&fscache_n_marks),
57957+ atomic_read_unchecked(&fscache_n_uncaches));
57958
57959 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
57960 " oom=%u\n",
57961- atomic_read(&fscache_n_acquires),
57962- atomic_read(&fscache_n_acquires_null),
57963- atomic_read(&fscache_n_acquires_no_cache),
57964- atomic_read(&fscache_n_acquires_ok),
57965- atomic_read(&fscache_n_acquires_nobufs),
57966- atomic_read(&fscache_n_acquires_oom));
57967+ atomic_read_unchecked(&fscache_n_acquires),
57968+ atomic_read_unchecked(&fscache_n_acquires_null),
57969+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
57970+ atomic_read_unchecked(&fscache_n_acquires_ok),
57971+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
57972+ atomic_read_unchecked(&fscache_n_acquires_oom));
57973
57974 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
57975- atomic_read(&fscache_n_object_lookups),
57976- atomic_read(&fscache_n_object_lookups_negative),
57977- atomic_read(&fscache_n_object_lookups_positive),
57978- atomic_read(&fscache_n_object_created),
57979- atomic_read(&fscache_n_object_lookups_timed_out));
57980+ atomic_read_unchecked(&fscache_n_object_lookups),
57981+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
57982+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
57983+ atomic_read_unchecked(&fscache_n_object_created),
57984+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
57985
57986 seq_printf(m, "Invals : n=%u run=%u\n",
57987- atomic_read(&fscache_n_invalidates),
57988- atomic_read(&fscache_n_invalidates_run));
57989+ atomic_read_unchecked(&fscache_n_invalidates),
57990+ atomic_read_unchecked(&fscache_n_invalidates_run));
57991
57992 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
57993- atomic_read(&fscache_n_updates),
57994- atomic_read(&fscache_n_updates_null),
57995- atomic_read(&fscache_n_updates_run));
57996+ atomic_read_unchecked(&fscache_n_updates),
57997+ atomic_read_unchecked(&fscache_n_updates_null),
57998+ atomic_read_unchecked(&fscache_n_updates_run));
57999
58000 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
58001- atomic_read(&fscache_n_relinquishes),
58002- atomic_read(&fscache_n_relinquishes_null),
58003- atomic_read(&fscache_n_relinquishes_waitcrt),
58004- atomic_read(&fscache_n_relinquishes_retire));
58005+ atomic_read_unchecked(&fscache_n_relinquishes),
58006+ atomic_read_unchecked(&fscache_n_relinquishes_null),
58007+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
58008+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
58009
58010 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
58011- atomic_read(&fscache_n_attr_changed),
58012- atomic_read(&fscache_n_attr_changed_ok),
58013- atomic_read(&fscache_n_attr_changed_nobufs),
58014- atomic_read(&fscache_n_attr_changed_nomem),
58015- atomic_read(&fscache_n_attr_changed_calls));
58016+ atomic_read_unchecked(&fscache_n_attr_changed),
58017+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
58018+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
58019+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
58020+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
58021
58022 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
58023- atomic_read(&fscache_n_allocs),
58024- atomic_read(&fscache_n_allocs_ok),
58025- atomic_read(&fscache_n_allocs_wait),
58026- atomic_read(&fscache_n_allocs_nobufs),
58027- atomic_read(&fscache_n_allocs_intr));
58028+ atomic_read_unchecked(&fscache_n_allocs),
58029+ atomic_read_unchecked(&fscache_n_allocs_ok),
58030+ atomic_read_unchecked(&fscache_n_allocs_wait),
58031+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
58032+ atomic_read_unchecked(&fscache_n_allocs_intr));
58033 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
58034- atomic_read(&fscache_n_alloc_ops),
58035- atomic_read(&fscache_n_alloc_op_waits),
58036- atomic_read(&fscache_n_allocs_object_dead));
58037+ atomic_read_unchecked(&fscache_n_alloc_ops),
58038+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
58039+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
58040
58041 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
58042 " int=%u oom=%u\n",
58043- atomic_read(&fscache_n_retrievals),
58044- atomic_read(&fscache_n_retrievals_ok),
58045- atomic_read(&fscache_n_retrievals_wait),
58046- atomic_read(&fscache_n_retrievals_nodata),
58047- atomic_read(&fscache_n_retrievals_nobufs),
58048- atomic_read(&fscache_n_retrievals_intr),
58049- atomic_read(&fscache_n_retrievals_nomem));
58050+ atomic_read_unchecked(&fscache_n_retrievals),
58051+ atomic_read_unchecked(&fscache_n_retrievals_ok),
58052+ atomic_read_unchecked(&fscache_n_retrievals_wait),
58053+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
58054+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
58055+ atomic_read_unchecked(&fscache_n_retrievals_intr),
58056+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
58057 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
58058- atomic_read(&fscache_n_retrieval_ops),
58059- atomic_read(&fscache_n_retrieval_op_waits),
58060- atomic_read(&fscache_n_retrievals_object_dead));
58061+ atomic_read_unchecked(&fscache_n_retrieval_ops),
58062+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
58063+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
58064
58065 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
58066- atomic_read(&fscache_n_stores),
58067- atomic_read(&fscache_n_stores_ok),
58068- atomic_read(&fscache_n_stores_again),
58069- atomic_read(&fscache_n_stores_nobufs),
58070- atomic_read(&fscache_n_stores_oom));
58071+ atomic_read_unchecked(&fscache_n_stores),
58072+ atomic_read_unchecked(&fscache_n_stores_ok),
58073+ atomic_read_unchecked(&fscache_n_stores_again),
58074+ atomic_read_unchecked(&fscache_n_stores_nobufs),
58075+ atomic_read_unchecked(&fscache_n_stores_oom));
58076 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
58077- atomic_read(&fscache_n_store_ops),
58078- atomic_read(&fscache_n_store_calls),
58079- atomic_read(&fscache_n_store_pages),
58080- atomic_read(&fscache_n_store_radix_deletes),
58081- atomic_read(&fscache_n_store_pages_over_limit));
58082+ atomic_read_unchecked(&fscache_n_store_ops),
58083+ atomic_read_unchecked(&fscache_n_store_calls),
58084+ atomic_read_unchecked(&fscache_n_store_pages),
58085+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
58086+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
58087
58088 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
58089- atomic_read(&fscache_n_store_vmscan_not_storing),
58090- atomic_read(&fscache_n_store_vmscan_gone),
58091- atomic_read(&fscache_n_store_vmscan_busy),
58092- atomic_read(&fscache_n_store_vmscan_cancelled),
58093- atomic_read(&fscache_n_store_vmscan_wait));
58094+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
58095+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
58096+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
58097+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
58098+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
58099
58100 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
58101- atomic_read(&fscache_n_op_pend),
58102- atomic_read(&fscache_n_op_run),
58103- atomic_read(&fscache_n_op_enqueue),
58104- atomic_read(&fscache_n_op_cancelled),
58105- atomic_read(&fscache_n_op_rejected));
58106+ atomic_read_unchecked(&fscache_n_op_pend),
58107+ atomic_read_unchecked(&fscache_n_op_run),
58108+ atomic_read_unchecked(&fscache_n_op_enqueue),
58109+ atomic_read_unchecked(&fscache_n_op_cancelled),
58110+ atomic_read_unchecked(&fscache_n_op_rejected));
58111 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
58112- atomic_read(&fscache_n_op_deferred_release),
58113- atomic_read(&fscache_n_op_release),
58114- atomic_read(&fscache_n_op_gc));
58115+ atomic_read_unchecked(&fscache_n_op_deferred_release),
58116+ atomic_read_unchecked(&fscache_n_op_release),
58117+ atomic_read_unchecked(&fscache_n_op_gc));
58118
58119 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
58120 atomic_read(&fscache_n_cop_alloc_object),
58121diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
58122index aef34b1..59bfd7b 100644
58123--- a/fs/fuse/cuse.c
58124+++ b/fs/fuse/cuse.c
58125@@ -600,10 +600,12 @@ static int __init cuse_init(void)
58126 INIT_LIST_HEAD(&cuse_conntbl[i]);
58127
58128 /* inherit and extend fuse_dev_operations */
58129- cuse_channel_fops = fuse_dev_operations;
58130- cuse_channel_fops.owner = THIS_MODULE;
58131- cuse_channel_fops.open = cuse_channel_open;
58132- cuse_channel_fops.release = cuse_channel_release;
58133+ pax_open_kernel();
58134+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
58135+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
58136+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
58137+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
58138+ pax_close_kernel();
58139
58140 cuse_class = class_create(THIS_MODULE, "cuse");
58141 if (IS_ERR(cuse_class))
58142diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
58143index 1d55f94..088da65 100644
58144--- a/fs/fuse/dev.c
58145+++ b/fs/fuse/dev.c
58146@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
58147 ret = 0;
58148 pipe_lock(pipe);
58149
58150- if (!pipe->readers) {
58151+ if (!atomic_read(&pipe->readers)) {
58152 send_sig(SIGPIPE, current, 0);
58153 if (!ret)
58154 ret = -EPIPE;
58155@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
58156 page_nr++;
58157 ret += buf->len;
58158
58159- if (pipe->files)
58160+ if (atomic_read(&pipe->files))
58161 do_wakeup = 1;
58162 }
58163
58164diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
58165index 5b12746..b481b03 100644
58166--- a/fs/fuse/dir.c
58167+++ b/fs/fuse/dir.c
58168@@ -1437,7 +1437,7 @@ static char *read_link(struct dentry *dentry)
58169 return link;
58170 }
58171
58172-static void free_link(char *link)
58173+static void free_link(const char *link)
58174 {
58175 if (!IS_ERR(link))
58176 free_page((unsigned long) link);
58177diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
58178index 62b484e..0f9a140 100644
58179--- a/fs/gfs2/inode.c
58180+++ b/fs/gfs2/inode.c
58181@@ -1441,7 +1441,7 @@ out:
58182
58183 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58184 {
58185- char *s = nd_get_link(nd);
58186+ const char *s = nd_get_link(nd);
58187 if (!IS_ERR(s))
58188 kfree(s);
58189 }
58190diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
58191index a3f868a..bb308ae 100644
58192--- a/fs/hugetlbfs/inode.c
58193+++ b/fs/hugetlbfs/inode.c
58194@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
58195 struct mm_struct *mm = current->mm;
58196 struct vm_area_struct *vma;
58197 struct hstate *h = hstate_file(file);
58198+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
58199 struct vm_unmapped_area_info info;
58200
58201 if (len & ~huge_page_mask(h))
58202@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
58203 return addr;
58204 }
58205
58206+#ifdef CONFIG_PAX_RANDMMAP
58207+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
58208+#endif
58209+
58210 if (addr) {
58211 addr = ALIGN(addr, huge_page_size(h));
58212 vma = find_vma(mm, addr);
58213- if (TASK_SIZE - len >= addr &&
58214- (!vma || addr + len <= vma->vm_start))
58215+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
58216 return addr;
58217 }
58218
58219 info.flags = 0;
58220 info.length = len;
58221 info.low_limit = TASK_UNMAPPED_BASE;
58222+
58223+#ifdef CONFIG_PAX_RANDMMAP
58224+ if (mm->pax_flags & MF_PAX_RANDMMAP)
58225+ info.low_limit += mm->delta_mmap;
58226+#endif
58227+
58228 info.high_limit = TASK_SIZE;
58229 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
58230 info.align_offset = 0;
58231@@ -898,7 +908,7 @@ static struct file_system_type hugetlbfs_fs_type = {
58232 };
58233 MODULE_ALIAS_FS("hugetlbfs");
58234
58235-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58236+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58237
58238 static int can_do_hugetlb_shm(void)
58239 {
58240diff --git a/fs/inode.c b/fs/inode.c
58241index 00d5fc3..98ce7d7 100644
58242--- a/fs/inode.c
58243+++ b/fs/inode.c
58244@@ -878,8 +878,8 @@ unsigned int get_next_ino(void)
58245
58246 #ifdef CONFIG_SMP
58247 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
58248- static atomic_t shared_last_ino;
58249- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
58250+ static atomic_unchecked_t shared_last_ino;
58251+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
58252
58253 res = next - LAST_INO_BATCH;
58254 }
58255diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
58256index 4a6cf28..d3a29d3 100644
58257--- a/fs/jffs2/erase.c
58258+++ b/fs/jffs2/erase.c
58259@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
58260 struct jffs2_unknown_node marker = {
58261 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
58262 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
58263- .totlen = cpu_to_je32(c->cleanmarker_size)
58264+ .totlen = cpu_to_je32(c->cleanmarker_size),
58265+ .hdr_crc = cpu_to_je32(0)
58266 };
58267
58268 jffs2_prealloc_raw_node_refs(c, jeb, 1);
58269diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
58270index a6597d6..41b30ec 100644
58271--- a/fs/jffs2/wbuf.c
58272+++ b/fs/jffs2/wbuf.c
58273@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
58274 {
58275 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
58276 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
58277- .totlen = constant_cpu_to_je32(8)
58278+ .totlen = constant_cpu_to_je32(8),
58279+ .hdr_crc = constant_cpu_to_je32(0)
58280 };
58281
58282 /*
58283diff --git a/fs/jfs/super.c b/fs/jfs/super.c
58284index 788e0a9..8433098 100644
58285--- a/fs/jfs/super.c
58286+++ b/fs/jfs/super.c
58287@@ -878,7 +878,7 @@ static int __init init_jfs_fs(void)
58288
58289 jfs_inode_cachep =
58290 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
58291- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
58292+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
58293 init_once);
58294 if (jfs_inode_cachep == NULL)
58295 return -ENOMEM;
58296diff --git a/fs/libfs.c b/fs/libfs.c
58297index 916da8c..1588998 100644
58298--- a/fs/libfs.c
58299+++ b/fs/libfs.c
58300@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
58301
58302 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
58303 struct dentry *next;
58304+ char d_name[sizeof(next->d_iname)];
58305+ const unsigned char *name;
58306+
58307 next = list_entry(p, struct dentry, d_u.d_child);
58308 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
58309 if (!simple_positive(next)) {
58310@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
58311
58312 spin_unlock(&next->d_lock);
58313 spin_unlock(&dentry->d_lock);
58314- if (filldir(dirent, next->d_name.name,
58315+ name = next->d_name.name;
58316+ if (name == next->d_iname) {
58317+ memcpy(d_name, name, next->d_name.len);
58318+ name = d_name;
58319+ }
58320+ if (filldir(dirent, name,
58321 next->d_name.len, filp->f_pos,
58322 next->d_inode->i_ino,
58323 dt_type(next->d_inode)) < 0)
58324diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
58325index acd3947..1f896e2 100644
58326--- a/fs/lockd/clntproc.c
58327+++ b/fs/lockd/clntproc.c
58328@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
58329 /*
58330 * Cookie counter for NLM requests
58331 */
58332-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
58333+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
58334
58335 void nlmclnt_next_cookie(struct nlm_cookie *c)
58336 {
58337- u32 cookie = atomic_inc_return(&nlm_cookie);
58338+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
58339
58340 memcpy(c->data, &cookie, 4);
58341 c->len=4;
58342diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
58343index a2aa97d..10d6c41 100644
58344--- a/fs/lockd/svc.c
58345+++ b/fs/lockd/svc.c
58346@@ -305,7 +305,7 @@ static int lockd_start_svc(struct svc_serv *serv)
58347 svc_sock_update_bufs(serv);
58348 serv->sv_maxconn = nlm_max_connections;
58349
58350- nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name);
58351+ nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, "%s", serv->sv_name);
58352 if (IS_ERR(nlmsvc_task)) {
58353 error = PTR_ERR(nlmsvc_task);
58354 printk(KERN_WARNING
58355diff --git a/fs/locks.c b/fs/locks.c
58356index cb424a4..850e4dd 100644
58357--- a/fs/locks.c
58358+++ b/fs/locks.c
58359@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
58360 return;
58361
58362 if (filp->f_op && filp->f_op->flock) {
58363- struct file_lock fl = {
58364+ struct file_lock flock = {
58365 .fl_pid = current->tgid,
58366 .fl_file = filp,
58367 .fl_flags = FL_FLOCK,
58368 .fl_type = F_UNLCK,
58369 .fl_end = OFFSET_MAX,
58370 };
58371- filp->f_op->flock(filp, F_SETLKW, &fl);
58372- if (fl.fl_ops && fl.fl_ops->fl_release_private)
58373- fl.fl_ops->fl_release_private(&fl);
58374+ filp->f_op->flock(filp, F_SETLKW, &flock);
58375+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
58376+ flock.fl_ops->fl_release_private(&flock);
58377 }
58378
58379 lock_flocks();
58380diff --git a/fs/namei.c b/fs/namei.c
58381index 9ed9361..2b72db1 100644
58382--- a/fs/namei.c
58383+++ b/fs/namei.c
58384@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
58385 if (ret != -EACCES)
58386 return ret;
58387
58388+#ifdef CONFIG_GRKERNSEC
58389+ /* we'll block if we have to log due to a denied capability use */
58390+ if (mask & MAY_NOT_BLOCK)
58391+ return -ECHILD;
58392+#endif
58393+
58394 if (S_ISDIR(inode->i_mode)) {
58395 /* DACs are overridable for directories */
58396- if (inode_capable(inode, CAP_DAC_OVERRIDE))
58397- return 0;
58398 if (!(mask & MAY_WRITE))
58399- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
58400+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
58401+ inode_capable(inode, CAP_DAC_READ_SEARCH))
58402 return 0;
58403+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
58404+ return 0;
58405 return -EACCES;
58406 }
58407 /*
58408+ * Searching includes executable on directories, else just read.
58409+ */
58410+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
58411+ if (mask == MAY_READ)
58412+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
58413+ inode_capable(inode, CAP_DAC_READ_SEARCH))
58414+ return 0;
58415+
58416+ /*
58417 * Read/write DACs are always overridable.
58418 * Executable DACs are overridable when there is
58419 * at least one exec bit set.
58420@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
58421 if (inode_capable(inode, CAP_DAC_OVERRIDE))
58422 return 0;
58423
58424- /*
58425- * Searching includes executable on directories, else just read.
58426- */
58427- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
58428- if (mask == MAY_READ)
58429- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
58430- return 0;
58431-
58432 return -EACCES;
58433 }
58434
58435@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
58436 {
58437 struct dentry *dentry = link->dentry;
58438 int error;
58439- char *s;
58440+ const char *s;
58441
58442 BUG_ON(nd->flags & LOOKUP_RCU);
58443
58444@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
58445 if (error)
58446 goto out_put_nd_path;
58447
58448+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
58449+ dentry->d_inode, dentry, nd->path.mnt)) {
58450+ error = -EACCES;
58451+ goto out_put_nd_path;
58452+ }
58453+
58454 nd->last_type = LAST_BIND;
58455 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
58456 error = PTR_ERR(*p);
58457@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
58458 if (res)
58459 break;
58460 res = walk_component(nd, path, LOOKUP_FOLLOW);
58461+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
58462+ res = -EACCES;
58463 put_link(nd, &link, cookie);
58464 } while (res > 0);
58465
58466@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
58467 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
58468 {
58469 unsigned long a, b, adata, bdata, mask, hash, len;
58470- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
58471+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
58472
58473 hash = a = 0;
58474 len = -sizeof(unsigned long);
58475@@ -1968,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
58476 if (err)
58477 break;
58478 err = lookup_last(nd, &path);
58479+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
58480+ err = -EACCES;
58481 put_link(nd, &link, cookie);
58482 }
58483 }
58484@@ -1975,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
58485 if (!err)
58486 err = complete_walk(nd);
58487
58488+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
58489+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58490+ path_put(&nd->path);
58491+ err = -ENOENT;
58492+ }
58493+ }
58494+
58495 if (!err && nd->flags & LOOKUP_DIRECTORY) {
58496 if (!can_lookup(nd->inode)) {
58497 path_put(&nd->path);
58498@@ -2002,8 +2027,15 @@ static int filename_lookup(int dfd, struct filename *name,
58499 retval = path_lookupat(dfd, name->name,
58500 flags | LOOKUP_REVAL, nd);
58501
58502- if (likely(!retval))
58503+ if (likely(!retval)) {
58504 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
58505+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
58506+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
58507+ path_put(&nd->path);
58508+ return -ENOENT;
58509+ }
58510+ }
58511+ }
58512 return retval;
58513 }
58514
58515@@ -2381,6 +2413,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
58516 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
58517 return -EPERM;
58518
58519+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
58520+ return -EPERM;
58521+ if (gr_handle_rawio(inode))
58522+ return -EPERM;
58523+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
58524+ return -EACCES;
58525+
58526 return 0;
58527 }
58528
58529@@ -2602,7 +2641,7 @@ looked_up:
58530 * cleared otherwise prior to returning.
58531 */
58532 static int lookup_open(struct nameidata *nd, struct path *path,
58533- struct file *file,
58534+ struct path *link, struct file *file,
58535 const struct open_flags *op,
58536 bool got_write, int *opened)
58537 {
58538@@ -2637,6 +2676,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
58539 /* Negative dentry, just create the file */
58540 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
58541 umode_t mode = op->mode;
58542+
58543+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
58544+ error = -EACCES;
58545+ goto out_dput;
58546+ }
58547+
58548+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
58549+ error = -EACCES;
58550+ goto out_dput;
58551+ }
58552+
58553 if (!IS_POSIXACL(dir->d_inode))
58554 mode &= ~current_umask();
58555 /*
58556@@ -2658,6 +2708,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
58557 nd->flags & LOOKUP_EXCL);
58558 if (error)
58559 goto out_dput;
58560+ else
58561+ gr_handle_create(dentry, nd->path.mnt);
58562 }
58563 out_no_open:
58564 path->dentry = dentry;
58565@@ -2672,7 +2724,7 @@ out_dput:
58566 /*
58567 * Handle the last step of open()
58568 */
58569-static int do_last(struct nameidata *nd, struct path *path,
58570+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
58571 struct file *file, const struct open_flags *op,
58572 int *opened, struct filename *name)
58573 {
58574@@ -2701,16 +2753,32 @@ static int do_last(struct nameidata *nd, struct path *path,
58575 error = complete_walk(nd);
58576 if (error)
58577 return error;
58578+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58579+ error = -ENOENT;
58580+ goto out;
58581+ }
58582 audit_inode(name, nd->path.dentry, 0);
58583 if (open_flag & O_CREAT) {
58584 error = -EISDIR;
58585 goto out;
58586 }
58587+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
58588+ error = -EACCES;
58589+ goto out;
58590+ }
58591 goto finish_open;
58592 case LAST_BIND:
58593 error = complete_walk(nd);
58594 if (error)
58595 return error;
58596+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
58597+ error = -ENOENT;
58598+ goto out;
58599+ }
58600+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
58601+ error = -EACCES;
58602+ goto out;
58603+ }
58604 audit_inode(name, dir, 0);
58605 goto finish_open;
58606 }
58607@@ -2759,7 +2827,7 @@ retry_lookup:
58608 */
58609 }
58610 mutex_lock(&dir->d_inode->i_mutex);
58611- error = lookup_open(nd, path, file, op, got_write, opened);
58612+ error = lookup_open(nd, path, link, file, op, got_write, opened);
58613 mutex_unlock(&dir->d_inode->i_mutex);
58614
58615 if (error <= 0) {
58616@@ -2783,11 +2851,28 @@ retry_lookup:
58617 goto finish_open_created;
58618 }
58619
58620+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
58621+ error = -ENOENT;
58622+ goto exit_dput;
58623+ }
58624+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
58625+ error = -EACCES;
58626+ goto exit_dput;
58627+ }
58628+
58629 /*
58630 * create/update audit record if it already exists.
58631 */
58632- if (path->dentry->d_inode)
58633+ if (path->dentry->d_inode) {
58634+ /* only check if O_CREAT is specified, all other checks need to go
58635+ into may_open */
58636+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
58637+ error = -EACCES;
58638+ goto exit_dput;
58639+ }
58640+
58641 audit_inode(name, path->dentry, 0);
58642+ }
58643
58644 /*
58645 * If atomic_open() acquired write access it is dropped now due to
58646@@ -2828,6 +2913,11 @@ finish_lookup:
58647 }
58648 }
58649 BUG_ON(inode != path->dentry->d_inode);
58650+ /* if we're resolving a symlink to another symlink */
58651+ if (link && gr_handle_symlink_owner(link, inode)) {
58652+ error = -EACCES;
58653+ goto out;
58654+ }
58655 return 1;
58656 }
58657
58658@@ -2837,7 +2927,6 @@ finish_lookup:
58659 save_parent.dentry = nd->path.dentry;
58660 save_parent.mnt = mntget(path->mnt);
58661 nd->path.dentry = path->dentry;
58662-
58663 }
58664 nd->inode = inode;
58665 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
58666@@ -2846,6 +2935,16 @@ finish_lookup:
58667 path_put(&save_parent);
58668 return error;
58669 }
58670+
58671+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58672+ error = -ENOENT;
58673+ goto out;
58674+ }
58675+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
58676+ error = -EACCES;
58677+ goto out;
58678+ }
58679+
58680 error = -EISDIR;
58681 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
58682 goto out;
58683@@ -2944,7 +3043,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
58684 if (unlikely(error))
58685 goto out;
58686
58687- error = do_last(nd, &path, file, op, &opened, pathname);
58688+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
58689 while (unlikely(error > 0)) { /* trailing symlink */
58690 struct path link = path;
58691 void *cookie;
58692@@ -2962,7 +3061,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
58693 error = follow_link(&link, nd, &cookie);
58694 if (unlikely(error))
58695 break;
58696- error = do_last(nd, &path, file, op, &opened, pathname);
58697+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
58698 put_link(nd, &link, cookie);
58699 }
58700 out:
58701@@ -3062,8 +3161,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
58702 goto unlock;
58703
58704 error = -EEXIST;
58705- if (dentry->d_inode)
58706+ if (dentry->d_inode) {
58707+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
58708+ error = -ENOENT;
58709+ }
58710 goto fail;
58711+ }
58712 /*
58713 * Special case - lookup gave negative, but... we had foo/bar/
58714 * From the vfs_mknod() POV we just have a negative dentry -
58715@@ -3115,6 +3218,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
58716 }
58717 EXPORT_SYMBOL(user_path_create);
58718
58719+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
58720+{
58721+ struct filename *tmp = getname(pathname);
58722+ struct dentry *res;
58723+ if (IS_ERR(tmp))
58724+ return ERR_CAST(tmp);
58725+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
58726+ if (IS_ERR(res))
58727+ putname(tmp);
58728+ else
58729+ *to = tmp;
58730+ return res;
58731+}
58732+
58733 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
58734 {
58735 int error = may_create(dir, dentry);
58736@@ -3177,6 +3294,17 @@ retry:
58737
58738 if (!IS_POSIXACL(path.dentry->d_inode))
58739 mode &= ~current_umask();
58740+
58741+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
58742+ error = -EPERM;
58743+ goto out;
58744+ }
58745+
58746+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
58747+ error = -EACCES;
58748+ goto out;
58749+ }
58750+
58751 error = security_path_mknod(&path, dentry, mode, dev);
58752 if (error)
58753 goto out;
58754@@ -3193,6 +3321,8 @@ retry:
58755 break;
58756 }
58757 out:
58758+ if (!error)
58759+ gr_handle_create(dentry, path.mnt);
58760 done_path_create(&path, dentry);
58761 if (retry_estale(error, lookup_flags)) {
58762 lookup_flags |= LOOKUP_REVAL;
58763@@ -3245,9 +3375,16 @@ retry:
58764
58765 if (!IS_POSIXACL(path.dentry->d_inode))
58766 mode &= ~current_umask();
58767+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
58768+ error = -EACCES;
58769+ goto out;
58770+ }
58771 error = security_path_mkdir(&path, dentry, mode);
58772 if (!error)
58773 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
58774+ if (!error)
58775+ gr_handle_create(dentry, path.mnt);
58776+out:
58777 done_path_create(&path, dentry);
58778 if (retry_estale(error, lookup_flags)) {
58779 lookup_flags |= LOOKUP_REVAL;
58780@@ -3328,6 +3465,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
58781 struct filename *name;
58782 struct dentry *dentry;
58783 struct nameidata nd;
58784+ ino_t saved_ino = 0;
58785+ dev_t saved_dev = 0;
58786 unsigned int lookup_flags = 0;
58787 retry:
58788 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
58789@@ -3360,10 +3499,21 @@ retry:
58790 error = -ENOENT;
58791 goto exit3;
58792 }
58793+
58794+ saved_ino = dentry->d_inode->i_ino;
58795+ saved_dev = gr_get_dev_from_dentry(dentry);
58796+
58797+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
58798+ error = -EACCES;
58799+ goto exit3;
58800+ }
58801+
58802 error = security_path_rmdir(&nd.path, dentry);
58803 if (error)
58804 goto exit3;
58805 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
58806+ if (!error && (saved_dev || saved_ino))
58807+ gr_handle_delete(saved_ino, saved_dev);
58808 exit3:
58809 dput(dentry);
58810 exit2:
58811@@ -3429,6 +3579,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
58812 struct dentry *dentry;
58813 struct nameidata nd;
58814 struct inode *inode = NULL;
58815+ ino_t saved_ino = 0;
58816+ dev_t saved_dev = 0;
58817 unsigned int lookup_flags = 0;
58818 retry:
58819 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
58820@@ -3455,10 +3607,22 @@ retry:
58821 if (!inode)
58822 goto slashes;
58823 ihold(inode);
58824+
58825+ if (inode->i_nlink <= 1) {
58826+ saved_ino = inode->i_ino;
58827+ saved_dev = gr_get_dev_from_dentry(dentry);
58828+ }
58829+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
58830+ error = -EACCES;
58831+ goto exit2;
58832+ }
58833+
58834 error = security_path_unlink(&nd.path, dentry);
58835 if (error)
58836 goto exit2;
58837 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
58838+ if (!error && (saved_ino || saved_dev))
58839+ gr_handle_delete(saved_ino, saved_dev);
58840 exit2:
58841 dput(dentry);
58842 }
58843@@ -3536,9 +3700,17 @@ retry:
58844 if (IS_ERR(dentry))
58845 goto out_putname;
58846
58847+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
58848+ error = -EACCES;
58849+ goto out;
58850+ }
58851+
58852 error = security_path_symlink(&path, dentry, from->name);
58853 if (!error)
58854 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
58855+ if (!error)
58856+ gr_handle_create(dentry, path.mnt);
58857+out:
58858 done_path_create(&path, dentry);
58859 if (retry_estale(error, lookup_flags)) {
58860 lookup_flags |= LOOKUP_REVAL;
58861@@ -3612,6 +3784,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
58862 {
58863 struct dentry *new_dentry;
58864 struct path old_path, new_path;
58865+ struct filename *to = NULL;
58866 int how = 0;
58867 int error;
58868
58869@@ -3635,7 +3808,7 @@ retry:
58870 if (error)
58871 return error;
58872
58873- new_dentry = user_path_create(newdfd, newname, &new_path,
58874+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
58875 (how & LOOKUP_REVAL));
58876 error = PTR_ERR(new_dentry);
58877 if (IS_ERR(new_dentry))
58878@@ -3647,11 +3820,28 @@ retry:
58879 error = may_linkat(&old_path);
58880 if (unlikely(error))
58881 goto out_dput;
58882+
58883+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
58884+ old_path.dentry->d_inode,
58885+ old_path.dentry->d_inode->i_mode, to)) {
58886+ error = -EACCES;
58887+ goto out_dput;
58888+ }
58889+
58890+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
58891+ old_path.dentry, old_path.mnt, to)) {
58892+ error = -EACCES;
58893+ goto out_dput;
58894+ }
58895+
58896 error = security_path_link(old_path.dentry, &new_path, new_dentry);
58897 if (error)
58898 goto out_dput;
58899 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
58900+ if (!error)
58901+ gr_handle_create(new_dentry, new_path.mnt);
58902 out_dput:
58903+ putname(to);
58904 done_path_create(&new_path, new_dentry);
58905 if (retry_estale(error, how)) {
58906 how |= LOOKUP_REVAL;
58907@@ -3897,12 +4087,21 @@ retry:
58908 if (new_dentry == trap)
58909 goto exit5;
58910
58911+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
58912+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
58913+ to);
58914+ if (error)
58915+ goto exit5;
58916+
58917 error = security_path_rename(&oldnd.path, old_dentry,
58918 &newnd.path, new_dentry);
58919 if (error)
58920 goto exit5;
58921 error = vfs_rename(old_dir->d_inode, old_dentry,
58922 new_dir->d_inode, new_dentry);
58923+ if (!error)
58924+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
58925+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
58926 exit5:
58927 dput(new_dentry);
58928 exit4:
58929@@ -3934,6 +4133,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
58930
58931 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
58932 {
58933+ char tmpbuf[64];
58934+ const char *newlink;
58935 int len;
58936
58937 len = PTR_ERR(link);
58938@@ -3943,7 +4144,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
58939 len = strlen(link);
58940 if (len > (unsigned) buflen)
58941 len = buflen;
58942- if (copy_to_user(buffer, link, len))
58943+
58944+ if (len < sizeof(tmpbuf)) {
58945+ memcpy(tmpbuf, link, len);
58946+ newlink = tmpbuf;
58947+ } else
58948+ newlink = link;
58949+
58950+ if (copy_to_user(buffer, newlink, len))
58951 len = -EFAULT;
58952 out:
58953 return len;
58954diff --git a/fs/namespace.c b/fs/namespace.c
58955index a45ba4f..44cfe66 100644
58956--- a/fs/namespace.c
58957+++ b/fs/namespace.c
58958@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
58959 if (!(sb->s_flags & MS_RDONLY))
58960 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
58961 up_write(&sb->s_umount);
58962+
58963+ gr_log_remount(mnt->mnt_devname, retval);
58964+
58965 return retval;
58966 }
58967
58968@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
58969 }
58970 br_write_unlock(&vfsmount_lock);
58971 namespace_unlock();
58972+
58973+ gr_log_unmount(mnt->mnt_devname, retval);
58974+
58975 return retval;
58976 }
58977
58978@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
58979 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
58980 */
58981
58982-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
58983+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
58984 {
58985 struct path path;
58986 struct mount *mnt;
58987@@ -1342,7 +1348,7 @@ out:
58988 /*
58989 * The 2.0 compatible umount. No flags.
58990 */
58991-SYSCALL_DEFINE1(oldumount, char __user *, name)
58992+SYSCALL_DEFINE1(oldumount, const char __user *, name)
58993 {
58994 return sys_umount(name, 0);
58995 }
58996@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
58997 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
58998 MS_STRICTATIME);
58999
59000+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
59001+ retval = -EPERM;
59002+ goto dput_out;
59003+ }
59004+
59005+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
59006+ retval = -EPERM;
59007+ goto dput_out;
59008+ }
59009+
59010 if (flags & MS_REMOUNT)
59011 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
59012 data_page);
59013@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
59014 dev_name, data_page);
59015 dput_out:
59016 path_put(&path);
59017+
59018+ gr_log_mount(dev_name, dir_name, retval);
59019+
59020 return retval;
59021 }
59022
59023@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
59024 * number incrementing at 10Ghz will take 12,427 years to wrap which
59025 * is effectively never, so we can ignore the possibility.
59026 */
59027-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
59028+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
59029
59030 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
59031 {
59032@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
59033 kfree(new_ns);
59034 return ERR_PTR(ret);
59035 }
59036- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
59037+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
59038 atomic_set(&new_ns->count, 1);
59039 new_ns->root = NULL;
59040 INIT_LIST_HEAD(&new_ns->list);
59041@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
59042 }
59043 EXPORT_SYMBOL(mount_subtree);
59044
59045-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
59046- char __user *, type, unsigned long, flags, void __user *, data)
59047+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
59048+ const char __user *, type, unsigned long, flags, void __user *, data)
59049 {
59050 int ret;
59051 char *kernel_type;
59052@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
59053 if (error)
59054 goto out2;
59055
59056+ if (gr_handle_chroot_pivot()) {
59057+ error = -EPERM;
59058+ goto out2;
59059+ }
59060+
59061 get_fs_root(current->fs, &root);
59062 old_mp = lock_mount(&old);
59063 error = PTR_ERR(old_mp);
59064@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
59065 !nsown_capable(CAP_SYS_ADMIN))
59066 return -EPERM;
59067
59068- if (fs->users != 1)
59069+ if (atomic_read(&fs->users) != 1)
59070 return -EINVAL;
59071
59072 get_mnt_ns(mnt_ns);
59073diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
59074index cff089a..4c3d57a 100644
59075--- a/fs/nfs/callback.c
59076+++ b/fs/nfs/callback.c
59077@@ -211,7 +211,6 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
59078 struct svc_rqst *rqstp;
59079 int (*callback_svc)(void *vrqstp);
59080 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
59081- char svc_name[12];
59082 int ret;
59083
59084 nfs_callback_bc_serv(minorversion, xprt, serv);
59085@@ -235,10 +234,9 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
59086
59087 svc_sock_update_bufs(serv);
59088
59089- sprintf(svc_name, "nfsv4.%u-svc", minorversion);
59090 cb_info->serv = serv;
59091 cb_info->rqst = rqstp;
59092- cb_info->task = kthread_run(callback_svc, cb_info->rqst, svc_name);
59093+ cb_info->task = kthread_run(callback_svc, cb_info->rqst, "nfsv4.%u-svc", minorversion);
59094 if (IS_ERR(cb_info->task)) {
59095 ret = PTR_ERR(cb_info->task);
59096 svc_exit_thread(cb_info->rqst);
59097diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
59098index a35582c..ebbdcd5 100644
59099--- a/fs/nfs/callback_xdr.c
59100+++ b/fs/nfs/callback_xdr.c
59101@@ -51,7 +51,7 @@ struct callback_op {
59102 callback_decode_arg_t decode_args;
59103 callback_encode_res_t encode_res;
59104 long res_maxsize;
59105-};
59106+} __do_const;
59107
59108 static struct callback_op callback_ops[];
59109
59110diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
59111index c1c7a9d..7afa0b8 100644
59112--- a/fs/nfs/inode.c
59113+++ b/fs/nfs/inode.c
59114@@ -1043,16 +1043,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
59115 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
59116 }
59117
59118-static atomic_long_t nfs_attr_generation_counter;
59119+static atomic_long_unchecked_t nfs_attr_generation_counter;
59120
59121 static unsigned long nfs_read_attr_generation_counter(void)
59122 {
59123- return atomic_long_read(&nfs_attr_generation_counter);
59124+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
59125 }
59126
59127 unsigned long nfs_inc_attr_generation_counter(void)
59128 {
59129- return atomic_long_inc_return(&nfs_attr_generation_counter);
59130+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
59131 }
59132
59133 void nfs_fattr_init(struct nfs_fattr *fattr)
59134diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
59135index 2c37442..9b9538b 100644
59136--- a/fs/nfs/nfs4state.c
59137+++ b/fs/nfs/nfs4state.c
59138@@ -1193,7 +1193,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp)
59139 snprintf(buf, sizeof(buf), "%s-manager",
59140 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
59141 rcu_read_unlock();
59142- task = kthread_run(nfs4_run_state_manager, clp, buf);
59143+ task = kthread_run(nfs4_run_state_manager, clp, "%s", buf);
59144 if (IS_ERR(task)) {
59145 printk(KERN_ERR "%s: kthread_run: %ld\n",
59146 __func__, PTR_ERR(task));
59147diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
59148index 27d74a2..c4c2a73 100644
59149--- a/fs/nfsd/nfs4proc.c
59150+++ b/fs/nfsd/nfs4proc.c
59151@@ -1126,7 +1126,7 @@ struct nfsd4_operation {
59152 nfsd4op_rsize op_rsize_bop;
59153 stateid_getter op_get_currentstateid;
59154 stateid_setter op_set_currentstateid;
59155-};
59156+} __do_const;
59157
59158 static struct nfsd4_operation nfsd4_ops[];
59159
59160diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
59161index 582321a..0224663 100644
59162--- a/fs/nfsd/nfs4xdr.c
59163+++ b/fs/nfsd/nfs4xdr.c
59164@@ -1458,7 +1458,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
59165
59166 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
59167
59168-static nfsd4_dec nfsd4_dec_ops[] = {
59169+static const nfsd4_dec nfsd4_dec_ops[] = {
59170 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
59171 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
59172 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
59173@@ -1498,7 +1498,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
59174 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
59175 };
59176
59177-static nfsd4_dec nfsd41_dec_ops[] = {
59178+static const nfsd4_dec nfsd41_dec_ops[] = {
59179 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
59180 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
59181 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
59182@@ -1560,7 +1560,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
59183 };
59184
59185 struct nfsd4_minorversion_ops {
59186- nfsd4_dec *decoders;
59187+ const nfsd4_dec *decoders;
59188 int nops;
59189 };
59190
59191diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
59192index e76244e..9fe8f2f1 100644
59193--- a/fs/nfsd/nfscache.c
59194+++ b/fs/nfsd/nfscache.c
59195@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
59196 {
59197 struct svc_cacherep *rp = rqstp->rq_cacherep;
59198 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
59199- int len;
59200+ long len;
59201 size_t bufsize = 0;
59202
59203 if (!rp)
59204 return;
59205
59206- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
59207- len >>= 2;
59208+ if (statp) {
59209+ len = (char*)statp - (char*)resv->iov_base;
59210+ len = resv->iov_len - len;
59211+ len >>= 2;
59212+ }
59213
59214 /* Don't cache excessive amounts of data and XDR failures */
59215 if (!statp || len > (256 >> 2)) {
59216diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
59217index baf149a..76b86ad 100644
59218--- a/fs/nfsd/vfs.c
59219+++ b/fs/nfsd/vfs.c
59220@@ -940,7 +940,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
59221 } else {
59222 oldfs = get_fs();
59223 set_fs(KERNEL_DS);
59224- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
59225+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
59226 set_fs(oldfs);
59227 }
59228
59229@@ -1027,7 +1027,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
59230
59231 /* Write the data. */
59232 oldfs = get_fs(); set_fs(KERNEL_DS);
59233- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
59234+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
59235 set_fs(oldfs);
59236 if (host_err < 0)
59237 goto out_nfserr;
59238@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
59239 */
59240
59241 oldfs = get_fs(); set_fs(KERNEL_DS);
59242- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
59243+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
59244 set_fs(oldfs);
59245
59246 if (host_err < 0)
59247diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
59248index fea6bd5..8ee9d81 100644
59249--- a/fs/nls/nls_base.c
59250+++ b/fs/nls/nls_base.c
59251@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
59252
59253 int register_nls(struct nls_table * nls)
59254 {
59255- struct nls_table ** tmp = &tables;
59256+ struct nls_table *tmp = tables;
59257
59258 if (nls->next)
59259 return -EBUSY;
59260
59261 spin_lock(&nls_lock);
59262- while (*tmp) {
59263- if (nls == *tmp) {
59264+ while (tmp) {
59265+ if (nls == tmp) {
59266 spin_unlock(&nls_lock);
59267 return -EBUSY;
59268 }
59269- tmp = &(*tmp)->next;
59270+ tmp = tmp->next;
59271 }
59272- nls->next = tables;
59273+ pax_open_kernel();
59274+ *(struct nls_table **)&nls->next = tables;
59275+ pax_close_kernel();
59276 tables = nls;
59277 spin_unlock(&nls_lock);
59278 return 0;
59279@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
59280
59281 int unregister_nls(struct nls_table * nls)
59282 {
59283- struct nls_table ** tmp = &tables;
59284+ struct nls_table * const * tmp = &tables;
59285
59286 spin_lock(&nls_lock);
59287 while (*tmp) {
59288 if (nls == *tmp) {
59289- *tmp = nls->next;
59290+ pax_open_kernel();
59291+ *(struct nls_table **)tmp = nls->next;
59292+ pax_close_kernel();
59293 spin_unlock(&nls_lock);
59294 return 0;
59295 }
59296diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
59297index 7424929..35f6be5 100644
59298--- a/fs/nls/nls_euc-jp.c
59299+++ b/fs/nls/nls_euc-jp.c
59300@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
59301 p_nls = load_nls("cp932");
59302
59303 if (p_nls) {
59304- table.charset2upper = p_nls->charset2upper;
59305- table.charset2lower = p_nls->charset2lower;
59306+ pax_open_kernel();
59307+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
59308+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
59309+ pax_close_kernel();
59310 return register_nls(&table);
59311 }
59312
59313diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
59314index e7bc1d7..06bd4bb 100644
59315--- a/fs/nls/nls_koi8-ru.c
59316+++ b/fs/nls/nls_koi8-ru.c
59317@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
59318 p_nls = load_nls("koi8-u");
59319
59320 if (p_nls) {
59321- table.charset2upper = p_nls->charset2upper;
59322- table.charset2lower = p_nls->charset2lower;
59323+ pax_open_kernel();
59324+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
59325+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
59326+ pax_close_kernel();
59327 return register_nls(&table);
59328 }
59329
59330diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
59331index 77cc85d..a1e6299 100644
59332--- a/fs/notify/fanotify/fanotify_user.c
59333+++ b/fs/notify/fanotify/fanotify_user.c
59334@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
59335
59336 fd = fanotify_event_metadata.fd;
59337 ret = -EFAULT;
59338- if (copy_to_user(buf, &fanotify_event_metadata,
59339- fanotify_event_metadata.event_len))
59340+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
59341+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
59342 goto out_close_fd;
59343
59344 ret = prepare_for_access_response(group, event, fd);
59345diff --git a/fs/notify/notification.c b/fs/notify/notification.c
59346index 7b51b05..5ea5ef6 100644
59347--- a/fs/notify/notification.c
59348+++ b/fs/notify/notification.c
59349@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
59350 * get set to 0 so it will never get 'freed'
59351 */
59352 static struct fsnotify_event *q_overflow_event;
59353-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
59354+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
59355
59356 /**
59357 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
59358@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
59359 */
59360 u32 fsnotify_get_cookie(void)
59361 {
59362- return atomic_inc_return(&fsnotify_sync_cookie);
59363+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
59364 }
59365 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
59366
59367diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
59368index aa411c3..c260a84 100644
59369--- a/fs/ntfs/dir.c
59370+++ b/fs/ntfs/dir.c
59371@@ -1329,7 +1329,7 @@ find_next_index_buffer:
59372 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
59373 ~(s64)(ndir->itype.index.block_size - 1)));
59374 /* Bounds checks. */
59375- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
59376+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
59377 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
59378 "inode 0x%lx or driver bug.", vdir->i_ino);
59379 goto err_out;
59380diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
59381index c5670b8..2b43d9b 100644
59382--- a/fs/ntfs/file.c
59383+++ b/fs/ntfs/file.c
59384@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
59385 char *addr;
59386 size_t total = 0;
59387 unsigned len;
59388- int left;
59389+ unsigned left;
59390
59391 do {
59392 len = PAGE_CACHE_SIZE - ofs;
59393@@ -2241,6 +2241,6 @@ const struct inode_operations ntfs_file_inode_ops = {
59394 #endif /* NTFS_RW */
59395 };
59396
59397-const struct file_operations ntfs_empty_file_ops = {};
59398+const struct file_operations ntfs_empty_file_ops __read_only;
59399
59400-const struct inode_operations ntfs_empty_inode_ops = {};
59401+const struct inode_operations ntfs_empty_inode_ops __read_only;
59402diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
59403index 82650d5..db37dcf 100644
59404--- a/fs/ntfs/super.c
59405+++ b/fs/ntfs/super.c
59406@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
59407 if (!silent)
59408 ntfs_error(sb, "Primary boot sector is invalid.");
59409 } else if (!silent)
59410- ntfs_error(sb, read_err_str, "primary");
59411+ ntfs_error(sb, read_err_str, "%s", "primary");
59412 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
59413 if (bh_primary)
59414 brelse(bh_primary);
59415@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
59416 goto hotfix_primary_boot_sector;
59417 brelse(bh_backup);
59418 } else if (!silent)
59419- ntfs_error(sb, read_err_str, "backup");
59420+ ntfs_error(sb, read_err_str, "%s", "backup");
59421 /* Try to read NT3.51- backup boot sector. */
59422 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
59423 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
59424@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
59425 "sector.");
59426 brelse(bh_backup);
59427 } else if (!silent)
59428- ntfs_error(sb, read_err_str, "backup");
59429+ ntfs_error(sb, read_err_str, "%s", "backup");
59430 /* We failed. Cleanup and return. */
59431 if (bh_primary)
59432 brelse(bh_primary);
59433diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
59434index 20dfec7..e238cb7 100644
59435--- a/fs/ocfs2/aops.c
59436+++ b/fs/ocfs2/aops.c
59437@@ -1756,7 +1756,7 @@ try_again:
59438 goto out;
59439 } else if (ret == 1) {
59440 clusters_need = wc->w_clen;
59441- ret = ocfs2_refcount_cow(inode, filp, di_bh,
59442+ ret = ocfs2_refcount_cow(inode, di_bh,
59443 wc->w_cpos, wc->w_clen, UINT_MAX);
59444 if (ret) {
59445 mlog_errno(ret);
59446diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
59447index ff54014..ff125fd 100644
59448--- a/fs/ocfs2/file.c
59449+++ b/fs/ocfs2/file.c
59450@@ -370,7 +370,7 @@ static int ocfs2_cow_file_pos(struct inode *inode,
59451 if (!(ext_flags & OCFS2_EXT_REFCOUNTED))
59452 goto out;
59453
59454- return ocfs2_refcount_cow(inode, NULL, fe_bh, cpos, 1, cpos+1);
59455+ return ocfs2_refcount_cow(inode, fe_bh, cpos, 1, cpos+1);
59456
59457 out:
59458 return status;
59459@@ -899,7 +899,7 @@ static int ocfs2_zero_extend_get_range(struct inode *inode,
59460 zero_clusters = last_cpos - zero_cpos;
59461
59462 if (needs_cow) {
59463- rc = ocfs2_refcount_cow(inode, NULL, di_bh, zero_cpos,
59464+ rc = ocfs2_refcount_cow(inode, di_bh, zero_cpos,
59465 zero_clusters, UINT_MAX);
59466 if (rc) {
59467 mlog_errno(rc);
59468@@ -2078,7 +2078,7 @@ static int ocfs2_prepare_inode_for_refcount(struct inode *inode,
59469
59470 *meta_level = 1;
59471
59472- ret = ocfs2_refcount_cow(inode, file, di_bh, cpos, clusters, UINT_MAX);
59473+ ret = ocfs2_refcount_cow(inode, di_bh, cpos, clusters, UINT_MAX);
59474 if (ret)
59475 mlog_errno(ret);
59476 out:
59477diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
59478index aebeacd..0dcdd26 100644
59479--- a/fs/ocfs2/localalloc.c
59480+++ b/fs/ocfs2/localalloc.c
59481@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
59482 goto bail;
59483 }
59484
59485- atomic_inc(&osb->alloc_stats.moves);
59486+ atomic_inc_unchecked(&osb->alloc_stats.moves);
59487
59488 bail:
59489 if (handle)
59490diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
59491index f1fc172..452068b 100644
59492--- a/fs/ocfs2/move_extents.c
59493+++ b/fs/ocfs2/move_extents.c
59494@@ -69,7 +69,7 @@ static int __ocfs2_move_extent(handle_t *handle,
59495 u64 ino = ocfs2_metadata_cache_owner(context->et.et_ci);
59496 u64 old_blkno = ocfs2_clusters_to_blocks(inode->i_sb, p_cpos);
59497
59498- ret = ocfs2_duplicate_clusters_by_page(handle, context->file, cpos,
59499+ ret = ocfs2_duplicate_clusters_by_page(handle, inode, cpos,
59500 p_cpos, new_p_cpos, len);
59501 if (ret) {
59502 mlog_errno(ret);
59503diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
59504index d355e6e..578d905 100644
59505--- a/fs/ocfs2/ocfs2.h
59506+++ b/fs/ocfs2/ocfs2.h
59507@@ -235,11 +235,11 @@ enum ocfs2_vol_state
59508
59509 struct ocfs2_alloc_stats
59510 {
59511- atomic_t moves;
59512- atomic_t local_data;
59513- atomic_t bitmap_data;
59514- atomic_t bg_allocs;
59515- atomic_t bg_extends;
59516+ atomic_unchecked_t moves;
59517+ atomic_unchecked_t local_data;
59518+ atomic_unchecked_t bitmap_data;
59519+ atomic_unchecked_t bg_allocs;
59520+ atomic_unchecked_t bg_extends;
59521 };
59522
59523 enum ocfs2_local_alloc_state
59524diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
59525index 998b17e..aefe414 100644
59526--- a/fs/ocfs2/refcounttree.c
59527+++ b/fs/ocfs2/refcounttree.c
59528@@ -49,7 +49,6 @@
59529
59530 struct ocfs2_cow_context {
59531 struct inode *inode;
59532- struct file *file;
59533 u32 cow_start;
59534 u32 cow_len;
59535 struct ocfs2_extent_tree data_et;
59536@@ -66,7 +65,7 @@ struct ocfs2_cow_context {
59537 u32 *num_clusters,
59538 unsigned int *extent_flags);
59539 int (*cow_duplicate_clusters)(handle_t *handle,
59540- struct file *file,
59541+ struct inode *inode,
59542 u32 cpos, u32 old_cluster,
59543 u32 new_cluster, u32 new_len);
59544 };
59545@@ -2922,14 +2921,12 @@ static int ocfs2_clear_cow_buffer(handle_t *handle, struct buffer_head *bh)
59546 }
59547
59548 int ocfs2_duplicate_clusters_by_page(handle_t *handle,
59549- struct file *file,
59550+ struct inode *inode,
59551 u32 cpos, u32 old_cluster,
59552 u32 new_cluster, u32 new_len)
59553 {
59554 int ret = 0, partial;
59555- struct inode *inode = file_inode(file);
59556- struct ocfs2_caching_info *ci = INODE_CACHE(inode);
59557- struct super_block *sb = ocfs2_metadata_cache_get_super(ci);
59558+ struct super_block *sb = inode->i_sb;
59559 u64 new_block = ocfs2_clusters_to_blocks(sb, new_cluster);
59560 struct page *page;
59561 pgoff_t page_index;
59562@@ -2973,13 +2970,6 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
59563 if (PAGE_CACHE_SIZE <= OCFS2_SB(sb)->s_clustersize)
59564 BUG_ON(PageDirty(page));
59565
59566- if (PageReadahead(page)) {
59567- page_cache_async_readahead(mapping,
59568- &file->f_ra, file,
59569- page, page_index,
59570- readahead_pages);
59571- }
59572-
59573 if (!PageUptodate(page)) {
59574 ret = block_read_full_page(page, ocfs2_get_block);
59575 if (ret) {
59576@@ -2999,7 +2989,8 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
59577 }
59578 }
59579
59580- ocfs2_map_and_dirty_page(inode, handle, from, to,
59581+ ocfs2_map_and_dirty_page(inode,
59582+ handle, from, to,
59583 page, 0, &new_block);
59584 mark_page_accessed(page);
59585 unlock:
59586@@ -3015,12 +3006,11 @@ unlock:
59587 }
59588
59589 int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
59590- struct file *file,
59591+ struct inode *inode,
59592 u32 cpos, u32 old_cluster,
59593 u32 new_cluster, u32 new_len)
59594 {
59595 int ret = 0;
59596- struct inode *inode = file_inode(file);
59597 struct super_block *sb = inode->i_sb;
59598 struct ocfs2_caching_info *ci = INODE_CACHE(inode);
59599 int i, blocks = ocfs2_clusters_to_blocks(sb, new_len);
59600@@ -3145,7 +3135,7 @@ static int ocfs2_replace_clusters(handle_t *handle,
59601
59602 /*If the old clusters is unwritten, no need to duplicate. */
59603 if (!(ext_flags & OCFS2_EXT_UNWRITTEN)) {
59604- ret = context->cow_duplicate_clusters(handle, context->file,
59605+ ret = context->cow_duplicate_clusters(handle, context->inode,
59606 cpos, old, new, len);
59607 if (ret) {
59608 mlog_errno(ret);
59609@@ -3423,35 +3413,12 @@ static int ocfs2_replace_cow(struct ocfs2_cow_context *context)
59610 return ret;
59611 }
59612
59613-static void ocfs2_readahead_for_cow(struct inode *inode,
59614- struct file *file,
59615- u32 start, u32 len)
59616-{
59617- struct address_space *mapping;
59618- pgoff_t index;
59619- unsigned long num_pages;
59620- int cs_bits = OCFS2_SB(inode->i_sb)->s_clustersize_bits;
59621-
59622- if (!file)
59623- return;
59624-
59625- mapping = file->f_mapping;
59626- num_pages = (len << cs_bits) >> PAGE_CACHE_SHIFT;
59627- if (!num_pages)
59628- num_pages = 1;
59629-
59630- index = ((loff_t)start << cs_bits) >> PAGE_CACHE_SHIFT;
59631- page_cache_sync_readahead(mapping, &file->f_ra, file,
59632- index, num_pages);
59633-}
59634-
59635 /*
59636 * Starting at cpos, try to CoW write_len clusters. Don't CoW
59637 * past max_cpos. This will stop when it runs into a hole or an
59638 * unrefcounted extent.
59639 */
59640 static int ocfs2_refcount_cow_hunk(struct inode *inode,
59641- struct file *file,
59642 struct buffer_head *di_bh,
59643 u32 cpos, u32 write_len, u32 max_cpos)
59644 {
59645@@ -3480,8 +3447,6 @@ static int ocfs2_refcount_cow_hunk(struct inode *inode,
59646
59647 BUG_ON(cow_len == 0);
59648
59649- ocfs2_readahead_for_cow(inode, file, cow_start, cow_len);
59650-
59651 context = kzalloc(sizeof(struct ocfs2_cow_context), GFP_NOFS);
59652 if (!context) {
59653 ret = -ENOMEM;
59654@@ -3503,7 +3468,6 @@ static int ocfs2_refcount_cow_hunk(struct inode *inode,
59655 context->ref_root_bh = ref_root_bh;
59656 context->cow_duplicate_clusters = ocfs2_duplicate_clusters_by_page;
59657 context->get_clusters = ocfs2_di_get_clusters;
59658- context->file = file;
59659
59660 ocfs2_init_dinode_extent_tree(&context->data_et,
59661 INODE_CACHE(inode), di_bh);
59662@@ -3532,7 +3496,6 @@ out:
59663 * clusters between cpos and cpos+write_len are safe to modify.
59664 */
59665 int ocfs2_refcount_cow(struct inode *inode,
59666- struct file *file,
59667 struct buffer_head *di_bh,
59668 u32 cpos, u32 write_len, u32 max_cpos)
59669 {
59670@@ -3552,7 +3515,7 @@ int ocfs2_refcount_cow(struct inode *inode,
59671 num_clusters = write_len;
59672
59673 if (ext_flags & OCFS2_EXT_REFCOUNTED) {
59674- ret = ocfs2_refcount_cow_hunk(inode, file, di_bh, cpos,
59675+ ret = ocfs2_refcount_cow_hunk(inode, di_bh, cpos,
59676 num_clusters, max_cpos);
59677 if (ret) {
59678 mlog_errno(ret);
59679diff --git a/fs/ocfs2/refcounttree.h b/fs/ocfs2/refcounttree.h
59680index 7754608..6422bbcdb 100644
59681--- a/fs/ocfs2/refcounttree.h
59682+++ b/fs/ocfs2/refcounttree.h
59683@@ -53,7 +53,7 @@ int ocfs2_prepare_refcount_change_for_del(struct inode *inode,
59684 int *credits,
59685 int *ref_blocks);
59686 int ocfs2_refcount_cow(struct inode *inode,
59687- struct file *filep, struct buffer_head *di_bh,
59688+ struct buffer_head *di_bh,
59689 u32 cpos, u32 write_len, u32 max_cpos);
59690
59691 typedef int (ocfs2_post_refcount_func)(struct inode *inode,
59692@@ -85,11 +85,11 @@ int ocfs2_refcount_cow_xattr(struct inode *inode,
59693 u32 cpos, u32 write_len,
59694 struct ocfs2_post_refcount *post);
59695 int ocfs2_duplicate_clusters_by_page(handle_t *handle,
59696- struct file *file,
59697+ struct inode *inode,
59698 u32 cpos, u32 old_cluster,
59699 u32 new_cluster, u32 new_len);
59700 int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
59701- struct file *file,
59702+ struct inode *inode,
59703 u32 cpos, u32 old_cluster,
59704 u32 new_cluster, u32 new_len);
59705 int ocfs2_cow_sync_writeback(struct super_block *sb,
59706diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
59707index b7e74b5..19c6536 100644
59708--- a/fs/ocfs2/suballoc.c
59709+++ b/fs/ocfs2/suballoc.c
59710@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
59711 mlog_errno(status);
59712 goto bail;
59713 }
59714- atomic_inc(&osb->alloc_stats.bg_extends);
59715+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
59716
59717 /* You should never ask for this much metadata */
59718 BUG_ON(bits_wanted >
59719@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
59720 mlog_errno(status);
59721 goto bail;
59722 }
59723- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59724+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59725
59726 *suballoc_loc = res.sr_bg_blkno;
59727 *suballoc_bit_start = res.sr_bit_offset;
59728@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
59729 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
59730 res->sr_bits);
59731
59732- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59733+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59734
59735 BUG_ON(res->sr_bits != 1);
59736
59737@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
59738 mlog_errno(status);
59739 goto bail;
59740 }
59741- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59742+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59743
59744 BUG_ON(res.sr_bits != 1);
59745
59746@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
59747 cluster_start,
59748 num_clusters);
59749 if (!status)
59750- atomic_inc(&osb->alloc_stats.local_data);
59751+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
59752 } else {
59753 if (min_clusters > (osb->bitmap_cpg - 1)) {
59754 /* The only paths asking for contiguousness
59755@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
59756 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
59757 res.sr_bg_blkno,
59758 res.sr_bit_offset);
59759- atomic_inc(&osb->alloc_stats.bitmap_data);
59760+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
59761 *num_clusters = res.sr_bits;
59762 }
59763 }
59764diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
59765index 01b8516..579c4df 100644
59766--- a/fs/ocfs2/super.c
59767+++ b/fs/ocfs2/super.c
59768@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
59769 "%10s => GlobalAllocs: %d LocalAllocs: %d "
59770 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
59771 "Stats",
59772- atomic_read(&osb->alloc_stats.bitmap_data),
59773- atomic_read(&osb->alloc_stats.local_data),
59774- atomic_read(&osb->alloc_stats.bg_allocs),
59775- atomic_read(&osb->alloc_stats.moves),
59776- atomic_read(&osb->alloc_stats.bg_extends));
59777+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
59778+ atomic_read_unchecked(&osb->alloc_stats.local_data),
59779+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
59780+ atomic_read_unchecked(&osb->alloc_stats.moves),
59781+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
59782
59783 out += snprintf(buf + out, len - out,
59784 "%10s => State: %u Descriptor: %llu Size: %u bits "
59785@@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
59786 spin_lock_init(&osb->osb_xattr_lock);
59787 ocfs2_init_steal_slots(osb);
59788
59789- atomic_set(&osb->alloc_stats.moves, 0);
59790- atomic_set(&osb->alloc_stats.local_data, 0);
59791- atomic_set(&osb->alloc_stats.bitmap_data, 0);
59792- atomic_set(&osb->alloc_stats.bg_allocs, 0);
59793- atomic_set(&osb->alloc_stats.bg_extends, 0);
59794+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
59795+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
59796+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
59797+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
59798+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
59799
59800 /* Copy the blockcheck stats from the superblock probe */
59801 osb->osb_ecc_stats = *stats;
59802diff --git a/fs/open.c b/fs/open.c
59803index 8c74100..4239c48 100644
59804--- a/fs/open.c
59805+++ b/fs/open.c
59806@@ -32,6 +32,8 @@
59807 #include <linux/dnotify.h>
59808 #include <linux/compat.h>
59809
59810+#define CREATE_TRACE_POINTS
59811+#include <trace/events/fs.h>
59812 #include "internal.h"
59813
59814 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
59815@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
59816 error = locks_verify_truncate(inode, NULL, length);
59817 if (!error)
59818 error = security_path_truncate(path);
59819+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
59820+ error = -EACCES;
59821 if (!error)
59822 error = do_truncate(path->dentry, length, 0, NULL);
59823
59824@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
59825 error = locks_verify_truncate(inode, f.file, length);
59826 if (!error)
59827 error = security_path_truncate(&f.file->f_path);
59828+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
59829+ error = -EACCES;
59830 if (!error)
59831 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
59832 sb_end_write(inode->i_sb);
59833@@ -360,6 +366,9 @@ retry:
59834 if (__mnt_is_readonly(path.mnt))
59835 res = -EROFS;
59836
59837+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
59838+ res = -EACCES;
59839+
59840 out_path_release:
59841 path_put(&path);
59842 if (retry_estale(res, lookup_flags)) {
59843@@ -391,6 +400,8 @@ retry:
59844 if (error)
59845 goto dput_and_out;
59846
59847+ gr_log_chdir(path.dentry, path.mnt);
59848+
59849 set_fs_pwd(current->fs, &path);
59850
59851 dput_and_out:
59852@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
59853 goto out_putf;
59854
59855 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
59856+
59857+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
59858+ error = -EPERM;
59859+
59860+ if (!error)
59861+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
59862+
59863 if (!error)
59864 set_fs_pwd(current->fs, &f.file->f_path);
59865 out_putf:
59866@@ -449,7 +467,13 @@ retry:
59867 if (error)
59868 goto dput_and_out;
59869
59870+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
59871+ goto dput_and_out;
59872+
59873 set_fs_root(current->fs, &path);
59874+
59875+ gr_handle_chroot_chdir(&path);
59876+
59877 error = 0;
59878 dput_and_out:
59879 path_put(&path);
59880@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
59881 if (error)
59882 return error;
59883 mutex_lock(&inode->i_mutex);
59884+
59885+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
59886+ error = -EACCES;
59887+ goto out_unlock;
59888+ }
59889+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
59890+ error = -EACCES;
59891+ goto out_unlock;
59892+ }
59893+
59894 error = security_path_chmod(path, mode);
59895 if (error)
59896 goto out_unlock;
59897@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
59898 uid = make_kuid(current_user_ns(), user);
59899 gid = make_kgid(current_user_ns(), group);
59900
59901+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
59902+ return -EACCES;
59903+
59904 newattrs.ia_valid = ATTR_CTIME;
59905 if (user != (uid_t) -1) {
59906 if (!uid_valid(uid))
59907@@ -946,6 +983,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
59908 } else {
59909 fsnotify_open(f);
59910 fd_install(fd, f);
59911+ trace_do_sys_open(tmp->name, flags, mode);
59912 }
59913 }
59914 putname(tmp);
59915diff --git a/fs/pipe.c b/fs/pipe.c
59916index d2c45e1..009fe1c 100644
59917--- a/fs/pipe.c
59918+++ b/fs/pipe.c
59919@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
59920
59921 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
59922 {
59923- if (pipe->files)
59924+ if (atomic_read(&pipe->files))
59925 mutex_lock_nested(&pipe->mutex, subclass);
59926 }
59927
59928@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
59929
59930 void pipe_unlock(struct pipe_inode_info *pipe)
59931 {
59932- if (pipe->files)
59933+ if (atomic_read(&pipe->files))
59934 mutex_unlock(&pipe->mutex);
59935 }
59936 EXPORT_SYMBOL(pipe_unlock);
59937@@ -449,9 +449,9 @@ redo:
59938 }
59939 if (bufs) /* More to do? */
59940 continue;
59941- if (!pipe->writers)
59942+ if (!atomic_read(&pipe->writers))
59943 break;
59944- if (!pipe->waiting_writers) {
59945+ if (!atomic_read(&pipe->waiting_writers)) {
59946 /* syscall merging: Usually we must not sleep
59947 * if O_NONBLOCK is set, or if we got some data.
59948 * But if a writer sleeps in kernel space, then
59949@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
59950 ret = 0;
59951 __pipe_lock(pipe);
59952
59953- if (!pipe->readers) {
59954+ if (!atomic_read(&pipe->readers)) {
59955 send_sig(SIGPIPE, current, 0);
59956 ret = -EPIPE;
59957 goto out;
59958@@ -562,7 +562,7 @@ redo1:
59959 for (;;) {
59960 int bufs;
59961
59962- if (!pipe->readers) {
59963+ if (!atomic_read(&pipe->readers)) {
59964 send_sig(SIGPIPE, current, 0);
59965 if (!ret)
59966 ret = -EPIPE;
59967@@ -653,9 +653,9 @@ redo2:
59968 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
59969 do_wakeup = 0;
59970 }
59971- pipe->waiting_writers++;
59972+ atomic_inc(&pipe->waiting_writers);
59973 pipe_wait(pipe);
59974- pipe->waiting_writers--;
59975+ atomic_dec(&pipe->waiting_writers);
59976 }
59977 out:
59978 __pipe_unlock(pipe);
59979@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
59980 mask = 0;
59981 if (filp->f_mode & FMODE_READ) {
59982 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
59983- if (!pipe->writers && filp->f_version != pipe->w_counter)
59984+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
59985 mask |= POLLHUP;
59986 }
59987
59988@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
59989 * Most Unices do not set POLLERR for FIFOs but on Linux they
59990 * behave exactly like pipes for poll().
59991 */
59992- if (!pipe->readers)
59993+ if (!atomic_read(&pipe->readers))
59994 mask |= POLLERR;
59995 }
59996
59997@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
59998
59999 __pipe_lock(pipe);
60000 if (file->f_mode & FMODE_READ)
60001- pipe->readers--;
60002+ atomic_dec(&pipe->readers);
60003 if (file->f_mode & FMODE_WRITE)
60004- pipe->writers--;
60005+ atomic_dec(&pipe->writers);
60006
60007- if (pipe->readers || pipe->writers) {
60008+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
60009 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
60010 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60011 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
60012 }
60013 spin_lock(&inode->i_lock);
60014- if (!--pipe->files) {
60015+ if (atomic_dec_and_test(&pipe->files)) {
60016 inode->i_pipe = NULL;
60017 kill = 1;
60018 }
60019@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
60020 kfree(pipe);
60021 }
60022
60023-static struct vfsmount *pipe_mnt __read_mostly;
60024+struct vfsmount *pipe_mnt __read_mostly;
60025
60026 /*
60027 * pipefs_dname() is called from d_path().
60028@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
60029 goto fail_iput;
60030
60031 inode->i_pipe = pipe;
60032- pipe->files = 2;
60033- pipe->readers = pipe->writers = 1;
60034+ atomic_set(&pipe->files, 2);
60035+ atomic_set(&pipe->readers, 1);
60036+ atomic_set(&pipe->writers, 1);
60037 inode->i_fop = &pipefifo_fops;
60038
60039 /*
60040@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
60041 spin_lock(&inode->i_lock);
60042 if (inode->i_pipe) {
60043 pipe = inode->i_pipe;
60044- pipe->files++;
60045+ atomic_inc(&pipe->files);
60046 spin_unlock(&inode->i_lock);
60047 } else {
60048 spin_unlock(&inode->i_lock);
60049 pipe = alloc_pipe_info();
60050 if (!pipe)
60051 return -ENOMEM;
60052- pipe->files = 1;
60053+ atomic_set(&pipe->files, 1);
60054 spin_lock(&inode->i_lock);
60055 if (unlikely(inode->i_pipe)) {
60056- inode->i_pipe->files++;
60057+ atomic_inc(&inode->i_pipe->files);
60058 spin_unlock(&inode->i_lock);
60059 free_pipe_info(pipe);
60060 pipe = inode->i_pipe;
60061@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
60062 * opened, even when there is no process writing the FIFO.
60063 */
60064 pipe->r_counter++;
60065- if (pipe->readers++ == 0)
60066+ if (atomic_inc_return(&pipe->readers) == 1)
60067 wake_up_partner(pipe);
60068
60069- if (!is_pipe && !pipe->writers) {
60070+ if (!is_pipe && !atomic_read(&pipe->writers)) {
60071 if ((filp->f_flags & O_NONBLOCK)) {
60072 /* suppress POLLHUP until we have
60073 * seen a writer */
60074@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
60075 * errno=ENXIO when there is no process reading the FIFO.
60076 */
60077 ret = -ENXIO;
60078- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
60079+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
60080 goto err;
60081
60082 pipe->w_counter++;
60083- if (!pipe->writers++)
60084+ if (atomic_inc_return(&pipe->writers) == 1)
60085 wake_up_partner(pipe);
60086
60087- if (!is_pipe && !pipe->readers) {
60088+ if (!is_pipe && !atomic_read(&pipe->readers)) {
60089 if (wait_for_partner(pipe, &pipe->r_counter))
60090 goto err_wr;
60091 }
60092@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
60093 * the process can at least talk to itself.
60094 */
60095
60096- pipe->readers++;
60097- pipe->writers++;
60098+ atomic_inc(&pipe->readers);
60099+ atomic_inc(&pipe->writers);
60100 pipe->r_counter++;
60101 pipe->w_counter++;
60102- if (pipe->readers == 1 || pipe->writers == 1)
60103+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
60104 wake_up_partner(pipe);
60105 break;
60106
60107@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
60108 return 0;
60109
60110 err_rd:
60111- if (!--pipe->readers)
60112+ if (atomic_dec_and_test(&pipe->readers))
60113 wake_up_interruptible(&pipe->wait);
60114 ret = -ERESTARTSYS;
60115 goto err;
60116
60117 err_wr:
60118- if (!--pipe->writers)
60119+ if (atomic_dec_and_test(&pipe->writers))
60120 wake_up_interruptible(&pipe->wait);
60121 ret = -ERESTARTSYS;
60122 goto err;
60123
60124 err:
60125 spin_lock(&inode->i_lock);
60126- if (!--pipe->files) {
60127+ if (atomic_dec_and_test(&pipe->files)) {
60128 inode->i_pipe = NULL;
60129 kill = 1;
60130 }
60131diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
60132index 15af622..0e9f4467 100644
60133--- a/fs/proc/Kconfig
60134+++ b/fs/proc/Kconfig
60135@@ -30,12 +30,12 @@ config PROC_FS
60136
60137 config PROC_KCORE
60138 bool "/proc/kcore support" if !ARM
60139- depends on PROC_FS && MMU
60140+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
60141
60142 config PROC_VMCORE
60143 bool "/proc/vmcore support"
60144- depends on PROC_FS && CRASH_DUMP
60145- default y
60146+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
60147+ default n
60148 help
60149 Exports the dump image of crashed kernel in ELF format.
60150
60151@@ -59,8 +59,8 @@ config PROC_SYSCTL
60152 limited in memory.
60153
60154 config PROC_PAGE_MONITOR
60155- default y
60156- depends on PROC_FS && MMU
60157+ default n
60158+ depends on PROC_FS && MMU && !GRKERNSEC
60159 bool "Enable /proc page monitoring" if EXPERT
60160 help
60161 Various /proc files exist to monitor process memory utilization:
60162diff --git a/fs/proc/array.c b/fs/proc/array.c
60163index cbd0f1b..adec3f0 100644
60164--- a/fs/proc/array.c
60165+++ b/fs/proc/array.c
60166@@ -60,6 +60,7 @@
60167 #include <linux/tty.h>
60168 #include <linux/string.h>
60169 #include <linux/mman.h>
60170+#include <linux/grsecurity.h>
60171 #include <linux/proc_fs.h>
60172 #include <linux/ioport.h>
60173 #include <linux/uaccess.h>
60174@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
60175 seq_putc(m, '\n');
60176 }
60177
60178+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60179+static inline void task_pax(struct seq_file *m, struct task_struct *p)
60180+{
60181+ if (p->mm)
60182+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
60183+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
60184+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
60185+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
60186+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
60187+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
60188+ else
60189+ seq_printf(m, "PaX:\t-----\n");
60190+}
60191+#endif
60192+
60193 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
60194 struct pid *pid, struct task_struct *task)
60195 {
60196@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
60197 task_cpus_allowed(m, task);
60198 cpuset_task_status_allowed(m, task);
60199 task_context_switch_counts(m, task);
60200+
60201+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60202+ task_pax(m, task);
60203+#endif
60204+
60205+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
60206+ task_grsec_rbac(m, task);
60207+#endif
60208+
60209 return 0;
60210 }
60211
60212+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60213+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
60214+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
60215+ _mm->pax_flags & MF_PAX_SEGMEXEC))
60216+#endif
60217+
60218 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60219 struct pid *pid, struct task_struct *task, int whole)
60220 {
60221@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60222 char tcomm[sizeof(task->comm)];
60223 unsigned long flags;
60224
60225+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60226+ if (current->exec_id != m->exec_id) {
60227+ gr_log_badprocpid("stat");
60228+ return 0;
60229+ }
60230+#endif
60231+
60232 state = *get_task_state(task);
60233 vsize = eip = esp = 0;
60234 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
60235@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60236 gtime = task_gtime(task);
60237 }
60238
60239+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60240+ if (PAX_RAND_FLAGS(mm)) {
60241+ eip = 0;
60242+ esp = 0;
60243+ wchan = 0;
60244+ }
60245+#endif
60246+#ifdef CONFIG_GRKERNSEC_HIDESYM
60247+ wchan = 0;
60248+ eip =0;
60249+ esp =0;
60250+#endif
60251+
60252 /* scale priority and nice values from timeslices to -20..20 */
60253 /* to make it look like a "normal" Unix priority/nice value */
60254 priority = task_prio(task);
60255@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60256 seq_put_decimal_ull(m, ' ', vsize);
60257 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
60258 seq_put_decimal_ull(m, ' ', rsslim);
60259+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60260+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
60261+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
60262+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
60263+#else
60264 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
60265 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
60266 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
60267+#endif
60268 seq_put_decimal_ull(m, ' ', esp);
60269 seq_put_decimal_ull(m, ' ', eip);
60270 /* The signal information here is obsolete.
60271@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60272 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
60273 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
60274
60275- if (mm && permitted) {
60276+ if (mm && permitted
60277+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60278+ && !PAX_RAND_FLAGS(mm)
60279+#endif
60280+ ) {
60281 seq_put_decimal_ull(m, ' ', mm->start_data);
60282 seq_put_decimal_ull(m, ' ', mm->end_data);
60283 seq_put_decimal_ull(m, ' ', mm->start_brk);
60284@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
60285 struct pid *pid, struct task_struct *task)
60286 {
60287 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
60288- struct mm_struct *mm = get_task_mm(task);
60289+ struct mm_struct *mm;
60290
60291+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60292+ if (current->exec_id != m->exec_id) {
60293+ gr_log_badprocpid("statm");
60294+ return 0;
60295+ }
60296+#endif
60297+ mm = get_task_mm(task);
60298 if (mm) {
60299 size = task_statm(mm, &shared, &text, &data, &resident);
60300 mmput(mm);
60301@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
60302 return 0;
60303 }
60304
60305+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60306+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
60307+{
60308+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
60309+}
60310+#endif
60311+
60312 #ifdef CONFIG_CHECKPOINT_RESTORE
60313 static struct pid *
60314 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
60315diff --git a/fs/proc/base.c b/fs/proc/base.c
60316index c3834da..b402b2b 100644
60317--- a/fs/proc/base.c
60318+++ b/fs/proc/base.c
60319@@ -113,6 +113,14 @@ struct pid_entry {
60320 union proc_op op;
60321 };
60322
60323+struct getdents_callback {
60324+ struct linux_dirent __user * current_dir;
60325+ struct linux_dirent __user * previous;
60326+ struct file * file;
60327+ int count;
60328+ int error;
60329+};
60330+
60331 #define NOD(NAME, MODE, IOP, FOP, OP) { \
60332 .name = (NAME), \
60333 .len = sizeof(NAME) - 1, \
60334@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
60335 if (!mm->arg_end)
60336 goto out_mm; /* Shh! No looking before we're done */
60337
60338+ if (gr_acl_handle_procpidmem(task))
60339+ goto out_mm;
60340+
60341 len = mm->arg_end - mm->arg_start;
60342
60343 if (len > PAGE_SIZE)
60344@@ -237,12 +248,28 @@ out:
60345 return res;
60346 }
60347
60348+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60349+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
60350+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
60351+ _mm->pax_flags & MF_PAX_SEGMEXEC))
60352+#endif
60353+
60354 static int proc_pid_auxv(struct task_struct *task, char *buffer)
60355 {
60356 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
60357 int res = PTR_ERR(mm);
60358 if (mm && !IS_ERR(mm)) {
60359 unsigned int nwords = 0;
60360+
60361+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60362+ /* allow if we're currently ptracing this task */
60363+ if (PAX_RAND_FLAGS(mm) &&
60364+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
60365+ mmput(mm);
60366+ return 0;
60367+ }
60368+#endif
60369+
60370 do {
60371 nwords += 2;
60372 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
60373@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
60374 }
60375
60376
60377-#ifdef CONFIG_KALLSYMS
60378+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60379 /*
60380 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
60381 * Returns the resolved symbol. If that fails, simply return the address.
60382@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
60383 mutex_unlock(&task->signal->cred_guard_mutex);
60384 }
60385
60386-#ifdef CONFIG_STACKTRACE
60387+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60388
60389 #define MAX_STACK_TRACE_DEPTH 64
60390
60391@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
60392 return count;
60393 }
60394
60395-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60396+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60397 static int proc_pid_syscall(struct task_struct *task, char *buffer)
60398 {
60399 long nr;
60400@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
60401 /************************************************************************/
60402
60403 /* permission checks */
60404-static int proc_fd_access_allowed(struct inode *inode)
60405+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
60406 {
60407 struct task_struct *task;
60408 int allowed = 0;
60409@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
60410 */
60411 task = get_proc_task(inode);
60412 if (task) {
60413- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
60414+ if (log)
60415+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
60416+ else
60417+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
60418 put_task_struct(task);
60419 }
60420 return allowed;
60421@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
60422 struct task_struct *task,
60423 int hide_pid_min)
60424 {
60425+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60426+ return false;
60427+
60428+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60429+ rcu_read_lock();
60430+ {
60431+ const struct cred *tmpcred = current_cred();
60432+ const struct cred *cred = __task_cred(task);
60433+
60434+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
60435+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60436+ || in_group_p(grsec_proc_gid)
60437+#endif
60438+ ) {
60439+ rcu_read_unlock();
60440+ return true;
60441+ }
60442+ }
60443+ rcu_read_unlock();
60444+
60445+ if (!pid->hide_pid)
60446+ return false;
60447+#endif
60448+
60449 if (pid->hide_pid < hide_pid_min)
60450 return true;
60451 if (in_group_p(pid->pid_gid))
60452 return true;
60453+
60454 return ptrace_may_access(task, PTRACE_MODE_READ);
60455 }
60456
60457@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
60458 put_task_struct(task);
60459
60460 if (!has_perms) {
60461+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60462+ {
60463+#else
60464 if (pid->hide_pid == 2) {
60465+#endif
60466 /*
60467 * Let's make getdents(), stat(), and open()
60468 * consistent with each other. If a process
60469@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
60470 if (!task)
60471 return -ESRCH;
60472
60473+ if (gr_acl_handle_procpidmem(task)) {
60474+ put_task_struct(task);
60475+ return -EPERM;
60476+ }
60477+
60478 mm = mm_access(task, mode);
60479 put_task_struct(task);
60480
60481@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
60482
60483 file->private_data = mm;
60484
60485+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60486+ file->f_version = current->exec_id;
60487+#endif
60488+
60489 return 0;
60490 }
60491
60492@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
60493 ssize_t copied;
60494 char *page;
60495
60496+#ifdef CONFIG_GRKERNSEC
60497+ if (write)
60498+ return -EPERM;
60499+#endif
60500+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60501+ if (file->f_version != current->exec_id) {
60502+ gr_log_badprocpid("mem");
60503+ return 0;
60504+ }
60505+#endif
60506+
60507 if (!mm)
60508 return 0;
60509
60510@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
60511 goto free;
60512
60513 while (count > 0) {
60514- int this_len = min_t(int, count, PAGE_SIZE);
60515+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
60516
60517 if (write && copy_from_user(page, buf, this_len)) {
60518 copied = -EFAULT;
60519@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
60520 if (!mm)
60521 return 0;
60522
60523+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60524+ if (file->f_version != current->exec_id) {
60525+ gr_log_badprocpid("environ");
60526+ return 0;
60527+ }
60528+#endif
60529+
60530 page = (char *)__get_free_page(GFP_TEMPORARY);
60531 if (!page)
60532 return -ENOMEM;
60533@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
60534 goto free;
60535 while (count > 0) {
60536 size_t this_len, max_len;
60537- int retval;
60538+ ssize_t retval;
60539
60540 if (src >= (mm->env_end - mm->env_start))
60541 break;
60542@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
60543 int error = -EACCES;
60544
60545 /* Are we allowed to snoop on the tasks file descriptors? */
60546- if (!proc_fd_access_allowed(inode))
60547+ if (!proc_fd_access_allowed(inode, 0))
60548 goto out;
60549
60550 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
60551@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
60552 struct path path;
60553
60554 /* Are we allowed to snoop on the tasks file descriptors? */
60555- if (!proc_fd_access_allowed(inode))
60556- goto out;
60557+ /* logging this is needed for learning on chromium to work properly,
60558+ but we don't want to flood the logs from 'ps' which does a readlink
60559+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
60560+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
60561+ */
60562+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
60563+ if (!proc_fd_access_allowed(inode,0))
60564+ goto out;
60565+ } else {
60566+ if (!proc_fd_access_allowed(inode,1))
60567+ goto out;
60568+ }
60569
60570 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
60571 if (error)
60572@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
60573 rcu_read_lock();
60574 cred = __task_cred(task);
60575 inode->i_uid = cred->euid;
60576+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60577+ inode->i_gid = grsec_proc_gid;
60578+#else
60579 inode->i_gid = cred->egid;
60580+#endif
60581 rcu_read_unlock();
60582 }
60583 security_task_to_inode(task, inode);
60584@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
60585 return -ENOENT;
60586 }
60587 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
60588+#ifdef CONFIG_GRKERNSEC_PROC_USER
60589+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
60590+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60591+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
60592+#endif
60593 task_dumpable(task)) {
60594 cred = __task_cred(task);
60595 stat->uid = cred->euid;
60596+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60597+ stat->gid = grsec_proc_gid;
60598+#else
60599 stat->gid = cred->egid;
60600+#endif
60601 }
60602 }
60603 rcu_read_unlock();
60604@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
60605
60606 if (task) {
60607 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
60608+#ifdef CONFIG_GRKERNSEC_PROC_USER
60609+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
60610+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60611+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
60612+#endif
60613 task_dumpable(task)) {
60614 rcu_read_lock();
60615 cred = __task_cred(task);
60616 inode->i_uid = cred->euid;
60617+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60618+ inode->i_gid = grsec_proc_gid;
60619+#else
60620 inode->i_gid = cred->egid;
60621+#endif
60622 rcu_read_unlock();
60623 } else {
60624 inode->i_uid = GLOBAL_ROOT_UID;
60625@@ -2196,6 +2314,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
60626 if (!task)
60627 goto out_no_task;
60628
60629+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60630+ goto out;
60631+
60632 /*
60633 * Yes, it does not scale. And it should not. Don't add
60634 * new entries into /proc/<tgid>/ without very good reasons.
60635@@ -2240,6 +2361,9 @@ static int proc_pident_readdir(struct file *filp,
60636 if (!task)
60637 goto out_no_task;
60638
60639+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60640+ goto out;
60641+
60642 ret = 0;
60643 i = filp->f_pos;
60644 switch (i) {
60645@@ -2653,7 +2777,7 @@ static const struct pid_entry tgid_base_stuff[] = {
60646 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
60647 #endif
60648 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
60649-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60650+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60651 INF("syscall", S_IRUGO, proc_pid_syscall),
60652 #endif
60653 INF("cmdline", S_IRUGO, proc_pid_cmdline),
60654@@ -2678,10 +2802,10 @@ static const struct pid_entry tgid_base_stuff[] = {
60655 #ifdef CONFIG_SECURITY
60656 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
60657 #endif
60658-#ifdef CONFIG_KALLSYMS
60659+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60660 INF("wchan", S_IRUGO, proc_pid_wchan),
60661 #endif
60662-#ifdef CONFIG_STACKTRACE
60663+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60664 ONE("stack", S_IRUGO, proc_pid_stack),
60665 #endif
60666 #ifdef CONFIG_SCHEDSTATS
60667@@ -2715,6 +2839,9 @@ static const struct pid_entry tgid_base_stuff[] = {
60668 #ifdef CONFIG_HARDWALL
60669 INF("hardwall", S_IRUGO, proc_pid_hardwall),
60670 #endif
60671+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60672+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
60673+#endif
60674 #ifdef CONFIG_USER_NS
60675 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
60676 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
60677@@ -2847,7 +2974,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
60678 if (!inode)
60679 goto out;
60680
60681+#ifdef CONFIG_GRKERNSEC_PROC_USER
60682+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
60683+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60684+ inode->i_gid = grsec_proc_gid;
60685+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
60686+#else
60687 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
60688+#endif
60689 inode->i_op = &proc_tgid_base_inode_operations;
60690 inode->i_fop = &proc_tgid_base_operations;
60691 inode->i_flags|=S_IMMUTABLE;
60692@@ -2885,7 +3019,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
60693 if (!task)
60694 goto out;
60695
60696+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60697+ goto out_put_task;
60698+
60699 result = proc_pid_instantiate(dir, dentry, task, NULL);
60700+out_put_task:
60701 put_task_struct(task);
60702 out:
60703 return result;
60704@@ -2948,6 +3086,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
60705 static int fake_filldir(void *buf, const char *name, int namelen,
60706 loff_t offset, u64 ino, unsigned d_type)
60707 {
60708+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
60709+ __buf->error = -EINVAL;
60710 return 0;
60711 }
60712
60713@@ -3007,7 +3147,7 @@ static const struct pid_entry tid_base_stuff[] = {
60714 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
60715 #endif
60716 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
60717-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60718+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60719 INF("syscall", S_IRUGO, proc_pid_syscall),
60720 #endif
60721 INF("cmdline", S_IRUGO, proc_pid_cmdline),
60722@@ -3034,10 +3174,10 @@ static const struct pid_entry tid_base_stuff[] = {
60723 #ifdef CONFIG_SECURITY
60724 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
60725 #endif
60726-#ifdef CONFIG_KALLSYMS
60727+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60728 INF("wchan", S_IRUGO, proc_pid_wchan),
60729 #endif
60730-#ifdef CONFIG_STACKTRACE
60731+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60732 ONE("stack", S_IRUGO, proc_pid_stack),
60733 #endif
60734 #ifdef CONFIG_SCHEDSTATS
60735diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
60736index 82676e3..5f8518a 100644
60737--- a/fs/proc/cmdline.c
60738+++ b/fs/proc/cmdline.c
60739@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
60740
60741 static int __init proc_cmdline_init(void)
60742 {
60743+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60744+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
60745+#else
60746 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
60747+#endif
60748 return 0;
60749 }
60750 module_init(proc_cmdline_init);
60751diff --git a/fs/proc/devices.c b/fs/proc/devices.c
60752index b143471..bb105e5 100644
60753--- a/fs/proc/devices.c
60754+++ b/fs/proc/devices.c
60755@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
60756
60757 static int __init proc_devices_init(void)
60758 {
60759+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60760+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
60761+#else
60762 proc_create("devices", 0, NULL, &proc_devinfo_operations);
60763+#endif
60764 return 0;
60765 }
60766 module_init(proc_devices_init);
60767diff --git a/fs/proc/fd.c b/fs/proc/fd.c
60768index d7a4a28..0201742 100644
60769--- a/fs/proc/fd.c
60770+++ b/fs/proc/fd.c
60771@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
60772 if (!task)
60773 return -ENOENT;
60774
60775- files = get_files_struct(task);
60776+ if (!gr_acl_handle_procpidmem(task))
60777+ files = get_files_struct(task);
60778 put_task_struct(task);
60779
60780 if (files) {
60781@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
60782 */
60783 int proc_fd_permission(struct inode *inode, int mask)
60784 {
60785+ struct task_struct *task;
60786 int rv = generic_permission(inode, mask);
60787- if (rv == 0)
60788- return 0;
60789+
60790 if (task_pid(current) == proc_pid(inode))
60791 rv = 0;
60792+
60793+ task = get_proc_task(inode);
60794+ if (task == NULL)
60795+ return rv;
60796+
60797+ if (gr_acl_handle_procpidmem(task))
60798+ rv = -EACCES;
60799+
60800+ put_task_struct(task);
60801+
60802 return rv;
60803 }
60804
60805diff --git a/fs/proc/inode.c b/fs/proc/inode.c
60806index 073aea6..0630370 100644
60807--- a/fs/proc/inode.c
60808+++ b/fs/proc/inode.c
60809@@ -23,11 +23,17 @@
60810 #include <linux/slab.h>
60811 #include <linux/mount.h>
60812 #include <linux/magic.h>
60813+#include <linux/grsecurity.h>
60814
60815 #include <asm/uaccess.h>
60816
60817 #include "internal.h"
60818
60819+#ifdef CONFIG_PROC_SYSCTL
60820+extern const struct inode_operations proc_sys_inode_operations;
60821+extern const struct inode_operations proc_sys_dir_operations;
60822+#endif
60823+
60824 static void proc_evict_inode(struct inode *inode)
60825 {
60826 struct proc_dir_entry *de;
60827@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
60828 ns = PROC_I(inode)->ns.ns;
60829 if (ns_ops && ns)
60830 ns_ops->put(ns);
60831+
60832+#ifdef CONFIG_PROC_SYSCTL
60833+ if (inode->i_op == &proc_sys_inode_operations ||
60834+ inode->i_op == &proc_sys_dir_operations)
60835+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
60836+#endif
60837+
60838 }
60839
60840 static struct kmem_cache * proc_inode_cachep;
60841@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
60842 if (de->mode) {
60843 inode->i_mode = de->mode;
60844 inode->i_uid = de->uid;
60845+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60846+ inode->i_gid = grsec_proc_gid;
60847+#else
60848 inode->i_gid = de->gid;
60849+#endif
60850 }
60851 if (de->size)
60852 inode->i_size = de->size;
60853diff --git a/fs/proc/internal.h b/fs/proc/internal.h
60854index d600fb0..3b495fe 100644
60855--- a/fs/proc/internal.h
60856+++ b/fs/proc/internal.h
60857@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
60858 struct pid *, struct task_struct *);
60859 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
60860 struct pid *, struct task_struct *);
60861+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60862+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
60863+#endif
60864
60865 /*
60866 * base.c
60867diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
60868index 0a22194..a9fc8c1 100644
60869--- a/fs/proc/kcore.c
60870+++ b/fs/proc/kcore.c
60871@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60872 * the addresses in the elf_phdr on our list.
60873 */
60874 start = kc_offset_to_vaddr(*fpos - elf_buflen);
60875- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
60876+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
60877+ if (tsz > buflen)
60878 tsz = buflen;
60879-
60880+
60881 while (buflen) {
60882 struct kcore_list *m;
60883
60884@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60885 kfree(elf_buf);
60886 } else {
60887 if (kern_addr_valid(start)) {
60888- unsigned long n;
60889+ char *elf_buf;
60890+ mm_segment_t oldfs;
60891
60892- n = copy_to_user(buffer, (char *)start, tsz);
60893- /*
60894- * We cannot distinguish between fault on source
60895- * and fault on destination. When this happens
60896- * we clear too and hope it will trigger the
60897- * EFAULT again.
60898- */
60899- if (n) {
60900- if (clear_user(buffer + tsz - n,
60901- n))
60902+ elf_buf = kmalloc(tsz, GFP_KERNEL);
60903+ if (!elf_buf)
60904+ return -ENOMEM;
60905+ oldfs = get_fs();
60906+ set_fs(KERNEL_DS);
60907+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
60908+ set_fs(oldfs);
60909+ if (copy_to_user(buffer, elf_buf, tsz)) {
60910+ kfree(elf_buf);
60911 return -EFAULT;
60912+ }
60913 }
60914+ set_fs(oldfs);
60915+ kfree(elf_buf);
60916 } else {
60917 if (clear_user(buffer, tsz))
60918 return -EFAULT;
60919@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60920
60921 static int open_kcore(struct inode *inode, struct file *filp)
60922 {
60923+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
60924+ return -EPERM;
60925+#endif
60926 if (!capable(CAP_SYS_RAWIO))
60927 return -EPERM;
60928 if (kcore_need_update)
60929diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
60930index 5aa847a..f77c8d4 100644
60931--- a/fs/proc/meminfo.c
60932+++ b/fs/proc/meminfo.c
60933@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
60934 vmi.used >> 10,
60935 vmi.largest_chunk >> 10
60936 #ifdef CONFIG_MEMORY_FAILURE
60937- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
60938+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
60939 #endif
60940 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
60941 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
60942diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
60943index ccfd99b..1b7e255 100644
60944--- a/fs/proc/nommu.c
60945+++ b/fs/proc/nommu.c
60946@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
60947 if (len < 1)
60948 len = 1;
60949 seq_printf(m, "%*c", len, ' ');
60950- seq_path(m, &file->f_path, "");
60951+ seq_path(m, &file->f_path, "\n\\");
60952 }
60953
60954 seq_putc(m, '\n');
60955diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
60956index 986e832..6e8e859 100644
60957--- a/fs/proc/proc_net.c
60958+++ b/fs/proc/proc_net.c
60959@@ -23,6 +23,7 @@
60960 #include <linux/nsproxy.h>
60961 #include <net/net_namespace.h>
60962 #include <linux/seq_file.h>
60963+#include <linux/grsecurity.h>
60964
60965 #include "internal.h"
60966
60967@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
60968 struct task_struct *task;
60969 struct nsproxy *ns;
60970 struct net *net = NULL;
60971+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60972+ const struct cred *cred = current_cred();
60973+#endif
60974+
60975+#ifdef CONFIG_GRKERNSEC_PROC_USER
60976+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
60977+ return net;
60978+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60979+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
60980+ return net;
60981+#endif
60982
60983 rcu_read_lock();
60984 task = pid_task(proc_pid(dir), PIDTYPE_PID);
60985diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
60986index ac05f33..1e6dc7e 100644
60987--- a/fs/proc/proc_sysctl.c
60988+++ b/fs/proc/proc_sysctl.c
60989@@ -13,11 +13,15 @@
60990 #include <linux/module.h>
60991 #include "internal.h"
60992
60993+extern int gr_handle_chroot_sysctl(const int op);
60994+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
60995+ const int op);
60996+
60997 static const struct dentry_operations proc_sys_dentry_operations;
60998 static const struct file_operations proc_sys_file_operations;
60999-static const struct inode_operations proc_sys_inode_operations;
61000+const struct inode_operations proc_sys_inode_operations;
61001 static const struct file_operations proc_sys_dir_file_operations;
61002-static const struct inode_operations proc_sys_dir_operations;
61003+const struct inode_operations proc_sys_dir_operations;
61004
61005 void proc_sys_poll_notify(struct ctl_table_poll *poll)
61006 {
61007@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
61008
61009 err = NULL;
61010 d_set_d_op(dentry, &proc_sys_dentry_operations);
61011+
61012+ gr_handle_proc_create(dentry, inode);
61013+
61014 d_add(dentry, inode);
61015
61016 out:
61017@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
61018 struct inode *inode = file_inode(filp);
61019 struct ctl_table_header *head = grab_header(inode);
61020 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
61021+ int op = write ? MAY_WRITE : MAY_READ;
61022 ssize_t error;
61023 size_t res;
61024
61025@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
61026 * and won't be until we finish.
61027 */
61028 error = -EPERM;
61029- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
61030+ if (sysctl_perm(head, table, op))
61031 goto out;
61032
61033 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
61034@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
61035 if (!table->proc_handler)
61036 goto out;
61037
61038+#ifdef CONFIG_GRKERNSEC
61039+ error = -EPERM;
61040+ if (gr_handle_chroot_sysctl(op))
61041+ goto out;
61042+ dget(filp->f_path.dentry);
61043+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
61044+ dput(filp->f_path.dentry);
61045+ goto out;
61046+ }
61047+ dput(filp->f_path.dentry);
61048+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
61049+ goto out;
61050+ if (write && !capable(CAP_SYS_ADMIN))
61051+ goto out;
61052+#endif
61053+
61054 /* careful: calling conventions are nasty here */
61055 res = count;
61056 error = table->proc_handler(table, write, buf, &res, ppos);
61057@@ -598,6 +622,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
61058 return -ENOMEM;
61059 } else {
61060 d_set_d_op(child, &proc_sys_dentry_operations);
61061+
61062+ gr_handle_proc_create(child, inode);
61063+
61064 d_add(child, inode);
61065 }
61066 } else {
61067@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
61068 if ((*pos)++ < file->f_pos)
61069 return 0;
61070
61071+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
61072+ return 0;
61073+
61074 if (unlikely(S_ISLNK(table->mode)))
61075 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
61076 else
61077@@ -751,6 +781,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
61078 if (IS_ERR(head))
61079 return PTR_ERR(head);
61080
61081+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
61082+ return -ENOENT;
61083+
61084 generic_fillattr(inode, stat);
61085 if (table)
61086 stat->mode = (stat->mode & S_IFMT) | table->mode;
61087@@ -773,13 +806,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
61088 .llseek = generic_file_llseek,
61089 };
61090
61091-static const struct inode_operations proc_sys_inode_operations = {
61092+const struct inode_operations proc_sys_inode_operations = {
61093 .permission = proc_sys_permission,
61094 .setattr = proc_sys_setattr,
61095 .getattr = proc_sys_getattr,
61096 };
61097
61098-static const struct inode_operations proc_sys_dir_operations = {
61099+const struct inode_operations proc_sys_dir_operations = {
61100 .lookup = proc_sys_lookup,
61101 .permission = proc_sys_permission,
61102 .setattr = proc_sys_setattr,
61103@@ -855,7 +888,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
61104 static struct ctl_dir *new_dir(struct ctl_table_set *set,
61105 const char *name, int namelen)
61106 {
61107- struct ctl_table *table;
61108+ ctl_table_no_const *table;
61109 struct ctl_dir *new;
61110 struct ctl_node *node;
61111 char *new_name;
61112@@ -867,7 +900,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
61113 return NULL;
61114
61115 node = (struct ctl_node *)(new + 1);
61116- table = (struct ctl_table *)(node + 1);
61117+ table = (ctl_table_no_const *)(node + 1);
61118 new_name = (char *)(table + 2);
61119 memcpy(new_name, name, namelen);
61120 new_name[namelen] = '\0';
61121@@ -1036,7 +1069,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
61122 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
61123 struct ctl_table_root *link_root)
61124 {
61125- struct ctl_table *link_table, *entry, *link;
61126+ ctl_table_no_const *link_table, *link;
61127+ struct ctl_table *entry;
61128 struct ctl_table_header *links;
61129 struct ctl_node *node;
61130 char *link_name;
61131@@ -1059,7 +1093,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
61132 return NULL;
61133
61134 node = (struct ctl_node *)(links + 1);
61135- link_table = (struct ctl_table *)(node + nr_entries);
61136+ link_table = (ctl_table_no_const *)(node + nr_entries);
61137 link_name = (char *)&link_table[nr_entries + 1];
61138
61139 for (link = link_table, entry = table; entry->procname; link++, entry++) {
61140@@ -1307,8 +1341,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
61141 struct ctl_table_header ***subheader, struct ctl_table_set *set,
61142 struct ctl_table *table)
61143 {
61144- struct ctl_table *ctl_table_arg = NULL;
61145- struct ctl_table *entry, *files;
61146+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
61147+ struct ctl_table *entry;
61148 int nr_files = 0;
61149 int nr_dirs = 0;
61150 int err = -ENOMEM;
61151@@ -1320,10 +1354,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
61152 nr_files++;
61153 }
61154
61155- files = table;
61156 /* If there are mixed files and directories we need a new table */
61157 if (nr_dirs && nr_files) {
61158- struct ctl_table *new;
61159+ ctl_table_no_const *new;
61160 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
61161 GFP_KERNEL);
61162 if (!files)
61163@@ -1341,7 +1374,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
61164 /* Register everything except a directory full of subdirectories */
61165 if (nr_files || !nr_dirs) {
61166 struct ctl_table_header *header;
61167- header = __register_sysctl_table(set, path, files);
61168+ header = __register_sysctl_table(set, path, files ? files : table);
61169 if (!header) {
61170 kfree(ctl_table_arg);
61171 goto out;
61172diff --git a/fs/proc/root.c b/fs/proc/root.c
61173index 41a6ea9..23eaa92 100644
61174--- a/fs/proc/root.c
61175+++ b/fs/proc/root.c
61176@@ -182,7 +182,15 @@ void __init proc_root_init(void)
61177 #ifdef CONFIG_PROC_DEVICETREE
61178 proc_device_tree_init();
61179 #endif
61180+#ifdef CONFIG_GRKERNSEC_PROC_ADD
61181+#ifdef CONFIG_GRKERNSEC_PROC_USER
61182+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
61183+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61184+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
61185+#endif
61186+#else
61187 proc_mkdir("bus", NULL);
61188+#endif
61189 proc_sys_init();
61190 }
61191
61192diff --git a/fs/proc/self.c b/fs/proc/self.c
61193index 6b6a993..807cccc 100644
61194--- a/fs/proc/self.c
61195+++ b/fs/proc/self.c
61196@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
61197 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
61198 void *cookie)
61199 {
61200- char *s = nd_get_link(nd);
61201+ const char *s = nd_get_link(nd);
61202 if (!IS_ERR(s))
61203 kfree(s);
61204 }
61205diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
61206index 65fc60a..350cc48 100644
61207--- a/fs/proc/task_mmu.c
61208+++ b/fs/proc/task_mmu.c
61209@@ -11,12 +11,19 @@
61210 #include <linux/rmap.h>
61211 #include <linux/swap.h>
61212 #include <linux/swapops.h>
61213+#include <linux/grsecurity.h>
61214
61215 #include <asm/elf.h>
61216 #include <asm/uaccess.h>
61217 #include <asm/tlbflush.h>
61218 #include "internal.h"
61219
61220+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61221+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61222+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
61223+ _mm->pax_flags & MF_PAX_SEGMEXEC))
61224+#endif
61225+
61226 void task_mem(struct seq_file *m, struct mm_struct *mm)
61227 {
61228 unsigned long data, text, lib, swap;
61229@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
61230 "VmExe:\t%8lu kB\n"
61231 "VmLib:\t%8lu kB\n"
61232 "VmPTE:\t%8lu kB\n"
61233- "VmSwap:\t%8lu kB\n",
61234- hiwater_vm << (PAGE_SHIFT-10),
61235+ "VmSwap:\t%8lu kB\n"
61236+
61237+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61238+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
61239+#endif
61240+
61241+ ,hiwater_vm << (PAGE_SHIFT-10),
61242 total_vm << (PAGE_SHIFT-10),
61243 mm->locked_vm << (PAGE_SHIFT-10),
61244 mm->pinned_vm << (PAGE_SHIFT-10),
61245@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
61246 data << (PAGE_SHIFT-10),
61247 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
61248 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
61249- swap << (PAGE_SHIFT-10));
61250+ swap << (PAGE_SHIFT-10)
61251+
61252+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61253+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61254+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
61255+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
61256+#else
61257+ , mm->context.user_cs_base
61258+ , mm->context.user_cs_limit
61259+#endif
61260+#endif
61261+
61262+ );
61263 }
61264
61265 unsigned long task_vsize(struct mm_struct *mm)
61266@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61267 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
61268 }
61269
61270- /* We don't show the stack guard page in /proc/maps */
61271+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61272+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
61273+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
61274+#else
61275 start = vma->vm_start;
61276- if (stack_guard_page_start(vma, start))
61277- start += PAGE_SIZE;
61278 end = vma->vm_end;
61279- if (stack_guard_page_end(vma, end))
61280- end -= PAGE_SIZE;
61281+#endif
61282
61283 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
61284 start,
61285@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61286 flags & VM_WRITE ? 'w' : '-',
61287 flags & VM_EXEC ? 'x' : '-',
61288 flags & VM_MAYSHARE ? 's' : 'p',
61289+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61290+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
61291+#else
61292 pgoff,
61293+#endif
61294 MAJOR(dev), MINOR(dev), ino, &len);
61295
61296 /*
61297@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61298 */
61299 if (file) {
61300 pad_len_spaces(m, len);
61301- seq_path(m, &file->f_path, "\n");
61302+ seq_path(m, &file->f_path, "\n\\");
61303 goto done;
61304 }
61305
61306@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61307 * Thread stack in /proc/PID/task/TID/maps or
61308 * the main process stack.
61309 */
61310- if (!is_pid || (vma->vm_start <= mm->start_stack &&
61311- vma->vm_end >= mm->start_stack)) {
61312+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
61313+ (vma->vm_start <= mm->start_stack &&
61314+ vma->vm_end >= mm->start_stack)) {
61315 name = "[stack]";
61316 } else {
61317 /* Thread stack in /proc/PID/maps */
61318@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
61319 struct proc_maps_private *priv = m->private;
61320 struct task_struct *task = priv->task;
61321
61322+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61323+ if (current->exec_id != m->exec_id) {
61324+ gr_log_badprocpid("maps");
61325+ return 0;
61326+ }
61327+#endif
61328+
61329 show_map_vma(m, vma, is_pid);
61330
61331 if (m->count < m->size) /* vma is copied successfully */
61332@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
61333 .private = &mss,
61334 };
61335
61336+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61337+ if (current->exec_id != m->exec_id) {
61338+ gr_log_badprocpid("smaps");
61339+ return 0;
61340+ }
61341+#endif
61342 memset(&mss, 0, sizeof mss);
61343- mss.vma = vma;
61344- /* mmap_sem is held in m_start */
61345- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
61346- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
61347-
61348+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61349+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
61350+#endif
61351+ mss.vma = vma;
61352+ /* mmap_sem is held in m_start */
61353+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
61354+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
61355+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61356+ }
61357+#endif
61358 show_map_vma(m, vma, is_pid);
61359
61360 seq_printf(m,
61361@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
61362 "KernelPageSize: %8lu kB\n"
61363 "MMUPageSize: %8lu kB\n"
61364 "Locked: %8lu kB\n",
61365+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61366+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
61367+#else
61368 (vma->vm_end - vma->vm_start) >> 10,
61369+#endif
61370 mss.resident >> 10,
61371 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
61372 mss.shared_clean >> 10,
61373@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
61374 int n;
61375 char buffer[50];
61376
61377+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61378+ if (current->exec_id != m->exec_id) {
61379+ gr_log_badprocpid("numa_maps");
61380+ return 0;
61381+ }
61382+#endif
61383+
61384 if (!mm)
61385 return 0;
61386
61387@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
61388 mpol_to_str(buffer, sizeof(buffer), pol);
61389 mpol_cond_put(pol);
61390
61391+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61392+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
61393+#else
61394 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
61395+#endif
61396
61397 if (file) {
61398 seq_printf(m, " file=");
61399- seq_path(m, &file->f_path, "\n\t= ");
61400+ seq_path(m, &file->f_path, "\n\t\\= ");
61401 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
61402 seq_printf(m, " heap");
61403 } else {
61404diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
61405index 56123a6..5a2f6ec 100644
61406--- a/fs/proc/task_nommu.c
61407+++ b/fs/proc/task_nommu.c
61408@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
61409 else
61410 bytes += kobjsize(mm);
61411
61412- if (current->fs && current->fs->users > 1)
61413+ if (current->fs && atomic_read(&current->fs->users) > 1)
61414 sbytes += kobjsize(current->fs);
61415 else
61416 bytes += kobjsize(current->fs);
61417@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
61418
61419 if (file) {
61420 pad_len_spaces(m, len);
61421- seq_path(m, &file->f_path, "");
61422+ seq_path(m, &file->f_path, "\n\\");
61423 } else if (mm) {
61424 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
61425
61426diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
61427index 17f7e08..e4b1529 100644
61428--- a/fs/proc/vmcore.c
61429+++ b/fs/proc/vmcore.c
61430@@ -99,9 +99,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
61431 nr_bytes = count;
61432
61433 /* If pfn is not ram, return zeros for sparse dump files */
61434- if (pfn_is_ram(pfn) == 0)
61435- memset(buf, 0, nr_bytes);
61436- else {
61437+ if (pfn_is_ram(pfn) == 0) {
61438+ if (userbuf) {
61439+ if (clear_user((char __force_user *)buf, nr_bytes))
61440+ return -EFAULT;
61441+ } else
61442+ memset(buf, 0, nr_bytes);
61443+ } else {
61444 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
61445 offset, userbuf);
61446 if (tmp < 0)
61447@@ -186,7 +190,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
61448 if (tsz > nr_bytes)
61449 tsz = nr_bytes;
61450
61451- tmp = read_from_oldmem(buffer, tsz, &start, 1);
61452+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
61453 if (tmp < 0)
61454 return tmp;
61455 buflen -= tsz;
61456diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
61457index b00fcc9..e0c6381 100644
61458--- a/fs/qnx6/qnx6.h
61459+++ b/fs/qnx6/qnx6.h
61460@@ -74,7 +74,7 @@ enum {
61461 BYTESEX_BE,
61462 };
61463
61464-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
61465+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
61466 {
61467 if (sbi->s_bytesex == BYTESEX_LE)
61468 return le64_to_cpu((__force __le64)n);
61469@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
61470 return (__force __fs64)cpu_to_be64(n);
61471 }
61472
61473-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
61474+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
61475 {
61476 if (sbi->s_bytesex == BYTESEX_LE)
61477 return le32_to_cpu((__force __le32)n);
61478diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
61479index 16e8abb..2dcf914 100644
61480--- a/fs/quota/netlink.c
61481+++ b/fs/quota/netlink.c
61482@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
61483 void quota_send_warning(struct kqid qid, dev_t dev,
61484 const char warntype)
61485 {
61486- static atomic_t seq;
61487+ static atomic_unchecked_t seq;
61488 struct sk_buff *skb;
61489 void *msg_head;
61490 int ret;
61491@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
61492 "VFS: Not enough memory to send quota warning.\n");
61493 return;
61494 }
61495- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
61496+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
61497 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
61498 if (!msg_head) {
61499 printk(KERN_ERR
61500diff --git a/fs/read_write.c b/fs/read_write.c
61501index 2cefa41..c7e2fe0 100644
61502--- a/fs/read_write.c
61503+++ b/fs/read_write.c
61504@@ -411,7 +411,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
61505
61506 old_fs = get_fs();
61507 set_fs(get_ds());
61508- p = (__force const char __user *)buf;
61509+ p = (const char __force_user *)buf;
61510 if (count > MAX_RW_COUNT)
61511 count = MAX_RW_COUNT;
61512 if (file->f_op->write)
61513diff --git a/fs/readdir.c b/fs/readdir.c
61514index fee38e0..12fdf47 100644
61515--- a/fs/readdir.c
61516+++ b/fs/readdir.c
61517@@ -17,6 +17,7 @@
61518 #include <linux/security.h>
61519 #include <linux/syscalls.h>
61520 #include <linux/unistd.h>
61521+#include <linux/namei.h>
61522
61523 #include <asm/uaccess.h>
61524
61525@@ -67,6 +68,7 @@ struct old_linux_dirent {
61526
61527 struct readdir_callback {
61528 struct old_linux_dirent __user * dirent;
61529+ struct file * file;
61530 int result;
61531 };
61532
61533@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
61534 buf->result = -EOVERFLOW;
61535 return -EOVERFLOW;
61536 }
61537+
61538+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61539+ return 0;
61540+
61541 buf->result++;
61542 dirent = buf->dirent;
61543 if (!access_ok(VERIFY_WRITE, dirent,
61544@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
61545
61546 buf.result = 0;
61547 buf.dirent = dirent;
61548+ buf.file = f.file;
61549
61550 error = vfs_readdir(f.file, fillonedir, &buf);
61551 if (buf.result)
61552@@ -139,6 +146,7 @@ struct linux_dirent {
61553 struct getdents_callback {
61554 struct linux_dirent __user * current_dir;
61555 struct linux_dirent __user * previous;
61556+ struct file * file;
61557 int count;
61558 int error;
61559 };
61560@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
61561 buf->error = -EOVERFLOW;
61562 return -EOVERFLOW;
61563 }
61564+
61565+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61566+ return 0;
61567+
61568 dirent = buf->previous;
61569 if (dirent) {
61570 if (__put_user(offset, &dirent->d_off))
61571@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
61572 buf.previous = NULL;
61573 buf.count = count;
61574 buf.error = 0;
61575+ buf.file = f.file;
61576
61577 error = vfs_readdir(f.file, filldir, &buf);
61578 if (error >= 0)
61579@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
61580 struct getdents_callback64 {
61581 struct linux_dirent64 __user * current_dir;
61582 struct linux_dirent64 __user * previous;
61583+ struct file *file;
61584 int count;
61585 int error;
61586 };
61587@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
61588 buf->error = -EINVAL; /* only used if we fail.. */
61589 if (reclen > buf->count)
61590 return -EINVAL;
61591+
61592+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61593+ return 0;
61594+
61595 dirent = buf->previous;
61596 if (dirent) {
61597 if (__put_user(offset, &dirent->d_off))
61598@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
61599
61600 buf.current_dir = dirent;
61601 buf.previous = NULL;
61602+ buf.file = f.file;
61603 buf.count = count;
61604 buf.error = 0;
61605
61606@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
61607 error = buf.error;
61608 lastdirent = buf.previous;
61609 if (lastdirent) {
61610- typeof(lastdirent->d_off) d_off = f.file->f_pos;
61611+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
61612 if (__put_user(d_off, &lastdirent->d_off))
61613 error = -EFAULT;
61614 else
61615diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
61616index 2b7882b..1c5ef48 100644
61617--- a/fs/reiserfs/do_balan.c
61618+++ b/fs/reiserfs/do_balan.c
61619@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
61620 return;
61621 }
61622
61623- atomic_inc(&(fs_generation(tb->tb_sb)));
61624+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
61625 do_balance_starts(tb);
61626
61627 /* balance leaf returns 0 except if combining L R and S into
61628diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
61629index 1d48974..2f8f4e0 100644
61630--- a/fs/reiserfs/procfs.c
61631+++ b/fs/reiserfs/procfs.c
61632@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
61633 "SMALL_TAILS " : "NO_TAILS ",
61634 replay_only(sb) ? "REPLAY_ONLY " : "",
61635 convert_reiserfs(sb) ? "CONV " : "",
61636- atomic_read(&r->s_generation_counter),
61637+ atomic_read_unchecked(&r->s_generation_counter),
61638 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
61639 SF(s_do_balance), SF(s_unneeded_left_neighbor),
61640 SF(s_good_search_by_key_reada), SF(s_bmaps),
61641diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
61642index 157e474..65a6114 100644
61643--- a/fs/reiserfs/reiserfs.h
61644+++ b/fs/reiserfs/reiserfs.h
61645@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
61646 /* Comment? -Hans */
61647 wait_queue_head_t s_wait;
61648 /* To be obsoleted soon by per buffer seals.. -Hans */
61649- atomic_t s_generation_counter; // increased by one every time the
61650+ atomic_unchecked_t s_generation_counter; // increased by one every time the
61651 // tree gets re-balanced
61652 unsigned long s_properties; /* File system properties. Currently holds
61653 on-disk FS format */
61654@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
61655 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
61656
61657 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
61658-#define get_generation(s) atomic_read (&fs_generation(s))
61659+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
61660 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
61661 #define __fs_changed(gen,s) (gen != get_generation (s))
61662 #define fs_changed(gen,s) \
61663diff --git a/fs/select.c b/fs/select.c
61664index 8c1c96c..a0f9b6d 100644
61665--- a/fs/select.c
61666+++ b/fs/select.c
61667@@ -20,6 +20,7 @@
61668 #include <linux/export.h>
61669 #include <linux/slab.h>
61670 #include <linux/poll.h>
61671+#include <linux/security.h>
61672 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
61673 #include <linux/file.h>
61674 #include <linux/fdtable.h>
61675@@ -827,6 +828,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
61676 struct poll_list *walk = head;
61677 unsigned long todo = nfds;
61678
61679+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
61680 if (nfds > rlimit(RLIMIT_NOFILE))
61681 return -EINVAL;
61682
61683diff --git a/fs/seq_file.c b/fs/seq_file.c
61684index 774c1eb..b67582a 100644
61685--- a/fs/seq_file.c
61686+++ b/fs/seq_file.c
61687@@ -10,6 +10,7 @@
61688 #include <linux/seq_file.h>
61689 #include <linux/slab.h>
61690 #include <linux/cred.h>
61691+#include <linux/sched.h>
61692
61693 #include <asm/uaccess.h>
61694 #include <asm/page.h>
61695@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
61696 #ifdef CONFIG_USER_NS
61697 p->user_ns = file->f_cred->user_ns;
61698 #endif
61699+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61700+ p->exec_id = current->exec_id;
61701+#endif
61702
61703 /*
61704 * Wrappers around seq_open(e.g. swaps_open) need to be
61705@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
61706 return 0;
61707 }
61708 if (!m->buf) {
61709- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
61710+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
61711 if (!m->buf)
61712 return -ENOMEM;
61713 }
61714@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
61715 Eoverflow:
61716 m->op->stop(m, p);
61717 kfree(m->buf);
61718- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
61719+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
61720 return !m->buf ? -ENOMEM : -EAGAIN;
61721 }
61722
61723@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61724
61725 /* grab buffer if we didn't have one */
61726 if (!m->buf) {
61727- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
61728+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
61729 if (!m->buf)
61730 goto Enomem;
61731 }
61732@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61733 goto Fill;
61734 m->op->stop(m, p);
61735 kfree(m->buf);
61736- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
61737+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
61738 if (!m->buf)
61739 goto Enomem;
61740 m->count = 0;
61741@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
61742 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
61743 void *data)
61744 {
61745- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
61746+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
61747 int res = -ENOMEM;
61748
61749 if (op) {
61750diff --git a/fs/splice.c b/fs/splice.c
61751index d37431d..09241b4 100644
61752--- a/fs/splice.c
61753+++ b/fs/splice.c
61754@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61755 pipe_lock(pipe);
61756
61757 for (;;) {
61758- if (!pipe->readers) {
61759+ if (!atomic_read(&pipe->readers)) {
61760 send_sig(SIGPIPE, current, 0);
61761 if (!ret)
61762 ret = -EPIPE;
61763@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61764 page_nr++;
61765 ret += buf->len;
61766
61767- if (pipe->files)
61768+ if (atomic_read(&pipe->files))
61769 do_wakeup = 1;
61770
61771 if (!--spd->nr_pages)
61772@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61773 do_wakeup = 0;
61774 }
61775
61776- pipe->waiting_writers++;
61777+ atomic_inc(&pipe->waiting_writers);
61778 pipe_wait(pipe);
61779- pipe->waiting_writers--;
61780+ atomic_dec(&pipe->waiting_writers);
61781 }
61782
61783 pipe_unlock(pipe);
61784@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
61785 old_fs = get_fs();
61786 set_fs(get_ds());
61787 /* The cast to a user pointer is valid due to the set_fs() */
61788- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
61789+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
61790 set_fs(old_fs);
61791
61792 return res;
61793@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
61794 old_fs = get_fs();
61795 set_fs(get_ds());
61796 /* The cast to a user pointer is valid due to the set_fs() */
61797- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
61798+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
61799 set_fs(old_fs);
61800
61801 return res;
61802@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
61803 goto err;
61804
61805 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
61806- vec[i].iov_base = (void __user *) page_address(page);
61807+ vec[i].iov_base = (void __force_user *) page_address(page);
61808 vec[i].iov_len = this_len;
61809 spd.pages[i] = page;
61810 spd.nr_pages++;
61811@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
61812 ops->release(pipe, buf);
61813 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
61814 pipe->nrbufs--;
61815- if (pipe->files)
61816+ if (atomic_read(&pipe->files))
61817 sd->need_wakeup = true;
61818 }
61819
61820@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
61821 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
61822 {
61823 while (!pipe->nrbufs) {
61824- if (!pipe->writers)
61825+ if (!atomic_read(&pipe->writers))
61826 return 0;
61827
61828- if (!pipe->waiting_writers && sd->num_spliced)
61829+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
61830 return 0;
61831
61832 if (sd->flags & SPLICE_F_NONBLOCK)
61833@@ -1193,7 +1193,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
61834 * out of the pipe right after the splice_to_pipe(). So set
61835 * PIPE_READERS appropriately.
61836 */
61837- pipe->readers = 1;
61838+ atomic_set(&pipe->readers, 1);
61839
61840 current->splice_pipe = pipe;
61841 }
61842@@ -1467,6 +1467,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
61843
61844 partial[buffers].offset = off;
61845 partial[buffers].len = plen;
61846+ partial[buffers].private = 0;
61847
61848 off = 0;
61849 len -= plen;
61850@@ -1769,9 +1770,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61851 ret = -ERESTARTSYS;
61852 break;
61853 }
61854- if (!pipe->writers)
61855+ if (!atomic_read(&pipe->writers))
61856 break;
61857- if (!pipe->waiting_writers) {
61858+ if (!atomic_read(&pipe->waiting_writers)) {
61859 if (flags & SPLICE_F_NONBLOCK) {
61860 ret = -EAGAIN;
61861 break;
61862@@ -1803,7 +1804,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61863 pipe_lock(pipe);
61864
61865 while (pipe->nrbufs >= pipe->buffers) {
61866- if (!pipe->readers) {
61867+ if (!atomic_read(&pipe->readers)) {
61868 send_sig(SIGPIPE, current, 0);
61869 ret = -EPIPE;
61870 break;
61871@@ -1816,9 +1817,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61872 ret = -ERESTARTSYS;
61873 break;
61874 }
61875- pipe->waiting_writers++;
61876+ atomic_inc(&pipe->waiting_writers);
61877 pipe_wait(pipe);
61878- pipe->waiting_writers--;
61879+ atomic_dec(&pipe->waiting_writers);
61880 }
61881
61882 pipe_unlock(pipe);
61883@@ -1854,14 +1855,14 @@ retry:
61884 pipe_double_lock(ipipe, opipe);
61885
61886 do {
61887- if (!opipe->readers) {
61888+ if (!atomic_read(&opipe->readers)) {
61889 send_sig(SIGPIPE, current, 0);
61890 if (!ret)
61891 ret = -EPIPE;
61892 break;
61893 }
61894
61895- if (!ipipe->nrbufs && !ipipe->writers)
61896+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
61897 break;
61898
61899 /*
61900@@ -1958,7 +1959,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
61901 pipe_double_lock(ipipe, opipe);
61902
61903 do {
61904- if (!opipe->readers) {
61905+ if (!atomic_read(&opipe->readers)) {
61906 send_sig(SIGPIPE, current, 0);
61907 if (!ret)
61908 ret = -EPIPE;
61909@@ -2003,7 +2004,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
61910 * return EAGAIN if we have the potential of some data in the
61911 * future, otherwise just return 0
61912 */
61913- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
61914+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
61915 ret = -EAGAIN;
61916
61917 pipe_unlock(ipipe);
61918diff --git a/fs/stat.c b/fs/stat.c
61919index 04ce1ac..a13dd1e 100644
61920--- a/fs/stat.c
61921+++ b/fs/stat.c
61922@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
61923 stat->gid = inode->i_gid;
61924 stat->rdev = inode->i_rdev;
61925 stat->size = i_size_read(inode);
61926- stat->atime = inode->i_atime;
61927- stat->mtime = inode->i_mtime;
61928+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
61929+ stat->atime = inode->i_ctime;
61930+ stat->mtime = inode->i_ctime;
61931+ } else {
61932+ stat->atime = inode->i_atime;
61933+ stat->mtime = inode->i_mtime;
61934+ }
61935 stat->ctime = inode->i_ctime;
61936 stat->blksize = (1 << inode->i_blkbits);
61937 stat->blocks = inode->i_blocks;
61938@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
61939 if (retval)
61940 return retval;
61941
61942- if (inode->i_op->getattr)
61943- return inode->i_op->getattr(path->mnt, path->dentry, stat);
61944+ if (inode->i_op->getattr) {
61945+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
61946+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
61947+ stat->atime = stat->ctime;
61948+ stat->mtime = stat->ctime;
61949+ }
61950+ return retval;
61951+ }
61952
61953 generic_fillattr(inode, stat);
61954 return 0;
61955diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
61956index 15c68f9..36a8b3e 100644
61957--- a/fs/sysfs/bin.c
61958+++ b/fs/sysfs/bin.c
61959@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
61960 return ret;
61961 }
61962
61963-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
61964- void *buf, int len, int write)
61965+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
61966+ void *buf, size_t len, int write)
61967 {
61968 struct file *file = vma->vm_file;
61969 struct bin_buffer *bb = file->private_data;
61970 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
61971- int ret;
61972+ ssize_t ret;
61973
61974 if (!bb->vm_ops)
61975 return -EINVAL;
61976diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
61977index e8e0e71..79c28ac5 100644
61978--- a/fs/sysfs/dir.c
61979+++ b/fs/sysfs/dir.c
61980@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
61981 *
61982 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61983 */
61984-static unsigned int sysfs_name_hash(const void *ns, const char *name)
61985+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
61986 {
61987 unsigned long hash = init_name_hash();
61988 unsigned int len = strlen(name);
61989@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
61990 struct sysfs_dirent *sd;
61991 int rc;
61992
61993+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
61994+ const char *parent_name = parent_sd->s_name;
61995+
61996+ mode = S_IFDIR | S_IRWXU;
61997+
61998+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
61999+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
62000+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
62001+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
62002+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
62003+#endif
62004+
62005 /* allocate */
62006 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
62007 if (!sd)
62008diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
62009index 602f56d..6853db8 100644
62010--- a/fs/sysfs/file.c
62011+++ b/fs/sysfs/file.c
62012@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
62013
62014 struct sysfs_open_dirent {
62015 atomic_t refcnt;
62016- atomic_t event;
62017+ atomic_unchecked_t event;
62018 wait_queue_head_t poll;
62019 struct list_head buffers; /* goes through sysfs_buffer.list */
62020 };
62021@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
62022 if (!sysfs_get_active(attr_sd))
62023 return -ENODEV;
62024
62025- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
62026+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
62027 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
62028
62029 sysfs_put_active(attr_sd);
62030@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
62031 return -ENOMEM;
62032
62033 atomic_set(&new_od->refcnt, 0);
62034- atomic_set(&new_od->event, 1);
62035+ atomic_set_unchecked(&new_od->event, 1);
62036 init_waitqueue_head(&new_od->poll);
62037 INIT_LIST_HEAD(&new_od->buffers);
62038 goto retry;
62039@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
62040
62041 sysfs_put_active(attr_sd);
62042
62043- if (buffer->event != atomic_read(&od->event))
62044+ if (buffer->event != atomic_read_unchecked(&od->event))
62045 goto trigger;
62046
62047 return DEFAULT_POLLMASK;
62048@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
62049
62050 od = sd->s_attr.open;
62051 if (od) {
62052- atomic_inc(&od->event);
62053+ atomic_inc_unchecked(&od->event);
62054 wake_up_interruptible(&od->poll);
62055 }
62056
62057diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
62058index 8c940df..25b733e 100644
62059--- a/fs/sysfs/symlink.c
62060+++ b/fs/sysfs/symlink.c
62061@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
62062
62063 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
62064 {
62065- char *page = nd_get_link(nd);
62066+ const char *page = nd_get_link(nd);
62067 if (!IS_ERR(page))
62068 free_page((unsigned long)page);
62069 }
62070diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
62071index 69d4889..a810bd4 100644
62072--- a/fs/sysv/sysv.h
62073+++ b/fs/sysv/sysv.h
62074@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
62075 #endif
62076 }
62077
62078-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
62079+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
62080 {
62081 if (sbi->s_bytesex == BYTESEX_PDP)
62082 return PDP_swab((__force __u32)n);
62083diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
62084index e18b988..f1d4ad0f 100644
62085--- a/fs/ubifs/io.c
62086+++ b/fs/ubifs/io.c
62087@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
62088 return err;
62089 }
62090
62091-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
62092+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
62093 {
62094 int err;
62095
62096diff --git a/fs/udf/misc.c b/fs/udf/misc.c
62097index c175b4d..8f36a16 100644
62098--- a/fs/udf/misc.c
62099+++ b/fs/udf/misc.c
62100@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
62101
62102 u8 udf_tag_checksum(const struct tag *t)
62103 {
62104- u8 *data = (u8 *)t;
62105+ const u8 *data = (const u8 *)t;
62106 u8 checksum = 0;
62107 int i;
62108 for (i = 0; i < sizeof(struct tag); ++i)
62109diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
62110index 8d974c4..b82f6ec 100644
62111--- a/fs/ufs/swab.h
62112+++ b/fs/ufs/swab.h
62113@@ -22,7 +22,7 @@ enum {
62114 BYTESEX_BE
62115 };
62116
62117-static inline u64
62118+static inline u64 __intentional_overflow(-1)
62119 fs64_to_cpu(struct super_block *sbp, __fs64 n)
62120 {
62121 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
62122@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
62123 return (__force __fs64)cpu_to_be64(n);
62124 }
62125
62126-static inline u32
62127+static inline u32 __intentional_overflow(-1)
62128 fs32_to_cpu(struct super_block *sbp, __fs32 n)
62129 {
62130 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
62131diff --git a/fs/utimes.c b/fs/utimes.c
62132index f4fb7ec..3fe03c0 100644
62133--- a/fs/utimes.c
62134+++ b/fs/utimes.c
62135@@ -1,6 +1,7 @@
62136 #include <linux/compiler.h>
62137 #include <linux/file.h>
62138 #include <linux/fs.h>
62139+#include <linux/security.h>
62140 #include <linux/linkage.h>
62141 #include <linux/mount.h>
62142 #include <linux/namei.h>
62143@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
62144 goto mnt_drop_write_and_out;
62145 }
62146 }
62147+
62148+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
62149+ error = -EACCES;
62150+ goto mnt_drop_write_and_out;
62151+ }
62152+
62153 mutex_lock(&inode->i_mutex);
62154 error = notify_change(path->dentry, &newattrs);
62155 mutex_unlock(&inode->i_mutex);
62156diff --git a/fs/xattr.c b/fs/xattr.c
62157index 3377dff..4d074d9 100644
62158--- a/fs/xattr.c
62159+++ b/fs/xattr.c
62160@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
62161 return rc;
62162 }
62163
62164+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
62165+ssize_t
62166+pax_getxattr(struct dentry *dentry, void *value, size_t size)
62167+{
62168+ struct inode *inode = dentry->d_inode;
62169+ ssize_t error;
62170+
62171+ error = inode_permission(inode, MAY_EXEC);
62172+ if (error)
62173+ return error;
62174+
62175+ if (inode->i_op->getxattr)
62176+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
62177+ else
62178+ error = -EOPNOTSUPP;
62179+
62180+ return error;
62181+}
62182+EXPORT_SYMBOL(pax_getxattr);
62183+#endif
62184+
62185 ssize_t
62186 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
62187 {
62188@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
62189 * Extended attribute SET operations
62190 */
62191 static long
62192-setxattr(struct dentry *d, const char __user *name, const void __user *value,
62193+setxattr(struct path *path, const char __user *name, const void __user *value,
62194 size_t size, int flags)
62195 {
62196 int error;
62197@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
62198 posix_acl_fix_xattr_from_user(kvalue, size);
62199 }
62200
62201- error = vfs_setxattr(d, kname, kvalue, size, flags);
62202+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
62203+ error = -EACCES;
62204+ goto out;
62205+ }
62206+
62207+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
62208 out:
62209 if (vvalue)
62210 vfree(vvalue);
62211@@ -377,7 +403,7 @@ retry:
62212 return error;
62213 error = mnt_want_write(path.mnt);
62214 if (!error) {
62215- error = setxattr(path.dentry, name, value, size, flags);
62216+ error = setxattr(&path, name, value, size, flags);
62217 mnt_drop_write(path.mnt);
62218 }
62219 path_put(&path);
62220@@ -401,7 +427,7 @@ retry:
62221 return error;
62222 error = mnt_want_write(path.mnt);
62223 if (!error) {
62224- error = setxattr(path.dentry, name, value, size, flags);
62225+ error = setxattr(&path, name, value, size, flags);
62226 mnt_drop_write(path.mnt);
62227 }
62228 path_put(&path);
62229@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
62230 const void __user *,value, size_t, size, int, flags)
62231 {
62232 struct fd f = fdget(fd);
62233- struct dentry *dentry;
62234 int error = -EBADF;
62235
62236 if (!f.file)
62237 return error;
62238- dentry = f.file->f_path.dentry;
62239- audit_inode(NULL, dentry, 0);
62240+ audit_inode(NULL, f.file->f_path.dentry, 0);
62241 error = mnt_want_write_file(f.file);
62242 if (!error) {
62243- error = setxattr(dentry, name, value, size, flags);
62244+ error = setxattr(&f.file->f_path, name, value, size, flags);
62245 mnt_drop_write_file(f.file);
62246 }
62247 fdput(f);
62248diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
62249index 9fbea87..6b19972 100644
62250--- a/fs/xattr_acl.c
62251+++ b/fs/xattr_acl.c
62252@@ -76,8 +76,8 @@ struct posix_acl *
62253 posix_acl_from_xattr(struct user_namespace *user_ns,
62254 const void *value, size_t size)
62255 {
62256- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
62257- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
62258+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
62259+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
62260 int count;
62261 struct posix_acl *acl;
62262 struct posix_acl_entry *acl_e;
62263diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
62264index 8904284..ee0e14b 100644
62265--- a/fs/xfs/xfs_bmap.c
62266+++ b/fs/xfs/xfs_bmap.c
62267@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
62268
62269 #else
62270 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
62271-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
62272+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
62273 #endif /* DEBUG */
62274
62275 /*
62276diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
62277index 6157424..ac98f6d 100644
62278--- a/fs/xfs/xfs_dir2_sf.c
62279+++ b/fs/xfs/xfs_dir2_sf.c
62280@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
62281 }
62282
62283 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
62284- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
62285+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
62286+ char name[sfep->namelen];
62287+ memcpy(name, sfep->name, sfep->namelen);
62288+ if (filldir(dirent, name, sfep->namelen,
62289+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
62290+ *offset = off & 0x7fffffff;
62291+ return 0;
62292+ }
62293+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
62294 off & 0x7fffffff, ino, DT_UNKNOWN)) {
62295 *offset = off & 0x7fffffff;
62296 return 0;
62297diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
62298index 5e99968..45bd327 100644
62299--- a/fs/xfs/xfs_ioctl.c
62300+++ b/fs/xfs/xfs_ioctl.c
62301@@ -127,7 +127,7 @@ xfs_find_handle(
62302 }
62303
62304 error = -EFAULT;
62305- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
62306+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
62307 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
62308 goto out_put;
62309
62310diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
62311index ca9ecaa..60100c7 100644
62312--- a/fs/xfs/xfs_iops.c
62313+++ b/fs/xfs/xfs_iops.c
62314@@ -395,7 +395,7 @@ xfs_vn_put_link(
62315 struct nameidata *nd,
62316 void *p)
62317 {
62318- char *s = nd_get_link(nd);
62319+ const char *s = nd_get_link(nd);
62320
62321 if (!IS_ERR(s))
62322 kfree(s);
62323diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
62324new file mode 100644
62325index 0000000..6fb5192
62326--- /dev/null
62327+++ b/grsecurity/Kconfig
62328@@ -0,0 +1,1079 @@
62329+#
62330+# grecurity configuration
62331+#
62332+menu "Memory Protections"
62333+depends on GRKERNSEC
62334+
62335+config GRKERNSEC_KMEM
62336+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
62337+ default y if GRKERNSEC_CONFIG_AUTO
62338+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
62339+ help
62340+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
62341+ be written to or read from to modify or leak the contents of the running
62342+ kernel. /dev/port will also not be allowed to be opened and support
62343+ for /dev/cpu/*/msr will be removed. If you have module
62344+ support disabled, enabling this will close up five ways that are
62345+ currently used to insert malicious code into the running kernel.
62346+
62347+ Even with all these features enabled, we still highly recommend that
62348+ you use the RBAC system, as it is still possible for an attacker to
62349+ modify the running kernel through privileged I/O granted by ioperm/iopl.
62350+
62351+ If you are not using XFree86, you may be able to stop this additional
62352+ case by enabling the 'Disable privileged I/O' option. Though nothing
62353+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
62354+ but only to video memory, which is the only writing we allow in this
62355+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
62356+ not be allowed to mprotect it with PROT_WRITE later.
62357+ Enabling this feature will prevent the "cpupower" and "powertop" tools
62358+ from working.
62359+
62360+ It is highly recommended that you say Y here if you meet all the
62361+ conditions above.
62362+
62363+config GRKERNSEC_VM86
62364+ bool "Restrict VM86 mode"
62365+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62366+ depends on X86_32
62367+
62368+ help
62369+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
62370+ make use of a special execution mode on 32bit x86 processors called
62371+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
62372+ video cards and will still work with this option enabled. The purpose
62373+ of the option is to prevent exploitation of emulation errors in
62374+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
62375+ Nearly all users should be able to enable this option.
62376+
62377+config GRKERNSEC_IO
62378+ bool "Disable privileged I/O"
62379+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62380+ depends on X86
62381+ select RTC_CLASS
62382+ select RTC_INTF_DEV
62383+ select RTC_DRV_CMOS
62384+
62385+ help
62386+ If you say Y here, all ioperm and iopl calls will return an error.
62387+ Ioperm and iopl can be used to modify the running kernel.
62388+ Unfortunately, some programs need this access to operate properly,
62389+ the most notable of which are XFree86 and hwclock. hwclock can be
62390+ remedied by having RTC support in the kernel, so real-time
62391+ clock support is enabled if this option is enabled, to ensure
62392+ that hwclock operates correctly. XFree86 still will not
62393+ operate correctly with this option enabled, so DO NOT CHOOSE Y
62394+ IF YOU USE XFree86. If you use XFree86 and you still want to
62395+ protect your kernel against modification, use the RBAC system.
62396+
62397+config GRKERNSEC_JIT_HARDEN
62398+ bool "Harden BPF JIT against spray attacks"
62399+ default y if GRKERNSEC_CONFIG_AUTO
62400+ depends on BPF_JIT
62401+ help
62402+ If you say Y here, the native code generated by the kernel's Berkeley
62403+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
62404+ attacks that attempt to fit attacker-beneficial instructions in
62405+ 32bit immediate fields of JIT-generated native instructions. The
62406+ attacker will generally aim to cause an unintended instruction sequence
62407+ of JIT-generated native code to execute by jumping into the middle of
62408+ a generated instruction. This feature effectively randomizes the 32bit
62409+ immediate constants present in the generated code to thwart such attacks.
62410+
62411+ If you're using KERNEXEC, it's recommended that you enable this option
62412+ to supplement the hardening of the kernel.
62413+
62414+config GRKERNSEC_PERF_HARDEN
62415+ bool "Disable unprivileged PERF_EVENTS usage by default"
62416+ default y if GRKERNSEC_CONFIG_AUTO
62417+ depends on PERF_EVENTS
62418+ help
62419+ If you say Y here, the range of acceptable values for the
62420+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
62421+ default to a new value: 3. When the sysctl is set to this value, no
62422+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
62423+
62424+ Though PERF_EVENTS can be used legitimately for performance monitoring
62425+ and low-level application profiling, it is forced on regardless of
62426+ configuration, has been at fault for several vulnerabilities, and
62427+ creates new opportunities for side channels and other information leaks.
62428+
62429+ This feature puts PERF_EVENTS into a secure default state and permits
62430+ the administrator to change out of it temporarily if unprivileged
62431+ application profiling is needed.
62432+
62433+config GRKERNSEC_RAND_THREADSTACK
62434+ bool "Insert random gaps between thread stacks"
62435+ default y if GRKERNSEC_CONFIG_AUTO
62436+ depends on PAX_RANDMMAP && !PPC
62437+ help
62438+ If you say Y here, a random-sized gap will be enforced between allocated
62439+ thread stacks. Glibc's NPTL and other threading libraries that
62440+ pass MAP_STACK to the kernel for thread stack allocation are supported.
62441+ The implementation currently provides 8 bits of entropy for the gap.
62442+
62443+ Many distributions do not compile threaded remote services with the
62444+ -fstack-check argument to GCC, causing the variable-sized stack-based
62445+ allocator, alloca(), to not probe the stack on allocation. This
62446+ permits an unbounded alloca() to skip over any guard page and potentially
62447+ modify another thread's stack reliably. An enforced random gap
62448+ reduces the reliability of such an attack and increases the chance
62449+ that such a read/write to another thread's stack instead lands in
62450+ an unmapped area, causing a crash and triggering grsecurity's
62451+ anti-bruteforcing logic.
62452+
62453+config GRKERNSEC_PROC_MEMMAP
62454+ bool "Harden ASLR against information leaks and entropy reduction"
62455+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
62456+ depends on PAX_NOEXEC || PAX_ASLR
62457+ help
62458+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
62459+ give no information about the addresses of its mappings if
62460+ PaX features that rely on random addresses are enabled on the task.
62461+ In addition to sanitizing this information and disabling other
62462+ dangerous sources of information, this option causes reads of sensitive
62463+ /proc/<pid> entries where the file descriptor was opened in a different
62464+ task than the one performing the read. Such attempts are logged.
62465+ This option also limits argv/env strings for suid/sgid binaries
62466+ to 512KB to prevent a complete exhaustion of the stack entropy provided
62467+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
62468+ binaries to prevent alternative mmap layouts from being abused.
62469+
62470+ If you use PaX it is essential that you say Y here as it closes up
62471+ several holes that make full ASLR useless locally.
62472+
62473+config GRKERNSEC_BRUTE
62474+ bool "Deter exploit bruteforcing"
62475+ default y if GRKERNSEC_CONFIG_AUTO
62476+ help
62477+ If you say Y here, attempts to bruteforce exploits against forking
62478+ daemons such as apache or sshd, as well as against suid/sgid binaries
62479+ will be deterred. When a child of a forking daemon is killed by PaX
62480+ or crashes due to an illegal instruction or other suspicious signal,
62481+ the parent process will be delayed 30 seconds upon every subsequent
62482+ fork until the administrator is able to assess the situation and
62483+ restart the daemon.
62484+ In the suid/sgid case, the attempt is logged, the user has all their
62485+ existing instances of the suid/sgid binary terminated and will
62486+ be unable to execute any suid/sgid binaries for 15 minutes.
62487+
62488+ It is recommended that you also enable signal logging in the auditing
62489+ section so that logs are generated when a process triggers a suspicious
62490+ signal.
62491+ If the sysctl option is enabled, a sysctl option with name
62492+ "deter_bruteforce" is created.
62493+
62494+
62495+config GRKERNSEC_MODHARDEN
62496+ bool "Harden module auto-loading"
62497+ default y if GRKERNSEC_CONFIG_AUTO
62498+ depends on MODULES
62499+ help
62500+ If you say Y here, module auto-loading in response to use of some
62501+ feature implemented by an unloaded module will be restricted to
62502+ root users. Enabling this option helps defend against attacks
62503+ by unprivileged users who abuse the auto-loading behavior to
62504+ cause a vulnerable module to load that is then exploited.
62505+
62506+ If this option prevents a legitimate use of auto-loading for a
62507+ non-root user, the administrator can execute modprobe manually
62508+ with the exact name of the module mentioned in the alert log.
62509+ Alternatively, the administrator can add the module to the list
62510+ of modules loaded at boot by modifying init scripts.
62511+
62512+ Modification of init scripts will most likely be needed on
62513+ Ubuntu servers with encrypted home directory support enabled,
62514+ as the first non-root user logging in will cause the ecb(aes),
62515+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
62516+
62517+config GRKERNSEC_HIDESYM
62518+ bool "Hide kernel symbols"
62519+ default y if GRKERNSEC_CONFIG_AUTO
62520+ select PAX_USERCOPY_SLABS
62521+ help
62522+ If you say Y here, getting information on loaded modules, and
62523+ displaying all kernel symbols through a syscall will be restricted
62524+ to users with CAP_SYS_MODULE. For software compatibility reasons,
62525+ /proc/kallsyms will be restricted to the root user. The RBAC
62526+ system can hide that entry even from root.
62527+
62528+ This option also prevents leaking of kernel addresses through
62529+ several /proc entries.
62530+
62531+ Note that this option is only effective provided the following
62532+ conditions are met:
62533+ 1) The kernel using grsecurity is not precompiled by some distribution
62534+ 2) You have also enabled GRKERNSEC_DMESG
62535+ 3) You are using the RBAC system and hiding other files such as your
62536+ kernel image and System.map. Alternatively, enabling this option
62537+ causes the permissions on /boot, /lib/modules, and the kernel
62538+ source directory to change at compile time to prevent
62539+ reading by non-root users.
62540+ If the above conditions are met, this option will aid in providing a
62541+ useful protection against local kernel exploitation of overflows
62542+ and arbitrary read/write vulnerabilities.
62543+
62544+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
62545+ in addition to this feature.
62546+
62547+config GRKERNSEC_KERN_LOCKOUT
62548+ bool "Active kernel exploit response"
62549+ default y if GRKERNSEC_CONFIG_AUTO
62550+ depends on X86 || ARM || PPC || SPARC
62551+ help
62552+ If you say Y here, when a PaX alert is triggered due to suspicious
62553+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
62554+ or an OOPS occurs due to bad memory accesses, instead of just
62555+ terminating the offending process (and potentially allowing
62556+ a subsequent exploit from the same user), we will take one of two
62557+ actions:
62558+ If the user was root, we will panic the system
62559+ If the user was non-root, we will log the attempt, terminate
62560+ all processes owned by the user, then prevent them from creating
62561+ any new processes until the system is restarted
62562+ This deters repeated kernel exploitation/bruteforcing attempts
62563+ and is useful for later forensics.
62564+
62565+endmenu
62566+menu "Role Based Access Control Options"
62567+depends on GRKERNSEC
62568+
62569+config GRKERNSEC_RBAC_DEBUG
62570+ bool
62571+
62572+config GRKERNSEC_NO_RBAC
62573+ bool "Disable RBAC system"
62574+ help
62575+ If you say Y here, the /dev/grsec device will be removed from the kernel,
62576+ preventing the RBAC system from being enabled. You should only say Y
62577+ here if you have no intention of using the RBAC system, so as to prevent
62578+ an attacker with root access from misusing the RBAC system to hide files
62579+ and processes when loadable module support and /dev/[k]mem have been
62580+ locked down.
62581+
62582+config GRKERNSEC_ACL_HIDEKERN
62583+ bool "Hide kernel processes"
62584+ help
62585+ If you say Y here, all kernel threads will be hidden to all
62586+ processes but those whose subject has the "view hidden processes"
62587+ flag.
62588+
62589+config GRKERNSEC_ACL_MAXTRIES
62590+ int "Maximum tries before password lockout"
62591+ default 3
62592+ help
62593+ This option enforces the maximum number of times a user can attempt
62594+ to authorize themselves with the grsecurity RBAC system before being
62595+ denied the ability to attempt authorization again for a specified time.
62596+ The lower the number, the harder it will be to brute-force a password.
62597+
62598+config GRKERNSEC_ACL_TIMEOUT
62599+ int "Time to wait after max password tries, in seconds"
62600+ default 30
62601+ help
62602+ This option specifies the time the user must wait after attempting to
62603+ authorize to the RBAC system with the maximum number of invalid
62604+ passwords. The higher the number, the harder it will be to brute-force
62605+ a password.
62606+
62607+endmenu
62608+menu "Filesystem Protections"
62609+depends on GRKERNSEC
62610+
62611+config GRKERNSEC_PROC
62612+ bool "Proc restrictions"
62613+ default y if GRKERNSEC_CONFIG_AUTO
62614+ help
62615+ If you say Y here, the permissions of the /proc filesystem
62616+ will be altered to enhance system security and privacy. You MUST
62617+ choose either a user only restriction or a user and group restriction.
62618+ Depending upon the option you choose, you can either restrict users to
62619+ see only the processes they themselves run, or choose a group that can
62620+ view all processes and files normally restricted to root if you choose
62621+ the "restrict to user only" option. NOTE: If you're running identd or
62622+ ntpd as a non-root user, you will have to run it as the group you
62623+ specify here.
62624+
62625+config GRKERNSEC_PROC_USER
62626+ bool "Restrict /proc to user only"
62627+ depends on GRKERNSEC_PROC
62628+ help
62629+ If you say Y here, non-root users will only be able to view their own
62630+ processes, and restricts them from viewing network-related information,
62631+ and viewing kernel symbol and module information.
62632+
62633+config GRKERNSEC_PROC_USERGROUP
62634+ bool "Allow special group"
62635+ default y if GRKERNSEC_CONFIG_AUTO
62636+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
62637+ help
62638+ If you say Y here, you will be able to select a group that will be
62639+ able to view all processes and network-related information. If you've
62640+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
62641+ remain hidden. This option is useful if you want to run identd as
62642+ a non-root user. The group you select may also be chosen at boot time
62643+ via "grsec_proc_gid=" on the kernel commandline.
62644+
62645+config GRKERNSEC_PROC_GID
62646+ int "GID for special group"
62647+ depends on GRKERNSEC_PROC_USERGROUP
62648+ default 1001
62649+
62650+config GRKERNSEC_PROC_ADD
62651+ bool "Additional restrictions"
62652+ default y if GRKERNSEC_CONFIG_AUTO
62653+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
62654+ help
62655+ If you say Y here, additional restrictions will be placed on
62656+ /proc that keep normal users from viewing device information and
62657+ slabinfo information that could be useful for exploits.
62658+
62659+config GRKERNSEC_LINK
62660+ bool "Linking restrictions"
62661+ default y if GRKERNSEC_CONFIG_AUTO
62662+ help
62663+ If you say Y here, /tmp race exploits will be prevented, since users
62664+ will no longer be able to follow symlinks owned by other users in
62665+ world-writable +t directories (e.g. /tmp), unless the owner of the
62666+ symlink is the owner of the directory. users will also not be
62667+ able to hardlink to files they do not own. If the sysctl option is
62668+ enabled, a sysctl option with name "linking_restrictions" is created.
62669+
62670+config GRKERNSEC_SYMLINKOWN
62671+ bool "Kernel-enforced SymlinksIfOwnerMatch"
62672+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
62673+ help
62674+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
62675+ that prevents it from being used as a security feature. As Apache
62676+ verifies the symlink by performing a stat() against the target of
62677+ the symlink before it is followed, an attacker can setup a symlink
62678+ to point to a same-owned file, then replace the symlink with one
62679+ that targets another user's file just after Apache "validates" the
62680+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
62681+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
62682+ will be in place for the group you specify. If the sysctl option
62683+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
62684+ created.
62685+
62686+config GRKERNSEC_SYMLINKOWN_GID
62687+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
62688+ depends on GRKERNSEC_SYMLINKOWN
62689+ default 1006
62690+ help
62691+ Setting this GID determines what group kernel-enforced
62692+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
62693+ is enabled, a sysctl option with name "symlinkown_gid" is created.
62694+
62695+config GRKERNSEC_FIFO
62696+ bool "FIFO restrictions"
62697+ default y if GRKERNSEC_CONFIG_AUTO
62698+ help
62699+ If you say Y here, users will not be able to write to FIFOs they don't
62700+ own in world-writable +t directories (e.g. /tmp), unless the owner of
62701+ the FIFO is the same owner of the directory it's held in. If the sysctl
62702+ option is enabled, a sysctl option with name "fifo_restrictions" is
62703+ created.
62704+
62705+config GRKERNSEC_SYSFS_RESTRICT
62706+ bool "Sysfs/debugfs restriction"
62707+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62708+ depends on SYSFS
62709+ help
62710+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
62711+ any filesystem normally mounted under it (e.g. debugfs) will be
62712+ mostly accessible only by root. These filesystems generally provide access
62713+ to hardware and debug information that isn't appropriate for unprivileged
62714+ users of the system. Sysfs and debugfs have also become a large source
62715+ of new vulnerabilities, ranging from infoleaks to local compromise.
62716+ There has been very little oversight with an eye toward security involved
62717+ in adding new exporters of information to these filesystems, so their
62718+ use is discouraged.
62719+ For reasons of compatibility, a few directories have been whitelisted
62720+ for access by non-root users:
62721+ /sys/fs/selinux
62722+ /sys/fs/fuse
62723+ /sys/devices/system/cpu
62724+
62725+config GRKERNSEC_ROFS
62726+ bool "Runtime read-only mount protection"
62727+ depends on SYSCTL
62728+ help
62729+ If you say Y here, a sysctl option with name "romount_protect" will
62730+ be created. By setting this option to 1 at runtime, filesystems
62731+ will be protected in the following ways:
62732+ * No new writable mounts will be allowed
62733+ * Existing read-only mounts won't be able to be remounted read/write
62734+ * Write operations will be denied on all block devices
62735+ This option acts independently of grsec_lock: once it is set to 1,
62736+ it cannot be turned off. Therefore, please be mindful of the resulting
62737+ behavior if this option is enabled in an init script on a read-only
62738+ filesystem. This feature is mainly intended for secure embedded systems.
62739+
62740+config GRKERNSEC_DEVICE_SIDECHANNEL
62741+ bool "Eliminate stat/notify-based device sidechannels"
62742+ default y if GRKERNSEC_CONFIG_AUTO
62743+ help
62744+ If you say Y here, timing analyses on block or character
62745+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
62746+ will be thwarted for unprivileged users. If a process without
62747+ CAP_MKNOD stats such a device, the last access and last modify times
62748+ will match the device's create time. No access or modify events
62749+ will be triggered through inotify/dnotify/fanotify for such devices.
62750+ This feature will prevent attacks that may at a minimum
62751+ allow an attacker to determine the administrator's password length.
62752+
62753+config GRKERNSEC_CHROOT
62754+ bool "Chroot jail restrictions"
62755+ default y if GRKERNSEC_CONFIG_AUTO
62756+ help
62757+ If you say Y here, you will be able to choose several options that will
62758+ make breaking out of a chrooted jail much more difficult. If you
62759+ encounter no software incompatibilities with the following options, it
62760+ is recommended that you enable each one.
62761+
62762+config GRKERNSEC_CHROOT_MOUNT
62763+ bool "Deny mounts"
62764+ default y if GRKERNSEC_CONFIG_AUTO
62765+ depends on GRKERNSEC_CHROOT
62766+ help
62767+ If you say Y here, processes inside a chroot will not be able to
62768+ mount or remount filesystems. If the sysctl option is enabled, a
62769+ sysctl option with name "chroot_deny_mount" is created.
62770+
62771+config GRKERNSEC_CHROOT_DOUBLE
62772+ bool "Deny double-chroots"
62773+ default y if GRKERNSEC_CONFIG_AUTO
62774+ depends on GRKERNSEC_CHROOT
62775+ help
62776+ If you say Y here, processes inside a chroot will not be able to chroot
62777+ again outside the chroot. This is a widely used method of breaking
62778+ out of a chroot jail and should not be allowed. If the sysctl
62779+ option is enabled, a sysctl option with name
62780+ "chroot_deny_chroot" is created.
62781+
62782+config GRKERNSEC_CHROOT_PIVOT
62783+ bool "Deny pivot_root in chroot"
62784+ default y if GRKERNSEC_CONFIG_AUTO
62785+ depends on GRKERNSEC_CHROOT
62786+ help
62787+ If you say Y here, processes inside a chroot will not be able to use
62788+ a function called pivot_root() that was introduced in Linux 2.3.41. It
62789+ works similar to chroot in that it changes the root filesystem. This
62790+ function could be misused in a chrooted process to attempt to break out
62791+ of the chroot, and therefore should not be allowed. If the sysctl
62792+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
62793+ created.
62794+
62795+config GRKERNSEC_CHROOT_CHDIR
62796+ bool "Enforce chdir(\"/\") on all chroots"
62797+ default y if GRKERNSEC_CONFIG_AUTO
62798+ depends on GRKERNSEC_CHROOT
62799+ help
62800+ If you say Y here, the current working directory of all newly-chrooted
62801+ applications will be set to the the root directory of the chroot.
62802+ The man page on chroot(2) states:
62803+ Note that this call does not change the current working
62804+ directory, so that `.' can be outside the tree rooted at
62805+ `/'. In particular, the super-user can escape from a
62806+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
62807+
62808+ It is recommended that you say Y here, since it's not known to break
62809+ any software. If the sysctl option is enabled, a sysctl option with
62810+ name "chroot_enforce_chdir" is created.
62811+
62812+config GRKERNSEC_CHROOT_CHMOD
62813+ bool "Deny (f)chmod +s"
62814+ default y if GRKERNSEC_CONFIG_AUTO
62815+ depends on GRKERNSEC_CHROOT
62816+ help
62817+ If you say Y here, processes inside a chroot will not be able to chmod
62818+ or fchmod files to make them have suid or sgid bits. This protects
62819+ against another published method of breaking a chroot. If the sysctl
62820+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
62821+ created.
62822+
62823+config GRKERNSEC_CHROOT_FCHDIR
62824+ bool "Deny fchdir out of chroot"
62825+ default y if GRKERNSEC_CONFIG_AUTO
62826+ depends on GRKERNSEC_CHROOT
62827+ help
62828+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
62829+ to a file descriptor of the chrooting process that points to a directory
62830+ outside the filesystem will be stopped. If the sysctl option
62831+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
62832+
62833+config GRKERNSEC_CHROOT_MKNOD
62834+ bool "Deny mknod"
62835+ default y if GRKERNSEC_CONFIG_AUTO
62836+ depends on GRKERNSEC_CHROOT
62837+ help
62838+ If you say Y here, processes inside a chroot will not be allowed to
62839+ mknod. The problem with using mknod inside a chroot is that it
62840+ would allow an attacker to create a device entry that is the same
62841+ as one on the physical root of your system, which could range from
62842+ anything from the console device to a device for your harddrive (which
62843+ they could then use to wipe the drive or steal data). It is recommended
62844+ that you say Y here, unless you run into software incompatibilities.
62845+ If the sysctl option is enabled, a sysctl option with name
62846+ "chroot_deny_mknod" is created.
62847+
62848+config GRKERNSEC_CHROOT_SHMAT
62849+ bool "Deny shmat() out of chroot"
62850+ default y if GRKERNSEC_CONFIG_AUTO
62851+ depends on GRKERNSEC_CHROOT
62852+ help
62853+ If you say Y here, processes inside a chroot will not be able to attach
62854+ to shared memory segments that were created outside of the chroot jail.
62855+ It is recommended that you say Y here. If the sysctl option is enabled,
62856+ a sysctl option with name "chroot_deny_shmat" is created.
62857+
62858+config GRKERNSEC_CHROOT_UNIX
62859+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
62860+ default y if GRKERNSEC_CONFIG_AUTO
62861+ depends on GRKERNSEC_CHROOT
62862+ help
62863+ If you say Y here, processes inside a chroot will not be able to
62864+ connect to abstract (meaning not belonging to a filesystem) Unix
62865+ domain sockets that were bound outside of a chroot. It is recommended
62866+ that you say Y here. If the sysctl option is enabled, a sysctl option
62867+ with name "chroot_deny_unix" is created.
62868+
62869+config GRKERNSEC_CHROOT_FINDTASK
62870+ bool "Protect outside processes"
62871+ default y if GRKERNSEC_CONFIG_AUTO
62872+ depends on GRKERNSEC_CHROOT
62873+ help
62874+ If you say Y here, processes inside a chroot will not be able to
62875+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
62876+ getsid, or view any process outside of the chroot. If the sysctl
62877+ option is enabled, a sysctl option with name "chroot_findtask" is
62878+ created.
62879+
62880+config GRKERNSEC_CHROOT_NICE
62881+ bool "Restrict priority changes"
62882+ default y if GRKERNSEC_CONFIG_AUTO
62883+ depends on GRKERNSEC_CHROOT
62884+ help
62885+ If you say Y here, processes inside a chroot will not be able to raise
62886+ the priority of processes in the chroot, or alter the priority of
62887+ processes outside the chroot. This provides more security than simply
62888+ removing CAP_SYS_NICE from the process' capability set. If the
62889+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
62890+ is created.
62891+
62892+config GRKERNSEC_CHROOT_SYSCTL
62893+ bool "Deny sysctl writes"
62894+ default y if GRKERNSEC_CONFIG_AUTO
62895+ depends on GRKERNSEC_CHROOT
62896+ help
62897+ If you say Y here, an attacker in a chroot will not be able to
62898+ write to sysctl entries, either by sysctl(2) or through a /proc
62899+ interface. It is strongly recommended that you say Y here. If the
62900+ sysctl option is enabled, a sysctl option with name
62901+ "chroot_deny_sysctl" is created.
62902+
62903+config GRKERNSEC_CHROOT_CAPS
62904+ bool "Capability restrictions"
62905+ default y if GRKERNSEC_CONFIG_AUTO
62906+ depends on GRKERNSEC_CHROOT
62907+ help
62908+ If you say Y here, the capabilities on all processes within a
62909+ chroot jail will be lowered to stop module insertion, raw i/o,
62910+ system and net admin tasks, rebooting the system, modifying immutable
62911+ files, modifying IPC owned by another, and changing the system time.
62912+ This is left an option because it can break some apps. Disable this
62913+ if your chrooted apps are having problems performing those kinds of
62914+ tasks. If the sysctl option is enabled, a sysctl option with
62915+ name "chroot_caps" is created.
62916+
62917+config GRKERNSEC_CHROOT_INITRD
62918+ bool "Exempt initrd tasks from restrictions"
62919+ default y if GRKERNSEC_CONFIG_AUTO
62920+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
62921+ help
62922+ If you say Y here, tasks started prior to init will be exempted from
62923+ grsecurity's chroot restrictions. This option is mainly meant to
62924+ resolve Plymouth's performing privileged operations unnecessarily
62925+ in a chroot.
62926+
62927+endmenu
62928+menu "Kernel Auditing"
62929+depends on GRKERNSEC
62930+
62931+config GRKERNSEC_AUDIT_GROUP
62932+ bool "Single group for auditing"
62933+ help
62934+ If you say Y here, the exec and chdir logging features will only operate
62935+ on a group you specify. This option is recommended if you only want to
62936+ watch certain users instead of having a large amount of logs from the
62937+ entire system. If the sysctl option is enabled, a sysctl option with
62938+ name "audit_group" is created.
62939+
62940+config GRKERNSEC_AUDIT_GID
62941+ int "GID for auditing"
62942+ depends on GRKERNSEC_AUDIT_GROUP
62943+ default 1007
62944+
62945+config GRKERNSEC_EXECLOG
62946+ bool "Exec logging"
62947+ help
62948+ If you say Y here, all execve() calls will be logged (since the
62949+ other exec*() calls are frontends to execve(), all execution
62950+ will be logged). Useful for shell-servers that like to keep track
62951+ of their users. If the sysctl option is enabled, a sysctl option with
62952+ name "exec_logging" is created.
62953+ WARNING: This option when enabled will produce a LOT of logs, especially
62954+ on an active system.
62955+
62956+config GRKERNSEC_RESLOG
62957+ bool "Resource logging"
62958+ default y if GRKERNSEC_CONFIG_AUTO
62959+ help
62960+ If you say Y here, all attempts to overstep resource limits will
62961+ be logged with the resource name, the requested size, and the current
62962+ limit. It is highly recommended that you say Y here. If the sysctl
62963+ option is enabled, a sysctl option with name "resource_logging" is
62964+ created. If the RBAC system is enabled, the sysctl value is ignored.
62965+
62966+config GRKERNSEC_CHROOT_EXECLOG
62967+ bool "Log execs within chroot"
62968+ help
62969+ If you say Y here, all executions inside a chroot jail will be logged
62970+ to syslog. This can cause a large amount of logs if certain
62971+ applications (eg. djb's daemontools) are installed on the system, and
62972+ is therefore left as an option. If the sysctl option is enabled, a
62973+ sysctl option with name "chroot_execlog" is created.
62974+
62975+config GRKERNSEC_AUDIT_PTRACE
62976+ bool "Ptrace logging"
62977+ help
62978+ If you say Y here, all attempts to attach to a process via ptrace
62979+ will be logged. If the sysctl option is enabled, a sysctl option
62980+ with name "audit_ptrace" is created.
62981+
62982+config GRKERNSEC_AUDIT_CHDIR
62983+ bool "Chdir logging"
62984+ help
62985+ If you say Y here, all chdir() calls will be logged. If the sysctl
62986+ option is enabled, a sysctl option with name "audit_chdir" is created.
62987+
62988+config GRKERNSEC_AUDIT_MOUNT
62989+ bool "(Un)Mount logging"
62990+ help
62991+ If you say Y here, all mounts and unmounts will be logged. If the
62992+ sysctl option is enabled, a sysctl option with name "audit_mount" is
62993+ created.
62994+
62995+config GRKERNSEC_SIGNAL
62996+ bool "Signal logging"
62997+ default y if GRKERNSEC_CONFIG_AUTO
62998+ help
62999+ If you say Y here, certain important signals will be logged, such as
63000+ SIGSEGV, which will as a result inform you of when a error in a program
63001+ occurred, which in some cases could mean a possible exploit attempt.
63002+ If the sysctl option is enabled, a sysctl option with name
63003+ "signal_logging" is created.
63004+
63005+config GRKERNSEC_FORKFAIL
63006+ bool "Fork failure logging"
63007+ help
63008+ If you say Y here, all failed fork() attempts will be logged.
63009+ This could suggest a fork bomb, or someone attempting to overstep
63010+ their process limit. If the sysctl option is enabled, a sysctl option
63011+ with name "forkfail_logging" is created.
63012+
63013+config GRKERNSEC_TIME
63014+ bool "Time change logging"
63015+ default y if GRKERNSEC_CONFIG_AUTO
63016+ help
63017+ If you say Y here, any changes of the system clock will be logged.
63018+ If the sysctl option is enabled, a sysctl option with name
63019+ "timechange_logging" is created.
63020+
63021+config GRKERNSEC_PROC_IPADDR
63022+ bool "/proc/<pid>/ipaddr support"
63023+ default y if GRKERNSEC_CONFIG_AUTO
63024+ help
63025+ If you say Y here, a new entry will be added to each /proc/<pid>
63026+ directory that contains the IP address of the person using the task.
63027+ The IP is carried across local TCP and AF_UNIX stream sockets.
63028+ This information can be useful for IDS/IPSes to perform remote response
63029+ to a local attack. The entry is readable by only the owner of the
63030+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
63031+ the RBAC system), and thus does not create privacy concerns.
63032+
63033+config GRKERNSEC_RWXMAP_LOG
63034+ bool 'Denied RWX mmap/mprotect logging'
63035+ default y if GRKERNSEC_CONFIG_AUTO
63036+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
63037+ help
63038+ If you say Y here, calls to mmap() and mprotect() with explicit
63039+ usage of PROT_WRITE and PROT_EXEC together will be logged when
63040+ denied by the PAX_MPROTECT feature. This feature will also
63041+ log other problematic scenarios that can occur when PAX_MPROTECT
63042+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
63043+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
63044+ is created.
63045+
63046+endmenu
63047+
63048+menu "Executable Protections"
63049+depends on GRKERNSEC
63050+
63051+config GRKERNSEC_DMESG
63052+ bool "Dmesg(8) restriction"
63053+ default y if GRKERNSEC_CONFIG_AUTO
63054+ help
63055+ If you say Y here, non-root users will not be able to use dmesg(8)
63056+ to view the contents of the kernel's circular log buffer.
63057+ The kernel's log buffer often contains kernel addresses and other
63058+ identifying information useful to an attacker in fingerprinting a
63059+ system for a targeted exploit.
63060+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
63061+ created.
63062+
63063+config GRKERNSEC_HARDEN_PTRACE
63064+ bool "Deter ptrace-based process snooping"
63065+ default y if GRKERNSEC_CONFIG_AUTO
63066+ help
63067+ If you say Y here, TTY sniffers and other malicious monitoring
63068+ programs implemented through ptrace will be defeated. If you
63069+ have been using the RBAC system, this option has already been
63070+ enabled for several years for all users, with the ability to make
63071+ fine-grained exceptions.
63072+
63073+ This option only affects the ability of non-root users to ptrace
63074+ processes that are not a descendent of the ptracing process.
63075+ This means that strace ./binary and gdb ./binary will still work,
63076+ but attaching to arbitrary processes will not. If the sysctl
63077+ option is enabled, a sysctl option with name "harden_ptrace" is
63078+ created.
63079+
63080+config GRKERNSEC_PTRACE_READEXEC
63081+ bool "Require read access to ptrace sensitive binaries"
63082+ default y if GRKERNSEC_CONFIG_AUTO
63083+ help
63084+ If you say Y here, unprivileged users will not be able to ptrace unreadable
63085+ binaries. This option is useful in environments that
63086+ remove the read bits (e.g. file mode 4711) from suid binaries to
63087+ prevent infoleaking of their contents. This option adds
63088+ consistency to the use of that file mode, as the binary could normally
63089+ be read out when run without privileges while ptracing.
63090+
63091+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
63092+ is created.
63093+
63094+config GRKERNSEC_SETXID
63095+ bool "Enforce consistent multithreaded privileges"
63096+ default y if GRKERNSEC_CONFIG_AUTO
63097+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
63098+ help
63099+ If you say Y here, a change from a root uid to a non-root uid
63100+ in a multithreaded application will cause the resulting uids,
63101+ gids, supplementary groups, and capabilities in that thread
63102+ to be propagated to the other threads of the process. In most
63103+ cases this is unnecessary, as glibc will emulate this behavior
63104+ on behalf of the application. Other libcs do not act in the
63105+ same way, allowing the other threads of the process to continue
63106+ running with root privileges. If the sysctl option is enabled,
63107+ a sysctl option with name "consistent_setxid" is created.
63108+
63109+config GRKERNSEC_TPE
63110+ bool "Trusted Path Execution (TPE)"
63111+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
63112+ help
63113+ If you say Y here, you will be able to choose a gid to add to the
63114+ supplementary groups of users you want to mark as "untrusted."
63115+ These users will not be able to execute any files that are not in
63116+ root-owned directories writable only by root. If the sysctl option
63117+ is enabled, a sysctl option with name "tpe" is created.
63118+
63119+config GRKERNSEC_TPE_ALL
63120+ bool "Partially restrict all non-root users"
63121+ depends on GRKERNSEC_TPE
63122+ help
63123+ If you say Y here, all non-root users will be covered under
63124+ a weaker TPE restriction. This is separate from, and in addition to,
63125+ the main TPE options that you have selected elsewhere. Thus, if a
63126+ "trusted" GID is chosen, this restriction applies to even that GID.
63127+ Under this restriction, all non-root users will only be allowed to
63128+ execute files in directories they own that are not group or
63129+ world-writable, or in directories owned by root and writable only by
63130+ root. If the sysctl option is enabled, a sysctl option with name
63131+ "tpe_restrict_all" is created.
63132+
63133+config GRKERNSEC_TPE_INVERT
63134+ bool "Invert GID option"
63135+ depends on GRKERNSEC_TPE
63136+ help
63137+ If you say Y here, the group you specify in the TPE configuration will
63138+ decide what group TPE restrictions will be *disabled* for. This
63139+ option is useful if you want TPE restrictions to be applied to most
63140+ users on the system. If the sysctl option is enabled, a sysctl option
63141+ with name "tpe_invert" is created. Unlike other sysctl options, this
63142+ entry will default to on for backward-compatibility.
63143+
63144+config GRKERNSEC_TPE_GID
63145+ int
63146+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
63147+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
63148+
63149+config GRKERNSEC_TPE_UNTRUSTED_GID
63150+ int "GID for TPE-untrusted users"
63151+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
63152+ default 1005
63153+ help
63154+ Setting this GID determines what group TPE restrictions will be
63155+ *enabled* for. If the sysctl option is enabled, a sysctl option
63156+ with name "tpe_gid" is created.
63157+
63158+config GRKERNSEC_TPE_TRUSTED_GID
63159+ int "GID for TPE-trusted users"
63160+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
63161+ default 1005
63162+ help
63163+ Setting this GID determines what group TPE restrictions will be
63164+ *disabled* for. If the sysctl option is enabled, a sysctl option
63165+ with name "tpe_gid" is created.
63166+
63167+endmenu
63168+menu "Network Protections"
63169+depends on GRKERNSEC
63170+
63171+config GRKERNSEC_RANDNET
63172+ bool "Larger entropy pools"
63173+ default y if GRKERNSEC_CONFIG_AUTO
63174+ help
63175+ If you say Y here, the entropy pools used for many features of Linux
63176+ and grsecurity will be doubled in size. Since several grsecurity
63177+ features use additional randomness, it is recommended that you say Y
63178+ here. Saying Y here has a similar effect as modifying
63179+ /proc/sys/kernel/random/poolsize.
63180+
63181+config GRKERNSEC_BLACKHOLE
63182+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
63183+ default y if GRKERNSEC_CONFIG_AUTO
63184+ depends on NET
63185+ help
63186+ If you say Y here, neither TCP resets nor ICMP
63187+ destination-unreachable packets will be sent in response to packets
63188+ sent to ports for which no associated listening process exists.
63189+ This feature supports both IPV4 and IPV6 and exempts the
63190+ loopback interface from blackholing. Enabling this feature
63191+ makes a host more resilient to DoS attacks and reduces network
63192+ visibility against scanners.
63193+
63194+ The blackhole feature as-implemented is equivalent to the FreeBSD
63195+ blackhole feature, as it prevents RST responses to all packets, not
63196+ just SYNs. Under most application behavior this causes no
63197+ problems, but applications (like haproxy) may not close certain
63198+ connections in a way that cleanly terminates them on the remote
63199+ end, leaving the remote host in LAST_ACK state. Because of this
63200+ side-effect and to prevent intentional LAST_ACK DoSes, this
63201+ feature also adds automatic mitigation against such attacks.
63202+ The mitigation drastically reduces the amount of time a socket
63203+ can spend in LAST_ACK state. If you're using haproxy and not
63204+ all servers it connects to have this option enabled, consider
63205+ disabling this feature on the haproxy host.
63206+
63207+ If the sysctl option is enabled, two sysctl options with names
63208+ "ip_blackhole" and "lastack_retries" will be created.
63209+ While "ip_blackhole" takes the standard zero/non-zero on/off
63210+ toggle, "lastack_retries" uses the same kinds of values as
63211+ "tcp_retries1" and "tcp_retries2". The default value of 4
63212+ prevents a socket from lasting more than 45 seconds in LAST_ACK
63213+ state.
63214+
63215+config GRKERNSEC_NO_SIMULT_CONNECT
63216+ bool "Disable TCP Simultaneous Connect"
63217+ default y if GRKERNSEC_CONFIG_AUTO
63218+ depends on NET
63219+ help
63220+ If you say Y here, a feature by Willy Tarreau will be enabled that
63221+ removes a weakness in Linux's strict implementation of TCP that
63222+ allows two clients to connect to each other without either entering
63223+ a listening state. The weakness allows an attacker to easily prevent
63224+ a client from connecting to a known server provided the source port
63225+ for the connection is guessed correctly.
63226+
63227+ As the weakness could be used to prevent an antivirus or IPS from
63228+ fetching updates, or prevent an SSL gateway from fetching a CRL,
63229+ it should be eliminated by enabling this option. Though Linux is
63230+ one of few operating systems supporting simultaneous connect, it
63231+ has no legitimate use in practice and is rarely supported by firewalls.
63232+
63233+config GRKERNSEC_SOCKET
63234+ bool "Socket restrictions"
63235+ depends on NET
63236+ help
63237+ If you say Y here, you will be able to choose from several options.
63238+ If you assign a GID on your system and add it to the supplementary
63239+ groups of users you want to restrict socket access to, this patch
63240+ will perform up to three things, based on the option(s) you choose.
63241+
63242+config GRKERNSEC_SOCKET_ALL
63243+ bool "Deny any sockets to group"
63244+ depends on GRKERNSEC_SOCKET
63245+ help
63246+ If you say Y here, you will be able to choose a GID of whose users will
63247+ be unable to connect to other hosts from your machine or run server
63248+ applications from your machine. If the sysctl option is enabled, a
63249+ sysctl option with name "socket_all" is created.
63250+
63251+config GRKERNSEC_SOCKET_ALL_GID
63252+ int "GID to deny all sockets for"
63253+ depends on GRKERNSEC_SOCKET_ALL
63254+ default 1004
63255+ help
63256+ Here you can choose the GID to disable socket access for. Remember to
63257+ add the users you want socket access disabled for to the GID
63258+ specified here. If the sysctl option is enabled, a sysctl option
63259+ with name "socket_all_gid" is created.
63260+
63261+config GRKERNSEC_SOCKET_CLIENT
63262+ bool "Deny client sockets to group"
63263+ depends on GRKERNSEC_SOCKET
63264+ help
63265+ If you say Y here, you will be able to choose a GID of whose users will
63266+ be unable to connect to other hosts from your machine, but will be
63267+ able to run servers. If this option is enabled, all users in the group
63268+ you specify will have to use passive mode when initiating ftp transfers
63269+ from the shell on your machine. If the sysctl option is enabled, a
63270+ sysctl option with name "socket_client" is created.
63271+
63272+config GRKERNSEC_SOCKET_CLIENT_GID
63273+ int "GID to deny client sockets for"
63274+ depends on GRKERNSEC_SOCKET_CLIENT
63275+ default 1003
63276+ help
63277+ Here you can choose the GID to disable client socket access for.
63278+ Remember to add the users you want client socket access disabled for to
63279+ the GID specified here. If the sysctl option is enabled, a sysctl
63280+ option with name "socket_client_gid" is created.
63281+
63282+config GRKERNSEC_SOCKET_SERVER
63283+ bool "Deny server sockets to group"
63284+ depends on GRKERNSEC_SOCKET
63285+ help
63286+ If you say Y here, you will be able to choose a GID of whose users will
63287+ be unable to run server applications from your machine. If the sysctl
63288+ option is enabled, a sysctl option with name "socket_server" is created.
63289+
63290+config GRKERNSEC_SOCKET_SERVER_GID
63291+ int "GID to deny server sockets for"
63292+ depends on GRKERNSEC_SOCKET_SERVER
63293+ default 1002
63294+ help
63295+ Here you can choose the GID to disable server socket access for.
63296+ Remember to add the users you want server socket access disabled for to
63297+ the GID specified here. If the sysctl option is enabled, a sysctl
63298+ option with name "socket_server_gid" is created.
63299+
63300+endmenu
63301+
63302+menu "Physical Protections"
63303+depends on GRKERNSEC
63304+
63305+config GRKERNSEC_DENYUSB
63306+ bool "Deny new USB connections after toggle"
63307+ default y if GRKERNSEC_CONFIG_AUTO
63308+ help
63309+ If you say Y here, a new sysctl option with name "deny_new_usb"
63310+ will be created. Setting its value to 1 will prevent any new
63311+ USB devices from being recognized by the OS. Any attempted USB
63312+ device insertion will be logged. This option is intended to be
63313+ used against custom USB devices designed to exploit vulnerabilities
63314+ in various USB device drivers.
63315+
63316+ For greatest effectiveness, this sysctl should be set after any
63317+ relevant init scripts. This option is safe to enable in distros
63318+ as each user can choose whether or not to toggle the sysctl.
63319+
63320+config GRKERNSEC_DENYUSB_FORCE
63321+ bool "Reject all USB devices not connected at boot"
63322+ select USB
63323+ depends on SYSCTL && GRKERNSEC_DENYUSB
63324+ help
63325+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
63326+ that doesn't involve a sysctl entry. This option should only be
63327+ enabled if you're sure you want to deny all new USB connections
63328+ at runtime and don't want to modify init scripts. This should not
63329+ be enabled by distros. It forces the core USB code to be built
63330+ into the kernel image so that all devices connected at boot time
63331+ can be recognized and new USB device connections can be prevented
63332+ prior to init running.
63333+
63334+endmenu
63335+
63336+menu "Sysctl Support"
63337+depends on GRKERNSEC && SYSCTL
63338+
63339+config GRKERNSEC_SYSCTL
63340+ bool "Sysctl support"
63341+ default y if GRKERNSEC_CONFIG_AUTO
63342+ help
63343+ If you say Y here, you will be able to change the options that
63344+ grsecurity runs with at bootup, without having to recompile your
63345+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
63346+ to enable (1) or disable (0) various features. All the sysctl entries
63347+ are mutable until the "grsec_lock" entry is set to a non-zero value.
63348+ All features enabled in the kernel configuration are disabled at boot
63349+ if you do not say Y to the "Turn on features by default" option.
63350+ All options should be set at startup, and the grsec_lock entry should
63351+ be set to a non-zero value after all the options are set.
63352+ *THIS IS EXTREMELY IMPORTANT*
63353+
63354+config GRKERNSEC_SYSCTL_DISTRO
63355+ bool "Extra sysctl support for distro makers (READ HELP)"
63356+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
63357+ help
63358+ If you say Y here, additional sysctl options will be created
63359+ for features that affect processes running as root. Therefore,
63360+ it is critical when using this option that the grsec_lock entry be
63361+ enabled after boot. Only distros with prebuilt kernel packages
63362+ with this option enabled that can ensure grsec_lock is enabled
63363+ after boot should use this option.
63364+ *Failure to set grsec_lock after boot makes all grsec features
63365+ this option covers useless*
63366+
63367+ Currently this option creates the following sysctl entries:
63368+ "Disable Privileged I/O": "disable_priv_io"
63369+
63370+config GRKERNSEC_SYSCTL_ON
63371+ bool "Turn on features by default"
63372+ default y if GRKERNSEC_CONFIG_AUTO
63373+ depends on GRKERNSEC_SYSCTL
63374+ help
63375+ If you say Y here, instead of having all features enabled in the
63376+ kernel configuration disabled at boot time, the features will be
63377+ enabled at boot time. It is recommended you say Y here unless
63378+ there is some reason you would want all sysctl-tunable features to
63379+ be disabled by default. As mentioned elsewhere, it is important
63380+ to enable the grsec_lock entry once you have finished modifying
63381+ the sysctl entries.
63382+
63383+endmenu
63384+menu "Logging Options"
63385+depends on GRKERNSEC
63386+
63387+config GRKERNSEC_FLOODTIME
63388+ int "Seconds in between log messages (minimum)"
63389+ default 10
63390+ help
63391+ This option allows you to enforce the number of seconds between
63392+ grsecurity log messages. The default should be suitable for most
63393+ people, however, if you choose to change it, choose a value small enough
63394+ to allow informative logs to be produced, but large enough to
63395+ prevent flooding.
63396+
63397+config GRKERNSEC_FLOODBURST
63398+ int "Number of messages in a burst (maximum)"
63399+ default 6
63400+ help
63401+ This option allows you to choose the maximum number of messages allowed
63402+ within the flood time interval you chose in a separate option. The
63403+ default should be suitable for most people, however if you find that
63404+ many of your logs are being interpreted as flooding, you may want to
63405+ raise this value.
63406+
63407+endmenu
63408diff --git a/grsecurity/Makefile b/grsecurity/Makefile
63409new file mode 100644
63410index 0000000..b0b77d5
63411--- /dev/null
63412+++ b/grsecurity/Makefile
63413@@ -0,0 +1,43 @@
63414+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
63415+# during 2001-2009 it has been completely redesigned by Brad Spengler
63416+# into an RBAC system
63417+#
63418+# All code in this directory and various hooks inserted throughout the kernel
63419+# are copyright Brad Spengler - Open Source Security, Inc., and released
63420+# under the GPL v2 or higher
63421+
63422+KBUILD_CFLAGS += -Werror
63423+
63424+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
63425+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
63426+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
63427+ grsec_usb.o
63428+
63429+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
63430+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
63431+ gracl_learn.o grsec_log.o
63432+ifdef CONFIG_COMPAT
63433+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
63434+endif
63435+
63436+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
63437+
63438+ifdef CONFIG_NET
63439+obj-y += grsec_sock.o
63440+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
63441+endif
63442+
63443+ifndef CONFIG_GRKERNSEC
63444+obj-y += grsec_disabled.o
63445+endif
63446+
63447+ifdef CONFIG_GRKERNSEC_HIDESYM
63448+extra-y := grsec_hidesym.o
63449+$(obj)/grsec_hidesym.o:
63450+ @-chmod -f 500 /boot
63451+ @-chmod -f 500 /lib/modules
63452+ @-chmod -f 500 /lib64/modules
63453+ @-chmod -f 500 /lib32/modules
63454+ @-chmod -f 700 .
63455+ @echo ' grsec: protected kernel image paths'
63456+endif
63457diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
63458new file mode 100644
63459index 0000000..c0793fd
63460--- /dev/null
63461+++ b/grsecurity/gracl.c
63462@@ -0,0 +1,4178 @@
63463+#include <linux/kernel.h>
63464+#include <linux/module.h>
63465+#include <linux/sched.h>
63466+#include <linux/mm.h>
63467+#include <linux/file.h>
63468+#include <linux/fs.h>
63469+#include <linux/namei.h>
63470+#include <linux/mount.h>
63471+#include <linux/tty.h>
63472+#include <linux/proc_fs.h>
63473+#include <linux/lglock.h>
63474+#include <linux/slab.h>
63475+#include <linux/vmalloc.h>
63476+#include <linux/types.h>
63477+#include <linux/sysctl.h>
63478+#include <linux/netdevice.h>
63479+#include <linux/ptrace.h>
63480+#include <linux/gracl.h>
63481+#include <linux/gralloc.h>
63482+#include <linux/security.h>
63483+#include <linux/grinternal.h>
63484+#include <linux/pid_namespace.h>
63485+#include <linux/stop_machine.h>
63486+#include <linux/fdtable.h>
63487+#include <linux/percpu.h>
63488+#include <linux/lglock.h>
63489+#include <linux/hugetlb.h>
63490+#include <linux/posix-timers.h>
63491+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63492+#include <linux/magic.h>
63493+#include <linux/pagemap.h>
63494+#include "../fs/btrfs/async-thread.h"
63495+#include "../fs/btrfs/ctree.h"
63496+#include "../fs/btrfs/btrfs_inode.h"
63497+#endif
63498+#include "../fs/mount.h"
63499+
63500+#include <asm/uaccess.h>
63501+#include <asm/errno.h>
63502+#include <asm/mman.h>
63503+
63504+extern struct lglock vfsmount_lock;
63505+
63506+static struct acl_role_db acl_role_set;
63507+static struct name_db name_set;
63508+static struct inodev_db inodev_set;
63509+
63510+/* for keeping track of userspace pointers used for subjects, so we
63511+ can share references in the kernel as well
63512+*/
63513+
63514+static struct path real_root;
63515+
63516+static struct acl_subj_map_db subj_map_set;
63517+
63518+static struct acl_role_label *default_role;
63519+
63520+static struct acl_role_label *role_list;
63521+
63522+static u16 acl_sp_role_value;
63523+
63524+extern char *gr_shared_page[4];
63525+static DEFINE_MUTEX(gr_dev_mutex);
63526+DEFINE_RWLOCK(gr_inode_lock);
63527+
63528+struct gr_arg *gr_usermode;
63529+
63530+static unsigned int gr_status __read_only = GR_STATUS_INIT;
63531+
63532+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
63533+extern void gr_clear_learn_entries(void);
63534+
63535+unsigned char *gr_system_salt;
63536+unsigned char *gr_system_sum;
63537+
63538+static struct sprole_pw **acl_special_roles = NULL;
63539+static __u16 num_sprole_pws = 0;
63540+
63541+static struct acl_role_label *kernel_role = NULL;
63542+
63543+static unsigned int gr_auth_attempts = 0;
63544+static unsigned long gr_auth_expires = 0UL;
63545+
63546+#ifdef CONFIG_NET
63547+extern struct vfsmount *sock_mnt;
63548+#endif
63549+
63550+extern struct vfsmount *pipe_mnt;
63551+extern struct vfsmount *shm_mnt;
63552+
63553+#ifdef CONFIG_HUGETLBFS
63554+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63555+#endif
63556+
63557+static struct acl_object_label *fakefs_obj_rw;
63558+static struct acl_object_label *fakefs_obj_rwx;
63559+
63560+extern int gr_init_uidset(void);
63561+extern void gr_free_uidset(void);
63562+extern void gr_remove_uid(uid_t uid);
63563+extern int gr_find_uid(uid_t uid);
63564+
63565+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
63566+{
63567+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
63568+ return -EFAULT;
63569+
63570+ return 0;
63571+}
63572+
63573+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
63574+{
63575+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
63576+ return -EFAULT;
63577+
63578+ return 0;
63579+}
63580+
63581+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
63582+{
63583+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
63584+ return -EFAULT;
63585+
63586+ return 0;
63587+}
63588+
63589+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
63590+{
63591+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
63592+ return -EFAULT;
63593+
63594+ return 0;
63595+}
63596+
63597+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
63598+{
63599+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
63600+ return -EFAULT;
63601+
63602+ return 0;
63603+}
63604+
63605+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
63606+{
63607+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
63608+ return -EFAULT;
63609+
63610+ return 0;
63611+}
63612+
63613+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
63614+{
63615+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
63616+ return -EFAULT;
63617+
63618+ return 0;
63619+}
63620+
63621+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
63622+{
63623+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
63624+ return -EFAULT;
63625+
63626+ return 0;
63627+}
63628+
63629+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
63630+{
63631+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
63632+ return -EFAULT;
63633+
63634+ return 0;
63635+}
63636+
63637+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
63638+{
63639+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
63640+ return -EFAULT;
63641+
63642+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
63643+ return -EINVAL;
63644+
63645+ return 0;
63646+}
63647+
63648+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
63649+{
63650+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
63651+ return -EFAULT;
63652+
63653+ return 0;
63654+}
63655+
63656+static size_t get_gr_arg_wrapper_size_normal(void)
63657+{
63658+ return sizeof(struct gr_arg_wrapper);
63659+}
63660+
63661+#ifdef CONFIG_COMPAT
63662+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
63663+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
63664+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
63665+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
63666+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
63667+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
63668+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
63669+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
63670+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
63671+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
63672+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
63673+extern size_t get_gr_arg_wrapper_size_compat(void);
63674+
63675+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
63676+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
63677+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
63678+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
63679+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
63680+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
63681+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
63682+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
63683+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
63684+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
63685+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
63686+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
63687+
63688+#else
63689+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
63690+#define copy_gr_arg copy_gr_arg_normal
63691+#define copy_gr_hash_struct copy_gr_hash_struct_normal
63692+#define copy_acl_object_label copy_acl_object_label_normal
63693+#define copy_acl_subject_label copy_acl_subject_label_normal
63694+#define copy_acl_role_label copy_acl_role_label_normal
63695+#define copy_acl_ip_label copy_acl_ip_label_normal
63696+#define copy_pointer_from_array copy_pointer_from_array_normal
63697+#define copy_sprole_pw copy_sprole_pw_normal
63698+#define copy_role_transition copy_role_transition_normal
63699+#define copy_role_allowed_ip copy_role_allowed_ip_normal
63700+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
63701+#endif
63702+
63703+__inline__ int
63704+gr_acl_is_enabled(void)
63705+{
63706+ return (gr_status & GR_READY);
63707+}
63708+
63709+static inline dev_t __get_dev(const struct dentry *dentry)
63710+{
63711+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63712+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
63713+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
63714+ else
63715+#endif
63716+ return dentry->d_sb->s_dev;
63717+}
63718+
63719+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63720+{
63721+ return __get_dev(dentry);
63722+}
63723+
63724+static char gr_task_roletype_to_char(struct task_struct *task)
63725+{
63726+ switch (task->role->roletype &
63727+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
63728+ GR_ROLE_SPECIAL)) {
63729+ case GR_ROLE_DEFAULT:
63730+ return 'D';
63731+ case GR_ROLE_USER:
63732+ return 'U';
63733+ case GR_ROLE_GROUP:
63734+ return 'G';
63735+ case GR_ROLE_SPECIAL:
63736+ return 'S';
63737+ }
63738+
63739+ return 'X';
63740+}
63741+
63742+char gr_roletype_to_char(void)
63743+{
63744+ return gr_task_roletype_to_char(current);
63745+}
63746+
63747+__inline__ int
63748+gr_acl_tpe_check(void)
63749+{
63750+ if (unlikely(!(gr_status & GR_READY)))
63751+ return 0;
63752+ if (current->role->roletype & GR_ROLE_TPE)
63753+ return 1;
63754+ else
63755+ return 0;
63756+}
63757+
63758+int
63759+gr_handle_rawio(const struct inode *inode)
63760+{
63761+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63762+ if (inode && S_ISBLK(inode->i_mode) &&
63763+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
63764+ !capable(CAP_SYS_RAWIO))
63765+ return 1;
63766+#endif
63767+ return 0;
63768+}
63769+
63770+static int
63771+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
63772+{
63773+ if (likely(lena != lenb))
63774+ return 0;
63775+
63776+ return !memcmp(a, b, lena);
63777+}
63778+
63779+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
63780+{
63781+ *buflen -= namelen;
63782+ if (*buflen < 0)
63783+ return -ENAMETOOLONG;
63784+ *buffer -= namelen;
63785+ memcpy(*buffer, str, namelen);
63786+ return 0;
63787+}
63788+
63789+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
63790+{
63791+ return prepend(buffer, buflen, name->name, name->len);
63792+}
63793+
63794+static int prepend_path(const struct path *path, struct path *root,
63795+ char **buffer, int *buflen)
63796+{
63797+ struct dentry *dentry = path->dentry;
63798+ struct vfsmount *vfsmnt = path->mnt;
63799+ struct mount *mnt = real_mount(vfsmnt);
63800+ bool slash = false;
63801+ int error = 0;
63802+
63803+ while (dentry != root->dentry || vfsmnt != root->mnt) {
63804+ struct dentry * parent;
63805+
63806+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
63807+ /* Global root? */
63808+ if (!mnt_has_parent(mnt)) {
63809+ goto out;
63810+ }
63811+ dentry = mnt->mnt_mountpoint;
63812+ mnt = mnt->mnt_parent;
63813+ vfsmnt = &mnt->mnt;
63814+ continue;
63815+ }
63816+ parent = dentry->d_parent;
63817+ prefetch(parent);
63818+ spin_lock(&dentry->d_lock);
63819+ error = prepend_name(buffer, buflen, &dentry->d_name);
63820+ spin_unlock(&dentry->d_lock);
63821+ if (!error)
63822+ error = prepend(buffer, buflen, "/", 1);
63823+ if (error)
63824+ break;
63825+
63826+ slash = true;
63827+ dentry = parent;
63828+ }
63829+
63830+out:
63831+ if (!error && !slash)
63832+ error = prepend(buffer, buflen, "/", 1);
63833+
63834+ return error;
63835+}
63836+
63837+/* this must be called with vfsmount_lock and rename_lock held */
63838+
63839+static char *__our_d_path(const struct path *path, struct path *root,
63840+ char *buf, int buflen)
63841+{
63842+ char *res = buf + buflen;
63843+ int error;
63844+
63845+ prepend(&res, &buflen, "\0", 1);
63846+ error = prepend_path(path, root, &res, &buflen);
63847+ if (error)
63848+ return ERR_PTR(error);
63849+
63850+ return res;
63851+}
63852+
63853+static char *
63854+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
63855+{
63856+ char *retval;
63857+
63858+ retval = __our_d_path(path, root, buf, buflen);
63859+ if (unlikely(IS_ERR(retval)))
63860+ retval = strcpy(buf, "<path too long>");
63861+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
63862+ retval[1] = '\0';
63863+
63864+ return retval;
63865+}
63866+
63867+static char *
63868+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
63869+ char *buf, int buflen)
63870+{
63871+ struct path path;
63872+ char *res;
63873+
63874+ path.dentry = (struct dentry *)dentry;
63875+ path.mnt = (struct vfsmount *)vfsmnt;
63876+
63877+ /* we can use real_root.dentry, real_root.mnt, because this is only called
63878+ by the RBAC system */
63879+ res = gen_full_path(&path, &real_root, buf, buflen);
63880+
63881+ return res;
63882+}
63883+
63884+static char *
63885+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
63886+ char *buf, int buflen)
63887+{
63888+ char *res;
63889+ struct path path;
63890+ struct path root;
63891+ struct task_struct *reaper = init_pid_ns.child_reaper;
63892+
63893+ path.dentry = (struct dentry *)dentry;
63894+ path.mnt = (struct vfsmount *)vfsmnt;
63895+
63896+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
63897+ get_fs_root(reaper->fs, &root);
63898+
63899+ br_read_lock(&vfsmount_lock);
63900+ write_seqlock(&rename_lock);
63901+ res = gen_full_path(&path, &root, buf, buflen);
63902+ write_sequnlock(&rename_lock);
63903+ br_read_unlock(&vfsmount_lock);
63904+
63905+ path_put(&root);
63906+ return res;
63907+}
63908+
63909+static char *
63910+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
63911+{
63912+ char *ret;
63913+ br_read_lock(&vfsmount_lock);
63914+ write_seqlock(&rename_lock);
63915+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
63916+ PAGE_SIZE);
63917+ write_sequnlock(&rename_lock);
63918+ br_read_unlock(&vfsmount_lock);
63919+ return ret;
63920+}
63921+
63922+static char *
63923+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
63924+{
63925+ char *ret;
63926+ char *buf;
63927+ int buflen;
63928+
63929+ br_read_lock(&vfsmount_lock);
63930+ write_seqlock(&rename_lock);
63931+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
63932+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
63933+ buflen = (int)(ret - buf);
63934+ if (buflen >= 5)
63935+ prepend(&ret, &buflen, "/proc", 5);
63936+ else
63937+ ret = strcpy(buf, "<path too long>");
63938+ write_sequnlock(&rename_lock);
63939+ br_read_unlock(&vfsmount_lock);
63940+ return ret;
63941+}
63942+
63943+char *
63944+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
63945+{
63946+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
63947+ PAGE_SIZE);
63948+}
63949+
63950+char *
63951+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
63952+{
63953+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
63954+ PAGE_SIZE);
63955+}
63956+
63957+char *
63958+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
63959+{
63960+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
63961+ PAGE_SIZE);
63962+}
63963+
63964+char *
63965+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
63966+{
63967+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
63968+ PAGE_SIZE);
63969+}
63970+
63971+char *
63972+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
63973+{
63974+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
63975+ PAGE_SIZE);
63976+}
63977+
63978+__inline__ __u32
63979+to_gr_audit(const __u32 reqmode)
63980+{
63981+ /* masks off auditable permission flags, then shifts them to create
63982+ auditing flags, and adds the special case of append auditing if
63983+ we're requesting write */
63984+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
63985+}
63986+
63987+struct acl_subject_label *
63988+lookup_subject_map(const struct acl_subject_label *userp)
63989+{
63990+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
63991+ struct subject_map *match;
63992+
63993+ match = subj_map_set.s_hash[index];
63994+
63995+ while (match && match->user != userp)
63996+ match = match->next;
63997+
63998+ if (match != NULL)
63999+ return match->kernel;
64000+ else
64001+ return NULL;
64002+}
64003+
64004+static void
64005+insert_subj_map_entry(struct subject_map *subjmap)
64006+{
64007+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
64008+ struct subject_map **curr;
64009+
64010+ subjmap->prev = NULL;
64011+
64012+ curr = &subj_map_set.s_hash[index];
64013+ if (*curr != NULL)
64014+ (*curr)->prev = subjmap;
64015+
64016+ subjmap->next = *curr;
64017+ *curr = subjmap;
64018+
64019+ return;
64020+}
64021+
64022+static struct acl_role_label *
64023+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
64024+ const gid_t gid)
64025+{
64026+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
64027+ struct acl_role_label *match;
64028+ struct role_allowed_ip *ipp;
64029+ unsigned int x;
64030+ u32 curr_ip = task->signal->curr_ip;
64031+
64032+ task->signal->saved_ip = curr_ip;
64033+
64034+ match = acl_role_set.r_hash[index];
64035+
64036+ while (match) {
64037+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
64038+ for (x = 0; x < match->domain_child_num; x++) {
64039+ if (match->domain_children[x] == uid)
64040+ goto found;
64041+ }
64042+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
64043+ break;
64044+ match = match->next;
64045+ }
64046+found:
64047+ if (match == NULL) {
64048+ try_group:
64049+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
64050+ match = acl_role_set.r_hash[index];
64051+
64052+ while (match) {
64053+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
64054+ for (x = 0; x < match->domain_child_num; x++) {
64055+ if (match->domain_children[x] == gid)
64056+ goto found2;
64057+ }
64058+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
64059+ break;
64060+ match = match->next;
64061+ }
64062+found2:
64063+ if (match == NULL)
64064+ match = default_role;
64065+ if (match->allowed_ips == NULL)
64066+ return match;
64067+ else {
64068+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
64069+ if (likely
64070+ ((ntohl(curr_ip) & ipp->netmask) ==
64071+ (ntohl(ipp->addr) & ipp->netmask)))
64072+ return match;
64073+ }
64074+ match = default_role;
64075+ }
64076+ } else if (match->allowed_ips == NULL) {
64077+ return match;
64078+ } else {
64079+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
64080+ if (likely
64081+ ((ntohl(curr_ip) & ipp->netmask) ==
64082+ (ntohl(ipp->addr) & ipp->netmask)))
64083+ return match;
64084+ }
64085+ goto try_group;
64086+ }
64087+
64088+ return match;
64089+}
64090+
64091+struct acl_subject_label *
64092+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
64093+ const struct acl_role_label *role)
64094+{
64095+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
64096+ struct acl_subject_label *match;
64097+
64098+ match = role->subj_hash[index];
64099+
64100+ while (match && (match->inode != ino || match->device != dev ||
64101+ (match->mode & GR_DELETED))) {
64102+ match = match->next;
64103+ }
64104+
64105+ if (match && !(match->mode & GR_DELETED))
64106+ return match;
64107+ else
64108+ return NULL;
64109+}
64110+
64111+struct acl_subject_label *
64112+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
64113+ const struct acl_role_label *role)
64114+{
64115+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
64116+ struct acl_subject_label *match;
64117+
64118+ match = role->subj_hash[index];
64119+
64120+ while (match && (match->inode != ino || match->device != dev ||
64121+ !(match->mode & GR_DELETED))) {
64122+ match = match->next;
64123+ }
64124+
64125+ if (match && (match->mode & GR_DELETED))
64126+ return match;
64127+ else
64128+ return NULL;
64129+}
64130+
64131+static struct acl_object_label *
64132+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
64133+ const struct acl_subject_label *subj)
64134+{
64135+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
64136+ struct acl_object_label *match;
64137+
64138+ match = subj->obj_hash[index];
64139+
64140+ while (match && (match->inode != ino || match->device != dev ||
64141+ (match->mode & GR_DELETED))) {
64142+ match = match->next;
64143+ }
64144+
64145+ if (match && !(match->mode & GR_DELETED))
64146+ return match;
64147+ else
64148+ return NULL;
64149+}
64150+
64151+static struct acl_object_label *
64152+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
64153+ const struct acl_subject_label *subj)
64154+{
64155+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
64156+ struct acl_object_label *match;
64157+
64158+ match = subj->obj_hash[index];
64159+
64160+ while (match && (match->inode != ino || match->device != dev ||
64161+ !(match->mode & GR_DELETED))) {
64162+ match = match->next;
64163+ }
64164+
64165+ if (match && (match->mode & GR_DELETED))
64166+ return match;
64167+
64168+ match = subj->obj_hash[index];
64169+
64170+ while (match && (match->inode != ino || match->device != dev ||
64171+ (match->mode & GR_DELETED))) {
64172+ match = match->next;
64173+ }
64174+
64175+ if (match && !(match->mode & GR_DELETED))
64176+ return match;
64177+ else
64178+ return NULL;
64179+}
64180+
64181+static struct name_entry *
64182+lookup_name_entry(const char *name)
64183+{
64184+ unsigned int len = strlen(name);
64185+ unsigned int key = full_name_hash(name, len);
64186+ unsigned int index = key % name_set.n_size;
64187+ struct name_entry *match;
64188+
64189+ match = name_set.n_hash[index];
64190+
64191+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
64192+ match = match->next;
64193+
64194+ return match;
64195+}
64196+
64197+static struct name_entry *
64198+lookup_name_entry_create(const char *name)
64199+{
64200+ unsigned int len = strlen(name);
64201+ unsigned int key = full_name_hash(name, len);
64202+ unsigned int index = key % name_set.n_size;
64203+ struct name_entry *match;
64204+
64205+ match = name_set.n_hash[index];
64206+
64207+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
64208+ !match->deleted))
64209+ match = match->next;
64210+
64211+ if (match && match->deleted)
64212+ return match;
64213+
64214+ match = name_set.n_hash[index];
64215+
64216+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
64217+ match->deleted))
64218+ match = match->next;
64219+
64220+ if (match && !match->deleted)
64221+ return match;
64222+ else
64223+ return NULL;
64224+}
64225+
64226+static struct inodev_entry *
64227+lookup_inodev_entry(const ino_t ino, const dev_t dev)
64228+{
64229+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
64230+ struct inodev_entry *match;
64231+
64232+ match = inodev_set.i_hash[index];
64233+
64234+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
64235+ match = match->next;
64236+
64237+ return match;
64238+}
64239+
64240+static void
64241+insert_inodev_entry(struct inodev_entry *entry)
64242+{
64243+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
64244+ inodev_set.i_size);
64245+ struct inodev_entry **curr;
64246+
64247+ entry->prev = NULL;
64248+
64249+ curr = &inodev_set.i_hash[index];
64250+ if (*curr != NULL)
64251+ (*curr)->prev = entry;
64252+
64253+ entry->next = *curr;
64254+ *curr = entry;
64255+
64256+ return;
64257+}
64258+
64259+static void
64260+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
64261+{
64262+ unsigned int index =
64263+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
64264+ struct acl_role_label **curr;
64265+ struct acl_role_label *tmp, *tmp2;
64266+
64267+ curr = &acl_role_set.r_hash[index];
64268+
64269+ /* simple case, slot is empty, just set it to our role */
64270+ if (*curr == NULL) {
64271+ *curr = role;
64272+ } else {
64273+ /* example:
64274+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
64275+ 2 -> 3
64276+ */
64277+ /* first check to see if we can already be reached via this slot */
64278+ tmp = *curr;
64279+ while (tmp && tmp != role)
64280+ tmp = tmp->next;
64281+ if (tmp == role) {
64282+ /* we don't need to add ourselves to this slot's chain */
64283+ return;
64284+ }
64285+ /* we need to add ourselves to this chain, two cases */
64286+ if (role->next == NULL) {
64287+ /* simple case, append the current chain to our role */
64288+ role->next = *curr;
64289+ *curr = role;
64290+ } else {
64291+ /* 1 -> 2 -> 3 -> 4
64292+ 2 -> 3 -> 4
64293+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
64294+ */
64295+ /* trickier case: walk our role's chain until we find
64296+ the role for the start of the current slot's chain */
64297+ tmp = role;
64298+ tmp2 = *curr;
64299+ while (tmp->next && tmp->next != tmp2)
64300+ tmp = tmp->next;
64301+ if (tmp->next == tmp2) {
64302+ /* from example above, we found 3, so just
64303+ replace this slot's chain with ours */
64304+ *curr = role;
64305+ } else {
64306+ /* we didn't find a subset of our role's chain
64307+ in the current slot's chain, so append their
64308+ chain to ours, and set us as the first role in
64309+ the slot's chain
64310+
64311+ we could fold this case with the case above,
64312+ but making it explicit for clarity
64313+ */
64314+ tmp->next = tmp2;
64315+ *curr = role;
64316+ }
64317+ }
64318+ }
64319+
64320+ return;
64321+}
64322+
64323+static void
64324+insert_acl_role_label(struct acl_role_label *role)
64325+{
64326+ int i;
64327+
64328+ if (role_list == NULL) {
64329+ role_list = role;
64330+ role->prev = NULL;
64331+ } else {
64332+ role->prev = role_list;
64333+ role_list = role;
64334+ }
64335+
64336+ /* used for hash chains */
64337+ role->next = NULL;
64338+
64339+ if (role->roletype & GR_ROLE_DOMAIN) {
64340+ for (i = 0; i < role->domain_child_num; i++)
64341+ __insert_acl_role_label(role, role->domain_children[i]);
64342+ } else
64343+ __insert_acl_role_label(role, role->uidgid);
64344+}
64345+
64346+static int
64347+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
64348+{
64349+ struct name_entry **curr, *nentry;
64350+ struct inodev_entry *ientry;
64351+ unsigned int len = strlen(name);
64352+ unsigned int key = full_name_hash(name, len);
64353+ unsigned int index = key % name_set.n_size;
64354+
64355+ curr = &name_set.n_hash[index];
64356+
64357+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
64358+ curr = &((*curr)->next);
64359+
64360+ if (*curr != NULL)
64361+ return 1;
64362+
64363+ nentry = acl_alloc(sizeof (struct name_entry));
64364+ if (nentry == NULL)
64365+ return 0;
64366+ ientry = acl_alloc(sizeof (struct inodev_entry));
64367+ if (ientry == NULL)
64368+ return 0;
64369+ ientry->nentry = nentry;
64370+
64371+ nentry->key = key;
64372+ nentry->name = name;
64373+ nentry->inode = inode;
64374+ nentry->device = device;
64375+ nentry->len = len;
64376+ nentry->deleted = deleted;
64377+
64378+ nentry->prev = NULL;
64379+ curr = &name_set.n_hash[index];
64380+ if (*curr != NULL)
64381+ (*curr)->prev = nentry;
64382+ nentry->next = *curr;
64383+ *curr = nentry;
64384+
64385+ /* insert us into the table searchable by inode/dev */
64386+ insert_inodev_entry(ientry);
64387+
64388+ return 1;
64389+}
64390+
64391+static void
64392+insert_acl_obj_label(struct acl_object_label *obj,
64393+ struct acl_subject_label *subj)
64394+{
64395+ unsigned int index =
64396+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
64397+ struct acl_object_label **curr;
64398+
64399+
64400+ obj->prev = NULL;
64401+
64402+ curr = &subj->obj_hash[index];
64403+ if (*curr != NULL)
64404+ (*curr)->prev = obj;
64405+
64406+ obj->next = *curr;
64407+ *curr = obj;
64408+
64409+ return;
64410+}
64411+
64412+static void
64413+insert_acl_subj_label(struct acl_subject_label *obj,
64414+ struct acl_role_label *role)
64415+{
64416+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
64417+ struct acl_subject_label **curr;
64418+
64419+ obj->prev = NULL;
64420+
64421+ curr = &role->subj_hash[index];
64422+ if (*curr != NULL)
64423+ (*curr)->prev = obj;
64424+
64425+ obj->next = *curr;
64426+ *curr = obj;
64427+
64428+ return;
64429+}
64430+
64431+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
64432+
64433+static void *
64434+create_table(__u32 * len, int elementsize)
64435+{
64436+ unsigned int table_sizes[] = {
64437+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
64438+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
64439+ 4194301, 8388593, 16777213, 33554393, 67108859
64440+ };
64441+ void *newtable = NULL;
64442+ unsigned int pwr = 0;
64443+
64444+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
64445+ table_sizes[pwr] <= *len)
64446+ pwr++;
64447+
64448+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
64449+ return newtable;
64450+
64451+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
64452+ newtable =
64453+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
64454+ else
64455+ newtable = vmalloc(table_sizes[pwr] * elementsize);
64456+
64457+ *len = table_sizes[pwr];
64458+
64459+ return newtable;
64460+}
64461+
64462+static int
64463+init_variables(const struct gr_arg *arg)
64464+{
64465+ struct task_struct *reaper = init_pid_ns.child_reaper;
64466+ unsigned int stacksize;
64467+
64468+ subj_map_set.s_size = arg->role_db.num_subjects;
64469+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
64470+ name_set.n_size = arg->role_db.num_objects;
64471+ inodev_set.i_size = arg->role_db.num_objects;
64472+
64473+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
64474+ !name_set.n_size || !inodev_set.i_size)
64475+ return 1;
64476+
64477+ if (!gr_init_uidset())
64478+ return 1;
64479+
64480+ /* set up the stack that holds allocation info */
64481+
64482+ stacksize = arg->role_db.num_pointers + 5;
64483+
64484+ if (!acl_alloc_stack_init(stacksize))
64485+ return 1;
64486+
64487+ /* grab reference for the real root dentry and vfsmount */
64488+ get_fs_root(reaper->fs, &real_root);
64489+
64490+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64491+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
64492+#endif
64493+
64494+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
64495+ if (fakefs_obj_rw == NULL)
64496+ return 1;
64497+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
64498+
64499+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
64500+ if (fakefs_obj_rwx == NULL)
64501+ return 1;
64502+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
64503+
64504+ subj_map_set.s_hash =
64505+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
64506+ acl_role_set.r_hash =
64507+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
64508+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
64509+ inodev_set.i_hash =
64510+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
64511+
64512+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
64513+ !name_set.n_hash || !inodev_set.i_hash)
64514+ return 1;
64515+
64516+ memset(subj_map_set.s_hash, 0,
64517+ sizeof(struct subject_map *) * subj_map_set.s_size);
64518+ memset(acl_role_set.r_hash, 0,
64519+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
64520+ memset(name_set.n_hash, 0,
64521+ sizeof (struct name_entry *) * name_set.n_size);
64522+ memset(inodev_set.i_hash, 0,
64523+ sizeof (struct inodev_entry *) * inodev_set.i_size);
64524+
64525+ return 0;
64526+}
64527+
64528+/* free information not needed after startup
64529+ currently contains user->kernel pointer mappings for subjects
64530+*/
64531+
64532+static void
64533+free_init_variables(void)
64534+{
64535+ __u32 i;
64536+
64537+ if (subj_map_set.s_hash) {
64538+ for (i = 0; i < subj_map_set.s_size; i++) {
64539+ if (subj_map_set.s_hash[i]) {
64540+ kfree(subj_map_set.s_hash[i]);
64541+ subj_map_set.s_hash[i] = NULL;
64542+ }
64543+ }
64544+
64545+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
64546+ PAGE_SIZE)
64547+ kfree(subj_map_set.s_hash);
64548+ else
64549+ vfree(subj_map_set.s_hash);
64550+ }
64551+
64552+ return;
64553+}
64554+
64555+static void
64556+free_variables(void)
64557+{
64558+ struct acl_subject_label *s;
64559+ struct acl_role_label *r;
64560+ struct task_struct *task, *task2;
64561+ unsigned int x;
64562+
64563+ gr_clear_learn_entries();
64564+
64565+ read_lock(&tasklist_lock);
64566+ do_each_thread(task2, task) {
64567+ task->acl_sp_role = 0;
64568+ task->acl_role_id = 0;
64569+ task->acl = NULL;
64570+ task->role = NULL;
64571+ } while_each_thread(task2, task);
64572+ read_unlock(&tasklist_lock);
64573+
64574+ /* release the reference to the real root dentry and vfsmount */
64575+ path_put(&real_root);
64576+ memset(&real_root, 0, sizeof(real_root));
64577+
64578+ /* free all object hash tables */
64579+
64580+ FOR_EACH_ROLE_START(r)
64581+ if (r->subj_hash == NULL)
64582+ goto next_role;
64583+ FOR_EACH_SUBJECT_START(r, s, x)
64584+ if (s->obj_hash == NULL)
64585+ break;
64586+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
64587+ kfree(s->obj_hash);
64588+ else
64589+ vfree(s->obj_hash);
64590+ FOR_EACH_SUBJECT_END(s, x)
64591+ FOR_EACH_NESTED_SUBJECT_START(r, s)
64592+ if (s->obj_hash == NULL)
64593+ break;
64594+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
64595+ kfree(s->obj_hash);
64596+ else
64597+ vfree(s->obj_hash);
64598+ FOR_EACH_NESTED_SUBJECT_END(s)
64599+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
64600+ kfree(r->subj_hash);
64601+ else
64602+ vfree(r->subj_hash);
64603+ r->subj_hash = NULL;
64604+next_role:
64605+ FOR_EACH_ROLE_END(r)
64606+
64607+ acl_free_all();
64608+
64609+ if (acl_role_set.r_hash) {
64610+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
64611+ PAGE_SIZE)
64612+ kfree(acl_role_set.r_hash);
64613+ else
64614+ vfree(acl_role_set.r_hash);
64615+ }
64616+ if (name_set.n_hash) {
64617+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
64618+ PAGE_SIZE)
64619+ kfree(name_set.n_hash);
64620+ else
64621+ vfree(name_set.n_hash);
64622+ }
64623+
64624+ if (inodev_set.i_hash) {
64625+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
64626+ PAGE_SIZE)
64627+ kfree(inodev_set.i_hash);
64628+ else
64629+ vfree(inodev_set.i_hash);
64630+ }
64631+
64632+ gr_free_uidset();
64633+
64634+ memset(&name_set, 0, sizeof (struct name_db));
64635+ memset(&inodev_set, 0, sizeof (struct inodev_db));
64636+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
64637+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
64638+
64639+ default_role = NULL;
64640+ kernel_role = NULL;
64641+ role_list = NULL;
64642+
64643+ return;
64644+}
64645+
64646+static struct acl_subject_label *
64647+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
64648+
64649+static int alloc_and_copy_string(char **name, unsigned int maxlen)
64650+{
64651+ unsigned int len = strnlen_user(*name, maxlen);
64652+ char *tmp;
64653+
64654+ if (!len || len >= maxlen)
64655+ return -EINVAL;
64656+
64657+ if ((tmp = (char *) acl_alloc(len)) == NULL)
64658+ return -ENOMEM;
64659+
64660+ if (copy_from_user(tmp, *name, len))
64661+ return -EFAULT;
64662+
64663+ tmp[len-1] = '\0';
64664+ *name = tmp;
64665+
64666+ return 0;
64667+}
64668+
64669+static int
64670+copy_user_glob(struct acl_object_label *obj)
64671+{
64672+ struct acl_object_label *g_tmp, **guser;
64673+ int error;
64674+
64675+ if (obj->globbed == NULL)
64676+ return 0;
64677+
64678+ guser = &obj->globbed;
64679+ while (*guser) {
64680+ g_tmp = (struct acl_object_label *)
64681+ acl_alloc(sizeof (struct acl_object_label));
64682+ if (g_tmp == NULL)
64683+ return -ENOMEM;
64684+
64685+ if (copy_acl_object_label(g_tmp, *guser))
64686+ return -EFAULT;
64687+
64688+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
64689+ if (error)
64690+ return error;
64691+
64692+ *guser = g_tmp;
64693+ guser = &(g_tmp->next);
64694+ }
64695+
64696+ return 0;
64697+}
64698+
64699+static int
64700+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
64701+ struct acl_role_label *role)
64702+{
64703+ struct acl_object_label *o_tmp;
64704+ int ret;
64705+
64706+ while (userp) {
64707+ if ((o_tmp = (struct acl_object_label *)
64708+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
64709+ return -ENOMEM;
64710+
64711+ if (copy_acl_object_label(o_tmp, userp))
64712+ return -EFAULT;
64713+
64714+ userp = o_tmp->prev;
64715+
64716+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
64717+ if (ret)
64718+ return ret;
64719+
64720+ insert_acl_obj_label(o_tmp, subj);
64721+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
64722+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
64723+ return -ENOMEM;
64724+
64725+ ret = copy_user_glob(o_tmp);
64726+ if (ret)
64727+ return ret;
64728+
64729+ if (o_tmp->nested) {
64730+ int already_copied;
64731+
64732+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
64733+ if (IS_ERR(o_tmp->nested))
64734+ return PTR_ERR(o_tmp->nested);
64735+
64736+ /* insert into nested subject list if we haven't copied this one yet
64737+ to prevent duplicate entries */
64738+ if (!already_copied) {
64739+ o_tmp->nested->next = role->hash->first;
64740+ role->hash->first = o_tmp->nested;
64741+ }
64742+ }
64743+ }
64744+
64745+ return 0;
64746+}
64747+
64748+static __u32
64749+count_user_subjs(struct acl_subject_label *userp)
64750+{
64751+ struct acl_subject_label s_tmp;
64752+ __u32 num = 0;
64753+
64754+ while (userp) {
64755+ if (copy_acl_subject_label(&s_tmp, userp))
64756+ break;
64757+
64758+ userp = s_tmp.prev;
64759+ }
64760+
64761+ return num;
64762+}
64763+
64764+static int
64765+copy_user_allowedips(struct acl_role_label *rolep)
64766+{
64767+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
64768+
64769+ ruserip = rolep->allowed_ips;
64770+
64771+ while (ruserip) {
64772+ rlast = rtmp;
64773+
64774+ if ((rtmp = (struct role_allowed_ip *)
64775+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
64776+ return -ENOMEM;
64777+
64778+ if (copy_role_allowed_ip(rtmp, ruserip))
64779+ return -EFAULT;
64780+
64781+ ruserip = rtmp->prev;
64782+
64783+ if (!rlast) {
64784+ rtmp->prev = NULL;
64785+ rolep->allowed_ips = rtmp;
64786+ } else {
64787+ rlast->next = rtmp;
64788+ rtmp->prev = rlast;
64789+ }
64790+
64791+ if (!ruserip)
64792+ rtmp->next = NULL;
64793+ }
64794+
64795+ return 0;
64796+}
64797+
64798+static int
64799+copy_user_transitions(struct acl_role_label *rolep)
64800+{
64801+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
64802+ int error;
64803+
64804+ rusertp = rolep->transitions;
64805+
64806+ while (rusertp) {
64807+ rlast = rtmp;
64808+
64809+ if ((rtmp = (struct role_transition *)
64810+ acl_alloc(sizeof (struct role_transition))) == NULL)
64811+ return -ENOMEM;
64812+
64813+ if (copy_role_transition(rtmp, rusertp))
64814+ return -EFAULT;
64815+
64816+ rusertp = rtmp->prev;
64817+
64818+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
64819+ if (error)
64820+ return error;
64821+
64822+ if (!rlast) {
64823+ rtmp->prev = NULL;
64824+ rolep->transitions = rtmp;
64825+ } else {
64826+ rlast->next = rtmp;
64827+ rtmp->prev = rlast;
64828+ }
64829+
64830+ if (!rusertp)
64831+ rtmp->next = NULL;
64832+ }
64833+
64834+ return 0;
64835+}
64836+
64837+static __u32 count_user_objs(const struct acl_object_label __user *userp)
64838+{
64839+ struct acl_object_label o_tmp;
64840+ __u32 num = 0;
64841+
64842+ while (userp) {
64843+ if (copy_acl_object_label(&o_tmp, userp))
64844+ break;
64845+
64846+ userp = o_tmp.prev;
64847+ num++;
64848+ }
64849+
64850+ return num;
64851+}
64852+
64853+static struct acl_subject_label *
64854+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
64855+{
64856+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
64857+ __u32 num_objs;
64858+ struct acl_ip_label **i_tmp, *i_utmp2;
64859+ struct gr_hash_struct ghash;
64860+ struct subject_map *subjmap;
64861+ unsigned int i_num;
64862+ int err;
64863+
64864+ if (already_copied != NULL)
64865+ *already_copied = 0;
64866+
64867+ s_tmp = lookup_subject_map(userp);
64868+
64869+ /* we've already copied this subject into the kernel, just return
64870+ the reference to it, and don't copy it over again
64871+ */
64872+ if (s_tmp) {
64873+ if (already_copied != NULL)
64874+ *already_copied = 1;
64875+ return(s_tmp);
64876+ }
64877+
64878+ if ((s_tmp = (struct acl_subject_label *)
64879+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
64880+ return ERR_PTR(-ENOMEM);
64881+
64882+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
64883+ if (subjmap == NULL)
64884+ return ERR_PTR(-ENOMEM);
64885+
64886+ subjmap->user = userp;
64887+ subjmap->kernel = s_tmp;
64888+ insert_subj_map_entry(subjmap);
64889+
64890+ if (copy_acl_subject_label(s_tmp, userp))
64891+ return ERR_PTR(-EFAULT);
64892+
64893+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
64894+ if (err)
64895+ return ERR_PTR(err);
64896+
64897+ if (!strcmp(s_tmp->filename, "/"))
64898+ role->root_label = s_tmp;
64899+
64900+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
64901+ return ERR_PTR(-EFAULT);
64902+
64903+ /* copy user and group transition tables */
64904+
64905+ if (s_tmp->user_trans_num) {
64906+ uid_t *uidlist;
64907+
64908+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
64909+ if (uidlist == NULL)
64910+ return ERR_PTR(-ENOMEM);
64911+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
64912+ return ERR_PTR(-EFAULT);
64913+
64914+ s_tmp->user_transitions = uidlist;
64915+ }
64916+
64917+ if (s_tmp->group_trans_num) {
64918+ gid_t *gidlist;
64919+
64920+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
64921+ if (gidlist == NULL)
64922+ return ERR_PTR(-ENOMEM);
64923+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
64924+ return ERR_PTR(-EFAULT);
64925+
64926+ s_tmp->group_transitions = gidlist;
64927+ }
64928+
64929+ /* set up object hash table */
64930+ num_objs = count_user_objs(ghash.first);
64931+
64932+ s_tmp->obj_hash_size = num_objs;
64933+ s_tmp->obj_hash =
64934+ (struct acl_object_label **)
64935+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
64936+
64937+ if (!s_tmp->obj_hash)
64938+ return ERR_PTR(-ENOMEM);
64939+
64940+ memset(s_tmp->obj_hash, 0,
64941+ s_tmp->obj_hash_size *
64942+ sizeof (struct acl_object_label *));
64943+
64944+ /* add in objects */
64945+ err = copy_user_objs(ghash.first, s_tmp, role);
64946+
64947+ if (err)
64948+ return ERR_PTR(err);
64949+
64950+ /* set pointer for parent subject */
64951+ if (s_tmp->parent_subject) {
64952+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
64953+
64954+ if (IS_ERR(s_tmp2))
64955+ return s_tmp2;
64956+
64957+ s_tmp->parent_subject = s_tmp2;
64958+ }
64959+
64960+ /* add in ip acls */
64961+
64962+ if (!s_tmp->ip_num) {
64963+ s_tmp->ips = NULL;
64964+ goto insert;
64965+ }
64966+
64967+ i_tmp =
64968+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
64969+ sizeof (struct acl_ip_label *));
64970+
64971+ if (!i_tmp)
64972+ return ERR_PTR(-ENOMEM);
64973+
64974+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
64975+ *(i_tmp + i_num) =
64976+ (struct acl_ip_label *)
64977+ acl_alloc(sizeof (struct acl_ip_label));
64978+ if (!*(i_tmp + i_num))
64979+ return ERR_PTR(-ENOMEM);
64980+
64981+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
64982+ return ERR_PTR(-EFAULT);
64983+
64984+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
64985+ return ERR_PTR(-EFAULT);
64986+
64987+ if ((*(i_tmp + i_num))->iface == NULL)
64988+ continue;
64989+
64990+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
64991+ if (err)
64992+ return ERR_PTR(err);
64993+ }
64994+
64995+ s_tmp->ips = i_tmp;
64996+
64997+insert:
64998+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
64999+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
65000+ return ERR_PTR(-ENOMEM);
65001+
65002+ return s_tmp;
65003+}
65004+
65005+static int
65006+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
65007+{
65008+ struct acl_subject_label s_pre;
65009+ struct acl_subject_label * ret;
65010+ int err;
65011+
65012+ while (userp) {
65013+ if (copy_acl_subject_label(&s_pre, userp))
65014+ return -EFAULT;
65015+
65016+ ret = do_copy_user_subj(userp, role, NULL);
65017+
65018+ err = PTR_ERR(ret);
65019+ if (IS_ERR(ret))
65020+ return err;
65021+
65022+ insert_acl_subj_label(ret, role);
65023+
65024+ userp = s_pre.prev;
65025+ }
65026+
65027+ return 0;
65028+}
65029+
65030+static int
65031+copy_user_acl(struct gr_arg *arg)
65032+{
65033+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
65034+ struct acl_subject_label *subj_list;
65035+ struct sprole_pw *sptmp;
65036+ struct gr_hash_struct *ghash;
65037+ uid_t *domainlist;
65038+ unsigned int r_num;
65039+ int err = 0;
65040+ __u16 i;
65041+ __u32 num_subjs;
65042+
65043+ /* we need a default and kernel role */
65044+ if (arg->role_db.num_roles < 2)
65045+ return -EINVAL;
65046+
65047+ /* copy special role authentication info from userspace */
65048+
65049+ num_sprole_pws = arg->num_sprole_pws;
65050+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
65051+
65052+ if (!acl_special_roles && num_sprole_pws)
65053+ return -ENOMEM;
65054+
65055+ for (i = 0; i < num_sprole_pws; i++) {
65056+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
65057+ if (!sptmp)
65058+ return -ENOMEM;
65059+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
65060+ return -EFAULT;
65061+
65062+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
65063+ if (err)
65064+ return err;
65065+
65066+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65067+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
65068+#endif
65069+
65070+ acl_special_roles[i] = sptmp;
65071+ }
65072+
65073+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
65074+
65075+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
65076+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
65077+
65078+ if (!r_tmp)
65079+ return -ENOMEM;
65080+
65081+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
65082+ return -EFAULT;
65083+
65084+ if (copy_acl_role_label(r_tmp, r_utmp2))
65085+ return -EFAULT;
65086+
65087+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
65088+ if (err)
65089+ return err;
65090+
65091+ if (!strcmp(r_tmp->rolename, "default")
65092+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
65093+ default_role = r_tmp;
65094+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
65095+ kernel_role = r_tmp;
65096+ }
65097+
65098+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
65099+ return -ENOMEM;
65100+
65101+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
65102+ return -EFAULT;
65103+
65104+ r_tmp->hash = ghash;
65105+
65106+ num_subjs = count_user_subjs(r_tmp->hash->first);
65107+
65108+ r_tmp->subj_hash_size = num_subjs;
65109+ r_tmp->subj_hash =
65110+ (struct acl_subject_label **)
65111+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
65112+
65113+ if (!r_tmp->subj_hash)
65114+ return -ENOMEM;
65115+
65116+ err = copy_user_allowedips(r_tmp);
65117+ if (err)
65118+ return err;
65119+
65120+ /* copy domain info */
65121+ if (r_tmp->domain_children != NULL) {
65122+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
65123+ if (domainlist == NULL)
65124+ return -ENOMEM;
65125+
65126+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
65127+ return -EFAULT;
65128+
65129+ r_tmp->domain_children = domainlist;
65130+ }
65131+
65132+ err = copy_user_transitions(r_tmp);
65133+ if (err)
65134+ return err;
65135+
65136+ memset(r_tmp->subj_hash, 0,
65137+ r_tmp->subj_hash_size *
65138+ sizeof (struct acl_subject_label *));
65139+
65140+ /* acquire the list of subjects, then NULL out
65141+ the list prior to parsing the subjects for this role,
65142+ as during this parsing the list is replaced with a list
65143+ of *nested* subjects for the role
65144+ */
65145+ subj_list = r_tmp->hash->first;
65146+
65147+ /* set nested subject list to null */
65148+ r_tmp->hash->first = NULL;
65149+
65150+ err = copy_user_subjs(subj_list, r_tmp);
65151+
65152+ if (err)
65153+ return err;
65154+
65155+ insert_acl_role_label(r_tmp);
65156+ }
65157+
65158+ if (default_role == NULL || kernel_role == NULL)
65159+ return -EINVAL;
65160+
65161+ return err;
65162+}
65163+
65164+static int
65165+gracl_init(struct gr_arg *args)
65166+{
65167+ int error = 0;
65168+
65169+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
65170+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
65171+
65172+ if (init_variables(args)) {
65173+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
65174+ error = -ENOMEM;
65175+ free_variables();
65176+ goto out;
65177+ }
65178+
65179+ error = copy_user_acl(args);
65180+ free_init_variables();
65181+ if (error) {
65182+ free_variables();
65183+ goto out;
65184+ }
65185+
65186+ if ((error = gr_set_acls(0))) {
65187+ free_variables();
65188+ goto out;
65189+ }
65190+
65191+ pax_open_kernel();
65192+ gr_status |= GR_READY;
65193+ pax_close_kernel();
65194+
65195+ out:
65196+ return error;
65197+}
65198+
65199+/* derived from glibc fnmatch() 0: match, 1: no match*/
65200+
65201+static int
65202+glob_match(const char *p, const char *n)
65203+{
65204+ char c;
65205+
65206+ while ((c = *p++) != '\0') {
65207+ switch (c) {
65208+ case '?':
65209+ if (*n == '\0')
65210+ return 1;
65211+ else if (*n == '/')
65212+ return 1;
65213+ break;
65214+ case '\\':
65215+ if (*n != c)
65216+ return 1;
65217+ break;
65218+ case '*':
65219+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
65220+ if (*n == '/')
65221+ return 1;
65222+ else if (c == '?') {
65223+ if (*n == '\0')
65224+ return 1;
65225+ else
65226+ ++n;
65227+ }
65228+ }
65229+ if (c == '\0') {
65230+ return 0;
65231+ } else {
65232+ const char *endp;
65233+
65234+ if ((endp = strchr(n, '/')) == NULL)
65235+ endp = n + strlen(n);
65236+
65237+ if (c == '[') {
65238+ for (--p; n < endp; ++n)
65239+ if (!glob_match(p, n))
65240+ return 0;
65241+ } else if (c == '/') {
65242+ while (*n != '\0' && *n != '/')
65243+ ++n;
65244+ if (*n == '/' && !glob_match(p, n + 1))
65245+ return 0;
65246+ } else {
65247+ for (--p; n < endp; ++n)
65248+ if (*n == c && !glob_match(p, n))
65249+ return 0;
65250+ }
65251+
65252+ return 1;
65253+ }
65254+ case '[':
65255+ {
65256+ int not;
65257+ char cold;
65258+
65259+ if (*n == '\0' || *n == '/')
65260+ return 1;
65261+
65262+ not = (*p == '!' || *p == '^');
65263+ if (not)
65264+ ++p;
65265+
65266+ c = *p++;
65267+ for (;;) {
65268+ unsigned char fn = (unsigned char)*n;
65269+
65270+ if (c == '\0')
65271+ return 1;
65272+ else {
65273+ if (c == fn)
65274+ goto matched;
65275+ cold = c;
65276+ c = *p++;
65277+
65278+ if (c == '-' && *p != ']') {
65279+ unsigned char cend = *p++;
65280+
65281+ if (cend == '\0')
65282+ return 1;
65283+
65284+ if (cold <= fn && fn <= cend)
65285+ goto matched;
65286+
65287+ c = *p++;
65288+ }
65289+ }
65290+
65291+ if (c == ']')
65292+ break;
65293+ }
65294+ if (!not)
65295+ return 1;
65296+ break;
65297+ matched:
65298+ while (c != ']') {
65299+ if (c == '\0')
65300+ return 1;
65301+
65302+ c = *p++;
65303+ }
65304+ if (not)
65305+ return 1;
65306+ }
65307+ break;
65308+ default:
65309+ if (c != *n)
65310+ return 1;
65311+ }
65312+
65313+ ++n;
65314+ }
65315+
65316+ if (*n == '\0')
65317+ return 0;
65318+
65319+ if (*n == '/')
65320+ return 0;
65321+
65322+ return 1;
65323+}
65324+
65325+static struct acl_object_label *
65326+chk_glob_label(struct acl_object_label *globbed,
65327+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
65328+{
65329+ struct acl_object_label *tmp;
65330+
65331+ if (*path == NULL)
65332+ *path = gr_to_filename_nolock(dentry, mnt);
65333+
65334+ tmp = globbed;
65335+
65336+ while (tmp) {
65337+ if (!glob_match(tmp->filename, *path))
65338+ return tmp;
65339+ tmp = tmp->next;
65340+ }
65341+
65342+ return NULL;
65343+}
65344+
65345+static struct acl_object_label *
65346+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
65347+ const ino_t curr_ino, const dev_t curr_dev,
65348+ const struct acl_subject_label *subj, char **path, const int checkglob)
65349+{
65350+ struct acl_subject_label *tmpsubj;
65351+ struct acl_object_label *retval;
65352+ struct acl_object_label *retval2;
65353+
65354+ tmpsubj = (struct acl_subject_label *) subj;
65355+ read_lock(&gr_inode_lock);
65356+ do {
65357+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
65358+ if (retval) {
65359+ if (checkglob && retval->globbed) {
65360+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
65361+ if (retval2)
65362+ retval = retval2;
65363+ }
65364+ break;
65365+ }
65366+ } while ((tmpsubj = tmpsubj->parent_subject));
65367+ read_unlock(&gr_inode_lock);
65368+
65369+ return retval;
65370+}
65371+
65372+static __inline__ struct acl_object_label *
65373+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
65374+ struct dentry *curr_dentry,
65375+ const struct acl_subject_label *subj, char **path, const int checkglob)
65376+{
65377+ int newglob = checkglob;
65378+ ino_t inode;
65379+ dev_t device;
65380+
65381+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
65382+ as we don't want a / * rule to match instead of the / object
65383+ don't do this for create lookups that call this function though, since they're looking up
65384+ on the parent and thus need globbing checks on all paths
65385+ */
65386+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
65387+ newglob = GR_NO_GLOB;
65388+
65389+ spin_lock(&curr_dentry->d_lock);
65390+ inode = curr_dentry->d_inode->i_ino;
65391+ device = __get_dev(curr_dentry);
65392+ spin_unlock(&curr_dentry->d_lock);
65393+
65394+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
65395+}
65396+
65397+#ifdef CONFIG_HUGETLBFS
65398+static inline bool
65399+is_hugetlbfs_mnt(const struct vfsmount *mnt)
65400+{
65401+ int i;
65402+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
65403+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
65404+ return true;
65405+ }
65406+
65407+ return false;
65408+}
65409+#endif
65410+
65411+static struct acl_object_label *
65412+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65413+ const struct acl_subject_label *subj, char *path, const int checkglob)
65414+{
65415+ struct dentry *dentry = (struct dentry *) l_dentry;
65416+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
65417+ struct mount *real_mnt = real_mount(mnt);
65418+ struct acl_object_label *retval;
65419+ struct dentry *parent;
65420+
65421+ br_read_lock(&vfsmount_lock);
65422+ write_seqlock(&rename_lock);
65423+
65424+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
65425+#ifdef CONFIG_NET
65426+ mnt == sock_mnt ||
65427+#endif
65428+#ifdef CONFIG_HUGETLBFS
65429+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
65430+#endif
65431+ /* ignore Eric Biederman */
65432+ IS_PRIVATE(l_dentry->d_inode))) {
65433+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
65434+ goto out;
65435+ }
65436+
65437+ for (;;) {
65438+ if (dentry == real_root.dentry && mnt == real_root.mnt)
65439+ break;
65440+
65441+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
65442+ if (!mnt_has_parent(real_mnt))
65443+ break;
65444+
65445+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
65446+ if (retval != NULL)
65447+ goto out;
65448+
65449+ dentry = real_mnt->mnt_mountpoint;
65450+ real_mnt = real_mnt->mnt_parent;
65451+ mnt = &real_mnt->mnt;
65452+ continue;
65453+ }
65454+
65455+ parent = dentry->d_parent;
65456+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
65457+ if (retval != NULL)
65458+ goto out;
65459+
65460+ dentry = parent;
65461+ }
65462+
65463+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
65464+
65465+ /* real_root is pinned so we don't have to hold a reference */
65466+ if (retval == NULL)
65467+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
65468+out:
65469+ write_sequnlock(&rename_lock);
65470+ br_read_unlock(&vfsmount_lock);
65471+
65472+ BUG_ON(retval == NULL);
65473+
65474+ return retval;
65475+}
65476+
65477+static __inline__ struct acl_object_label *
65478+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65479+ const struct acl_subject_label *subj)
65480+{
65481+ char *path = NULL;
65482+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
65483+}
65484+
65485+static __inline__ struct acl_object_label *
65486+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65487+ const struct acl_subject_label *subj)
65488+{
65489+ char *path = NULL;
65490+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
65491+}
65492+
65493+static __inline__ struct acl_object_label *
65494+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65495+ const struct acl_subject_label *subj, char *path)
65496+{
65497+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
65498+}
65499+
65500+static struct acl_subject_label *
65501+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65502+ const struct acl_role_label *role)
65503+{
65504+ struct dentry *dentry = (struct dentry *) l_dentry;
65505+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
65506+ struct mount *real_mnt = real_mount(mnt);
65507+ struct acl_subject_label *retval;
65508+ struct dentry *parent;
65509+
65510+ br_read_lock(&vfsmount_lock);
65511+ write_seqlock(&rename_lock);
65512+
65513+ for (;;) {
65514+ if (dentry == real_root.dentry && mnt == real_root.mnt)
65515+ break;
65516+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
65517+ if (!mnt_has_parent(real_mnt))
65518+ break;
65519+
65520+ spin_lock(&dentry->d_lock);
65521+ read_lock(&gr_inode_lock);
65522+ retval =
65523+ lookup_acl_subj_label(dentry->d_inode->i_ino,
65524+ __get_dev(dentry), role);
65525+ read_unlock(&gr_inode_lock);
65526+ spin_unlock(&dentry->d_lock);
65527+ if (retval != NULL)
65528+ goto out;
65529+
65530+ dentry = real_mnt->mnt_mountpoint;
65531+ real_mnt = real_mnt->mnt_parent;
65532+ mnt = &real_mnt->mnt;
65533+ continue;
65534+ }
65535+
65536+ spin_lock(&dentry->d_lock);
65537+ read_lock(&gr_inode_lock);
65538+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
65539+ __get_dev(dentry), role);
65540+ read_unlock(&gr_inode_lock);
65541+ parent = dentry->d_parent;
65542+ spin_unlock(&dentry->d_lock);
65543+
65544+ if (retval != NULL)
65545+ goto out;
65546+
65547+ dentry = parent;
65548+ }
65549+
65550+ spin_lock(&dentry->d_lock);
65551+ read_lock(&gr_inode_lock);
65552+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
65553+ __get_dev(dentry), role);
65554+ read_unlock(&gr_inode_lock);
65555+ spin_unlock(&dentry->d_lock);
65556+
65557+ if (unlikely(retval == NULL)) {
65558+ /* real_root is pinned, we don't need to hold a reference */
65559+ read_lock(&gr_inode_lock);
65560+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
65561+ __get_dev(real_root.dentry), role);
65562+ read_unlock(&gr_inode_lock);
65563+ }
65564+out:
65565+ write_sequnlock(&rename_lock);
65566+ br_read_unlock(&vfsmount_lock);
65567+
65568+ BUG_ON(retval == NULL);
65569+
65570+ return retval;
65571+}
65572+
65573+static void
65574+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
65575+{
65576+ struct task_struct *task = current;
65577+ const struct cred *cred = current_cred();
65578+
65579+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
65580+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
65581+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
65582+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
65583+
65584+ return;
65585+}
65586+
65587+static void
65588+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
65589+{
65590+ struct task_struct *task = current;
65591+ const struct cred *cred = current_cred();
65592+
65593+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
65594+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
65595+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
65596+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
65597+
65598+ return;
65599+}
65600+
65601+static void
65602+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
65603+{
65604+ struct task_struct *task = current;
65605+ const struct cred *cred = current_cred();
65606+
65607+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
65608+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
65609+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
65610+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
65611+
65612+ return;
65613+}
65614+
65615+__u32
65616+gr_search_file(const struct dentry * dentry, const __u32 mode,
65617+ const struct vfsmount * mnt)
65618+{
65619+ __u32 retval = mode;
65620+ struct acl_subject_label *curracl;
65621+ struct acl_object_label *currobj;
65622+
65623+ if (unlikely(!(gr_status & GR_READY)))
65624+ return (mode & ~GR_AUDITS);
65625+
65626+ curracl = current->acl;
65627+
65628+ currobj = chk_obj_label(dentry, mnt, curracl);
65629+ retval = currobj->mode & mode;
65630+
65631+ /* if we're opening a specified transfer file for writing
65632+ (e.g. /dev/initctl), then transfer our role to init
65633+ */
65634+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
65635+ current->role->roletype & GR_ROLE_PERSIST)) {
65636+ struct task_struct *task = init_pid_ns.child_reaper;
65637+
65638+ if (task->role != current->role) {
65639+ task->acl_sp_role = 0;
65640+ task->acl_role_id = current->acl_role_id;
65641+ task->role = current->role;
65642+ rcu_read_lock();
65643+ read_lock(&grsec_exec_file_lock);
65644+ gr_apply_subject_to_task(task);
65645+ read_unlock(&grsec_exec_file_lock);
65646+ rcu_read_unlock();
65647+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
65648+ }
65649+ }
65650+
65651+ if (unlikely
65652+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
65653+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
65654+ __u32 new_mode = mode;
65655+
65656+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
65657+
65658+ retval = new_mode;
65659+
65660+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
65661+ new_mode |= GR_INHERIT;
65662+
65663+ if (!(mode & GR_NOLEARN))
65664+ gr_log_learn(dentry, mnt, new_mode);
65665+ }
65666+
65667+ return retval;
65668+}
65669+
65670+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
65671+ const struct dentry *parent,
65672+ const struct vfsmount *mnt)
65673+{
65674+ struct name_entry *match;
65675+ struct acl_object_label *matchpo;
65676+ struct acl_subject_label *curracl;
65677+ char *path;
65678+
65679+ if (unlikely(!(gr_status & GR_READY)))
65680+ return NULL;
65681+
65682+ preempt_disable();
65683+ path = gr_to_filename_rbac(new_dentry, mnt);
65684+ match = lookup_name_entry_create(path);
65685+
65686+ curracl = current->acl;
65687+
65688+ if (match) {
65689+ read_lock(&gr_inode_lock);
65690+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
65691+ read_unlock(&gr_inode_lock);
65692+
65693+ if (matchpo) {
65694+ preempt_enable();
65695+ return matchpo;
65696+ }
65697+ }
65698+
65699+ // lookup parent
65700+
65701+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
65702+
65703+ preempt_enable();
65704+ return matchpo;
65705+}
65706+
65707+__u32
65708+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
65709+ const struct vfsmount * mnt, const __u32 mode)
65710+{
65711+ struct acl_object_label *matchpo;
65712+ __u32 retval;
65713+
65714+ if (unlikely(!(gr_status & GR_READY)))
65715+ return (mode & ~GR_AUDITS);
65716+
65717+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
65718+
65719+ retval = matchpo->mode & mode;
65720+
65721+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
65722+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
65723+ __u32 new_mode = mode;
65724+
65725+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
65726+
65727+ gr_log_learn(new_dentry, mnt, new_mode);
65728+ return new_mode;
65729+ }
65730+
65731+ return retval;
65732+}
65733+
65734+__u32
65735+gr_check_link(const struct dentry * new_dentry,
65736+ const struct dentry * parent_dentry,
65737+ const struct vfsmount * parent_mnt,
65738+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
65739+{
65740+ struct acl_object_label *obj;
65741+ __u32 oldmode, newmode;
65742+ __u32 needmode;
65743+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
65744+ GR_DELETE | GR_INHERIT;
65745+
65746+ if (unlikely(!(gr_status & GR_READY)))
65747+ return (GR_CREATE | GR_LINK);
65748+
65749+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
65750+ oldmode = obj->mode;
65751+
65752+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
65753+ newmode = obj->mode;
65754+
65755+ needmode = newmode & checkmodes;
65756+
65757+ // old name for hardlink must have at least the permissions of the new name
65758+ if ((oldmode & needmode) != needmode)
65759+ goto bad;
65760+
65761+ // if old name had restrictions/auditing, make sure the new name does as well
65762+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
65763+
65764+ // don't allow hardlinking of suid/sgid/fcapped files without permission
65765+ if (is_privileged_binary(old_dentry))
65766+ needmode |= GR_SETID;
65767+
65768+ if ((newmode & needmode) != needmode)
65769+ goto bad;
65770+
65771+ // enforce minimum permissions
65772+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
65773+ return newmode;
65774+bad:
65775+ needmode = oldmode;
65776+ if (is_privileged_binary(old_dentry))
65777+ needmode |= GR_SETID;
65778+
65779+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
65780+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
65781+ return (GR_CREATE | GR_LINK);
65782+ } else if (newmode & GR_SUPPRESS)
65783+ return GR_SUPPRESS;
65784+ else
65785+ return 0;
65786+}
65787+
65788+int
65789+gr_check_hidden_task(const struct task_struct *task)
65790+{
65791+ if (unlikely(!(gr_status & GR_READY)))
65792+ return 0;
65793+
65794+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
65795+ return 1;
65796+
65797+ return 0;
65798+}
65799+
65800+int
65801+gr_check_protected_task(const struct task_struct *task)
65802+{
65803+ if (unlikely(!(gr_status & GR_READY) || !task))
65804+ return 0;
65805+
65806+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
65807+ task->acl != current->acl)
65808+ return 1;
65809+
65810+ return 0;
65811+}
65812+
65813+int
65814+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
65815+{
65816+ struct task_struct *p;
65817+ int ret = 0;
65818+
65819+ if (unlikely(!(gr_status & GR_READY) || !pid))
65820+ return ret;
65821+
65822+ read_lock(&tasklist_lock);
65823+ do_each_pid_task(pid, type, p) {
65824+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
65825+ p->acl != current->acl) {
65826+ ret = 1;
65827+ goto out;
65828+ }
65829+ } while_each_pid_task(pid, type, p);
65830+out:
65831+ read_unlock(&tasklist_lock);
65832+
65833+ return ret;
65834+}
65835+
65836+void
65837+gr_copy_label(struct task_struct *tsk)
65838+{
65839+ tsk->signal->used_accept = 0;
65840+ tsk->acl_sp_role = 0;
65841+ tsk->acl_role_id = current->acl_role_id;
65842+ tsk->acl = current->acl;
65843+ tsk->role = current->role;
65844+ tsk->signal->curr_ip = current->signal->curr_ip;
65845+ tsk->signal->saved_ip = current->signal->saved_ip;
65846+ if (current->exec_file)
65847+ get_file(current->exec_file);
65848+ tsk->exec_file = current->exec_file;
65849+ tsk->is_writable = current->is_writable;
65850+ if (unlikely(current->signal->used_accept)) {
65851+ current->signal->curr_ip = 0;
65852+ current->signal->saved_ip = 0;
65853+ }
65854+
65855+ return;
65856+}
65857+
65858+static void
65859+gr_set_proc_res(struct task_struct *task)
65860+{
65861+ struct acl_subject_label *proc;
65862+ unsigned short i;
65863+
65864+ proc = task->acl;
65865+
65866+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
65867+ return;
65868+
65869+ for (i = 0; i < RLIM_NLIMITS; i++) {
65870+ if (!(proc->resmask & (1U << i)))
65871+ continue;
65872+
65873+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
65874+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
65875+
65876+ if (i == RLIMIT_CPU)
65877+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
65878+ }
65879+
65880+ return;
65881+}
65882+
65883+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
65884+
65885+int
65886+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
65887+{
65888+ unsigned int i;
65889+ __u16 num;
65890+ uid_t *uidlist;
65891+ uid_t curuid;
65892+ int realok = 0;
65893+ int effectiveok = 0;
65894+ int fsok = 0;
65895+ uid_t globalreal, globaleffective, globalfs;
65896+
65897+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
65898+ struct user_struct *user;
65899+
65900+ if (!uid_valid(real))
65901+ goto skipit;
65902+
65903+ /* find user based on global namespace */
65904+
65905+ globalreal = GR_GLOBAL_UID(real);
65906+
65907+ user = find_user(make_kuid(&init_user_ns, globalreal));
65908+ if (user == NULL)
65909+ goto skipit;
65910+
65911+ if (gr_process_kernel_setuid_ban(user)) {
65912+ /* for find_user */
65913+ free_uid(user);
65914+ return 1;
65915+ }
65916+
65917+ /* for find_user */
65918+ free_uid(user);
65919+
65920+skipit:
65921+#endif
65922+
65923+ if (unlikely(!(gr_status & GR_READY)))
65924+ return 0;
65925+
65926+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
65927+ gr_log_learn_uid_change(real, effective, fs);
65928+
65929+ num = current->acl->user_trans_num;
65930+ uidlist = current->acl->user_transitions;
65931+
65932+ if (uidlist == NULL)
65933+ return 0;
65934+
65935+ if (!uid_valid(real)) {
65936+ realok = 1;
65937+ globalreal = (uid_t)-1;
65938+ } else {
65939+ globalreal = GR_GLOBAL_UID(real);
65940+ }
65941+ if (!uid_valid(effective)) {
65942+ effectiveok = 1;
65943+ globaleffective = (uid_t)-1;
65944+ } else {
65945+ globaleffective = GR_GLOBAL_UID(effective);
65946+ }
65947+ if (!uid_valid(fs)) {
65948+ fsok = 1;
65949+ globalfs = (uid_t)-1;
65950+ } else {
65951+ globalfs = GR_GLOBAL_UID(fs);
65952+ }
65953+
65954+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
65955+ for (i = 0; i < num; i++) {
65956+ curuid = uidlist[i];
65957+ if (globalreal == curuid)
65958+ realok = 1;
65959+ if (globaleffective == curuid)
65960+ effectiveok = 1;
65961+ if (globalfs == curuid)
65962+ fsok = 1;
65963+ }
65964+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
65965+ for (i = 0; i < num; i++) {
65966+ curuid = uidlist[i];
65967+ if (globalreal == curuid)
65968+ break;
65969+ if (globaleffective == curuid)
65970+ break;
65971+ if (globalfs == curuid)
65972+ break;
65973+ }
65974+ /* not in deny list */
65975+ if (i == num) {
65976+ realok = 1;
65977+ effectiveok = 1;
65978+ fsok = 1;
65979+ }
65980+ }
65981+
65982+ if (realok && effectiveok && fsok)
65983+ return 0;
65984+ else {
65985+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
65986+ return 1;
65987+ }
65988+}
65989+
65990+int
65991+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
65992+{
65993+ unsigned int i;
65994+ __u16 num;
65995+ gid_t *gidlist;
65996+ gid_t curgid;
65997+ int realok = 0;
65998+ int effectiveok = 0;
65999+ int fsok = 0;
66000+ gid_t globalreal, globaleffective, globalfs;
66001+
66002+ if (unlikely(!(gr_status & GR_READY)))
66003+ return 0;
66004+
66005+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66006+ gr_log_learn_gid_change(real, effective, fs);
66007+
66008+ num = current->acl->group_trans_num;
66009+ gidlist = current->acl->group_transitions;
66010+
66011+ if (gidlist == NULL)
66012+ return 0;
66013+
66014+ if (!gid_valid(real)) {
66015+ realok = 1;
66016+ globalreal = (gid_t)-1;
66017+ } else {
66018+ globalreal = GR_GLOBAL_GID(real);
66019+ }
66020+ if (!gid_valid(effective)) {
66021+ effectiveok = 1;
66022+ globaleffective = (gid_t)-1;
66023+ } else {
66024+ globaleffective = GR_GLOBAL_GID(effective);
66025+ }
66026+ if (!gid_valid(fs)) {
66027+ fsok = 1;
66028+ globalfs = (gid_t)-1;
66029+ } else {
66030+ globalfs = GR_GLOBAL_GID(fs);
66031+ }
66032+
66033+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
66034+ for (i = 0; i < num; i++) {
66035+ curgid = gidlist[i];
66036+ if (globalreal == curgid)
66037+ realok = 1;
66038+ if (globaleffective == curgid)
66039+ effectiveok = 1;
66040+ if (globalfs == curgid)
66041+ fsok = 1;
66042+ }
66043+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
66044+ for (i = 0; i < num; i++) {
66045+ curgid = gidlist[i];
66046+ if (globalreal == curgid)
66047+ break;
66048+ if (globaleffective == curgid)
66049+ break;
66050+ if (globalfs == curgid)
66051+ break;
66052+ }
66053+ /* not in deny list */
66054+ if (i == num) {
66055+ realok = 1;
66056+ effectiveok = 1;
66057+ fsok = 1;
66058+ }
66059+ }
66060+
66061+ if (realok && effectiveok && fsok)
66062+ return 0;
66063+ else {
66064+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
66065+ return 1;
66066+ }
66067+}
66068+
66069+extern int gr_acl_is_capable(const int cap);
66070+
66071+void
66072+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
66073+{
66074+ struct acl_role_label *role = task->role;
66075+ struct acl_subject_label *subj = NULL;
66076+ struct acl_object_label *obj;
66077+ struct file *filp;
66078+ uid_t uid;
66079+ gid_t gid;
66080+
66081+ if (unlikely(!(gr_status & GR_READY)))
66082+ return;
66083+
66084+ uid = GR_GLOBAL_UID(kuid);
66085+ gid = GR_GLOBAL_GID(kgid);
66086+
66087+ filp = task->exec_file;
66088+
66089+ /* kernel process, we'll give them the kernel role */
66090+ if (unlikely(!filp)) {
66091+ task->role = kernel_role;
66092+ task->acl = kernel_role->root_label;
66093+ return;
66094+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
66095+ role = lookup_acl_role_label(task, uid, gid);
66096+
66097+ /* don't change the role if we're not a privileged process */
66098+ if (role && task->role != role &&
66099+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
66100+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
66101+ return;
66102+
66103+ /* perform subject lookup in possibly new role
66104+ we can use this result below in the case where role == task->role
66105+ */
66106+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
66107+
66108+ /* if we changed uid/gid, but result in the same role
66109+ and are using inheritance, don't lose the inherited subject
66110+ if current subject is other than what normal lookup
66111+ would result in, we arrived via inheritance, don't
66112+ lose subject
66113+ */
66114+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
66115+ (subj == task->acl)))
66116+ task->acl = subj;
66117+
66118+ task->role = role;
66119+
66120+ task->is_writable = 0;
66121+
66122+ /* ignore additional mmap checks for processes that are writable
66123+ by the default ACL */
66124+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
66125+ if (unlikely(obj->mode & GR_WRITE))
66126+ task->is_writable = 1;
66127+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
66128+ if (unlikely(obj->mode & GR_WRITE))
66129+ task->is_writable = 1;
66130+
66131+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66132+ 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);
66133+#endif
66134+
66135+ gr_set_proc_res(task);
66136+
66137+ return;
66138+}
66139+
66140+int
66141+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
66142+ const int unsafe_flags)
66143+{
66144+ struct task_struct *task = current;
66145+ struct acl_subject_label *newacl;
66146+ struct acl_object_label *obj;
66147+ __u32 retmode;
66148+
66149+ if (unlikely(!(gr_status & GR_READY)))
66150+ return 0;
66151+
66152+ newacl = chk_subj_label(dentry, mnt, task->role);
66153+
66154+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
66155+ did an exec
66156+ */
66157+ rcu_read_lock();
66158+ read_lock(&tasklist_lock);
66159+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
66160+ (task->parent->acl->mode & GR_POVERRIDE))) {
66161+ read_unlock(&tasklist_lock);
66162+ rcu_read_unlock();
66163+ goto skip_check;
66164+ }
66165+ read_unlock(&tasklist_lock);
66166+ rcu_read_unlock();
66167+
66168+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
66169+ !(task->role->roletype & GR_ROLE_GOD) &&
66170+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
66171+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
66172+ if (unsafe_flags & LSM_UNSAFE_SHARE)
66173+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
66174+ else
66175+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
66176+ return -EACCES;
66177+ }
66178+
66179+skip_check:
66180+
66181+ obj = chk_obj_label(dentry, mnt, task->acl);
66182+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
66183+
66184+ if (!(task->acl->mode & GR_INHERITLEARN) &&
66185+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
66186+ if (obj->nested)
66187+ task->acl = obj->nested;
66188+ else
66189+ task->acl = newacl;
66190+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
66191+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
66192+
66193+ task->is_writable = 0;
66194+
66195+ /* ignore additional mmap checks for processes that are writable
66196+ by the default ACL */
66197+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
66198+ if (unlikely(obj->mode & GR_WRITE))
66199+ task->is_writable = 1;
66200+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
66201+ if (unlikely(obj->mode & GR_WRITE))
66202+ task->is_writable = 1;
66203+
66204+ gr_set_proc_res(task);
66205+
66206+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66207+ 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);
66208+#endif
66209+ return 0;
66210+}
66211+
66212+/* always called with valid inodev ptr */
66213+static void
66214+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
66215+{
66216+ struct acl_object_label *matchpo;
66217+ struct acl_subject_label *matchps;
66218+ struct acl_subject_label *subj;
66219+ struct acl_role_label *role;
66220+ unsigned int x;
66221+
66222+ FOR_EACH_ROLE_START(role)
66223+ FOR_EACH_SUBJECT_START(role, subj, x)
66224+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
66225+ matchpo->mode |= GR_DELETED;
66226+ FOR_EACH_SUBJECT_END(subj,x)
66227+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
66228+ /* nested subjects aren't in the role's subj_hash table */
66229+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
66230+ matchpo->mode |= GR_DELETED;
66231+ FOR_EACH_NESTED_SUBJECT_END(subj)
66232+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
66233+ matchps->mode |= GR_DELETED;
66234+ FOR_EACH_ROLE_END(role)
66235+
66236+ inodev->nentry->deleted = 1;
66237+
66238+ return;
66239+}
66240+
66241+void
66242+gr_handle_delete(const ino_t ino, const dev_t dev)
66243+{
66244+ struct inodev_entry *inodev;
66245+
66246+ if (unlikely(!(gr_status & GR_READY)))
66247+ return;
66248+
66249+ write_lock(&gr_inode_lock);
66250+ inodev = lookup_inodev_entry(ino, dev);
66251+ if (inodev != NULL)
66252+ do_handle_delete(inodev, ino, dev);
66253+ write_unlock(&gr_inode_lock);
66254+
66255+ return;
66256+}
66257+
66258+static void
66259+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
66260+ const ino_t newinode, const dev_t newdevice,
66261+ struct acl_subject_label *subj)
66262+{
66263+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
66264+ struct acl_object_label *match;
66265+
66266+ match = subj->obj_hash[index];
66267+
66268+ while (match && (match->inode != oldinode ||
66269+ match->device != olddevice ||
66270+ !(match->mode & GR_DELETED)))
66271+ match = match->next;
66272+
66273+ if (match && (match->inode == oldinode)
66274+ && (match->device == olddevice)
66275+ && (match->mode & GR_DELETED)) {
66276+ if (match->prev == NULL) {
66277+ subj->obj_hash[index] = match->next;
66278+ if (match->next != NULL)
66279+ match->next->prev = NULL;
66280+ } else {
66281+ match->prev->next = match->next;
66282+ if (match->next != NULL)
66283+ match->next->prev = match->prev;
66284+ }
66285+ match->prev = NULL;
66286+ match->next = NULL;
66287+ match->inode = newinode;
66288+ match->device = newdevice;
66289+ match->mode &= ~GR_DELETED;
66290+
66291+ insert_acl_obj_label(match, subj);
66292+ }
66293+
66294+ return;
66295+}
66296+
66297+static void
66298+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
66299+ const ino_t newinode, const dev_t newdevice,
66300+ struct acl_role_label *role)
66301+{
66302+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
66303+ struct acl_subject_label *match;
66304+
66305+ match = role->subj_hash[index];
66306+
66307+ while (match && (match->inode != oldinode ||
66308+ match->device != olddevice ||
66309+ !(match->mode & GR_DELETED)))
66310+ match = match->next;
66311+
66312+ if (match && (match->inode == oldinode)
66313+ && (match->device == olddevice)
66314+ && (match->mode & GR_DELETED)) {
66315+ if (match->prev == NULL) {
66316+ role->subj_hash[index] = match->next;
66317+ if (match->next != NULL)
66318+ match->next->prev = NULL;
66319+ } else {
66320+ match->prev->next = match->next;
66321+ if (match->next != NULL)
66322+ match->next->prev = match->prev;
66323+ }
66324+ match->prev = NULL;
66325+ match->next = NULL;
66326+ match->inode = newinode;
66327+ match->device = newdevice;
66328+ match->mode &= ~GR_DELETED;
66329+
66330+ insert_acl_subj_label(match, role);
66331+ }
66332+
66333+ return;
66334+}
66335+
66336+static void
66337+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
66338+ const ino_t newinode, const dev_t newdevice)
66339+{
66340+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
66341+ struct inodev_entry *match;
66342+
66343+ match = inodev_set.i_hash[index];
66344+
66345+ while (match && (match->nentry->inode != oldinode ||
66346+ match->nentry->device != olddevice || !match->nentry->deleted))
66347+ match = match->next;
66348+
66349+ if (match && (match->nentry->inode == oldinode)
66350+ && (match->nentry->device == olddevice) &&
66351+ match->nentry->deleted) {
66352+ if (match->prev == NULL) {
66353+ inodev_set.i_hash[index] = match->next;
66354+ if (match->next != NULL)
66355+ match->next->prev = NULL;
66356+ } else {
66357+ match->prev->next = match->next;
66358+ if (match->next != NULL)
66359+ match->next->prev = match->prev;
66360+ }
66361+ match->prev = NULL;
66362+ match->next = NULL;
66363+ match->nentry->inode = newinode;
66364+ match->nentry->device = newdevice;
66365+ match->nentry->deleted = 0;
66366+
66367+ insert_inodev_entry(match);
66368+ }
66369+
66370+ return;
66371+}
66372+
66373+static void
66374+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
66375+{
66376+ struct acl_subject_label *subj;
66377+ struct acl_role_label *role;
66378+ unsigned int x;
66379+
66380+ FOR_EACH_ROLE_START(role)
66381+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
66382+
66383+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
66384+ if ((subj->inode == ino) && (subj->device == dev)) {
66385+ subj->inode = ino;
66386+ subj->device = dev;
66387+ }
66388+ /* nested subjects aren't in the role's subj_hash table */
66389+ update_acl_obj_label(matchn->inode, matchn->device,
66390+ ino, dev, subj);
66391+ FOR_EACH_NESTED_SUBJECT_END(subj)
66392+ FOR_EACH_SUBJECT_START(role, subj, x)
66393+ update_acl_obj_label(matchn->inode, matchn->device,
66394+ ino, dev, subj);
66395+ FOR_EACH_SUBJECT_END(subj,x)
66396+ FOR_EACH_ROLE_END(role)
66397+
66398+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
66399+
66400+ return;
66401+}
66402+
66403+static void
66404+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
66405+ const struct vfsmount *mnt)
66406+{
66407+ ino_t ino = dentry->d_inode->i_ino;
66408+ dev_t dev = __get_dev(dentry);
66409+
66410+ __do_handle_create(matchn, ino, dev);
66411+
66412+ return;
66413+}
66414+
66415+void
66416+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
66417+{
66418+ struct name_entry *matchn;
66419+
66420+ if (unlikely(!(gr_status & GR_READY)))
66421+ return;
66422+
66423+ preempt_disable();
66424+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
66425+
66426+ if (unlikely((unsigned long)matchn)) {
66427+ write_lock(&gr_inode_lock);
66428+ do_handle_create(matchn, dentry, mnt);
66429+ write_unlock(&gr_inode_lock);
66430+ }
66431+ preempt_enable();
66432+
66433+ return;
66434+}
66435+
66436+void
66437+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
66438+{
66439+ struct name_entry *matchn;
66440+
66441+ if (unlikely(!(gr_status & GR_READY)))
66442+ return;
66443+
66444+ preempt_disable();
66445+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
66446+
66447+ if (unlikely((unsigned long)matchn)) {
66448+ write_lock(&gr_inode_lock);
66449+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
66450+ write_unlock(&gr_inode_lock);
66451+ }
66452+ preempt_enable();
66453+
66454+ return;
66455+}
66456+
66457+void
66458+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
66459+ struct dentry *old_dentry,
66460+ struct dentry *new_dentry,
66461+ struct vfsmount *mnt, const __u8 replace)
66462+{
66463+ struct name_entry *matchn;
66464+ struct inodev_entry *inodev;
66465+ struct inode *inode = new_dentry->d_inode;
66466+ ino_t old_ino = old_dentry->d_inode->i_ino;
66467+ dev_t old_dev = __get_dev(old_dentry);
66468+
66469+ /* vfs_rename swaps the name and parent link for old_dentry and
66470+ new_dentry
66471+ at this point, old_dentry has the new name, parent link, and inode
66472+ for the renamed file
66473+ if a file is being replaced by a rename, new_dentry has the inode
66474+ and name for the replaced file
66475+ */
66476+
66477+ if (unlikely(!(gr_status & GR_READY)))
66478+ return;
66479+
66480+ preempt_disable();
66481+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
66482+
66483+ /* we wouldn't have to check d_inode if it weren't for
66484+ NFS silly-renaming
66485+ */
66486+
66487+ write_lock(&gr_inode_lock);
66488+ if (unlikely(replace && inode)) {
66489+ ino_t new_ino = inode->i_ino;
66490+ dev_t new_dev = __get_dev(new_dentry);
66491+
66492+ inodev = lookup_inodev_entry(new_ino, new_dev);
66493+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
66494+ do_handle_delete(inodev, new_ino, new_dev);
66495+ }
66496+
66497+ inodev = lookup_inodev_entry(old_ino, old_dev);
66498+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
66499+ do_handle_delete(inodev, old_ino, old_dev);
66500+
66501+ if (unlikely((unsigned long)matchn))
66502+ do_handle_create(matchn, old_dentry, mnt);
66503+
66504+ write_unlock(&gr_inode_lock);
66505+ preempt_enable();
66506+
66507+ return;
66508+}
66509+
66510+static int
66511+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
66512+ unsigned char **sum)
66513+{
66514+ struct acl_role_label *r;
66515+ struct role_allowed_ip *ipp;
66516+ struct role_transition *trans;
66517+ unsigned int i;
66518+ int found = 0;
66519+ u32 curr_ip = current->signal->curr_ip;
66520+
66521+ current->signal->saved_ip = curr_ip;
66522+
66523+ /* check transition table */
66524+
66525+ for (trans = current->role->transitions; trans; trans = trans->next) {
66526+ if (!strcmp(rolename, trans->rolename)) {
66527+ found = 1;
66528+ break;
66529+ }
66530+ }
66531+
66532+ if (!found)
66533+ return 0;
66534+
66535+ /* handle special roles that do not require authentication
66536+ and check ip */
66537+
66538+ FOR_EACH_ROLE_START(r)
66539+ if (!strcmp(rolename, r->rolename) &&
66540+ (r->roletype & GR_ROLE_SPECIAL)) {
66541+ found = 0;
66542+ if (r->allowed_ips != NULL) {
66543+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
66544+ if ((ntohl(curr_ip) & ipp->netmask) ==
66545+ (ntohl(ipp->addr) & ipp->netmask))
66546+ found = 1;
66547+ }
66548+ } else
66549+ found = 2;
66550+ if (!found)
66551+ return 0;
66552+
66553+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
66554+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
66555+ *salt = NULL;
66556+ *sum = NULL;
66557+ return 1;
66558+ }
66559+ }
66560+ FOR_EACH_ROLE_END(r)
66561+
66562+ for (i = 0; i < num_sprole_pws; i++) {
66563+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
66564+ *salt = acl_special_roles[i]->salt;
66565+ *sum = acl_special_roles[i]->sum;
66566+ return 1;
66567+ }
66568+ }
66569+
66570+ return 0;
66571+}
66572+
66573+static void
66574+assign_special_role(char *rolename)
66575+{
66576+ struct acl_object_label *obj;
66577+ struct acl_role_label *r;
66578+ struct acl_role_label *assigned = NULL;
66579+ struct task_struct *tsk;
66580+ struct file *filp;
66581+
66582+ FOR_EACH_ROLE_START(r)
66583+ if (!strcmp(rolename, r->rolename) &&
66584+ (r->roletype & GR_ROLE_SPECIAL)) {
66585+ assigned = r;
66586+ break;
66587+ }
66588+ FOR_EACH_ROLE_END(r)
66589+
66590+ if (!assigned)
66591+ return;
66592+
66593+ read_lock(&tasklist_lock);
66594+ read_lock(&grsec_exec_file_lock);
66595+
66596+ tsk = current->real_parent;
66597+ if (tsk == NULL)
66598+ goto out_unlock;
66599+
66600+ filp = tsk->exec_file;
66601+ if (filp == NULL)
66602+ goto out_unlock;
66603+
66604+ tsk->is_writable = 0;
66605+
66606+ tsk->acl_sp_role = 1;
66607+ tsk->acl_role_id = ++acl_sp_role_value;
66608+ tsk->role = assigned;
66609+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
66610+
66611+ /* ignore additional mmap checks for processes that are writable
66612+ by the default ACL */
66613+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
66614+ if (unlikely(obj->mode & GR_WRITE))
66615+ tsk->is_writable = 1;
66616+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
66617+ if (unlikely(obj->mode & GR_WRITE))
66618+ tsk->is_writable = 1;
66619+
66620+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66621+ 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));
66622+#endif
66623+
66624+out_unlock:
66625+ read_unlock(&grsec_exec_file_lock);
66626+ read_unlock(&tasklist_lock);
66627+ return;
66628+}
66629+
66630+int gr_check_secure_terminal(struct task_struct *task)
66631+{
66632+ struct task_struct *p, *p2, *p3;
66633+ struct files_struct *files;
66634+ struct fdtable *fdt;
66635+ struct file *our_file = NULL, *file;
66636+ int i;
66637+
66638+ if (task->signal->tty == NULL)
66639+ return 1;
66640+
66641+ files = get_files_struct(task);
66642+ if (files != NULL) {
66643+ rcu_read_lock();
66644+ fdt = files_fdtable(files);
66645+ for (i=0; i < fdt->max_fds; i++) {
66646+ file = fcheck_files(files, i);
66647+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
66648+ get_file(file);
66649+ our_file = file;
66650+ }
66651+ }
66652+ rcu_read_unlock();
66653+ put_files_struct(files);
66654+ }
66655+
66656+ if (our_file == NULL)
66657+ return 1;
66658+
66659+ read_lock(&tasklist_lock);
66660+ do_each_thread(p2, p) {
66661+ files = get_files_struct(p);
66662+ if (files == NULL ||
66663+ (p->signal && p->signal->tty == task->signal->tty)) {
66664+ if (files != NULL)
66665+ put_files_struct(files);
66666+ continue;
66667+ }
66668+ rcu_read_lock();
66669+ fdt = files_fdtable(files);
66670+ for (i=0; i < fdt->max_fds; i++) {
66671+ file = fcheck_files(files, i);
66672+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
66673+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
66674+ p3 = task;
66675+ while (task_pid_nr(p3) > 0) {
66676+ if (p3 == p)
66677+ break;
66678+ p3 = p3->real_parent;
66679+ }
66680+ if (p3 == p)
66681+ break;
66682+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
66683+ gr_handle_alertkill(p);
66684+ rcu_read_unlock();
66685+ put_files_struct(files);
66686+ read_unlock(&tasklist_lock);
66687+ fput(our_file);
66688+ return 0;
66689+ }
66690+ }
66691+ rcu_read_unlock();
66692+ put_files_struct(files);
66693+ } while_each_thread(p2, p);
66694+ read_unlock(&tasklist_lock);
66695+
66696+ fput(our_file);
66697+ return 1;
66698+}
66699+
66700+static int gr_rbac_disable(void *unused)
66701+{
66702+ pax_open_kernel();
66703+ gr_status &= ~GR_READY;
66704+ pax_close_kernel();
66705+
66706+ return 0;
66707+}
66708+
66709+ssize_t
66710+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
66711+{
66712+ struct gr_arg_wrapper uwrap;
66713+ unsigned char *sprole_salt = NULL;
66714+ unsigned char *sprole_sum = NULL;
66715+ int error = 0;
66716+ int error2 = 0;
66717+ size_t req_count = 0;
66718+
66719+ mutex_lock(&gr_dev_mutex);
66720+
66721+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
66722+ error = -EPERM;
66723+ goto out;
66724+ }
66725+
66726+#ifdef CONFIG_COMPAT
66727+ pax_open_kernel();
66728+ if (is_compat_task()) {
66729+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
66730+ copy_gr_arg = &copy_gr_arg_compat;
66731+ copy_acl_object_label = &copy_acl_object_label_compat;
66732+ copy_acl_subject_label = &copy_acl_subject_label_compat;
66733+ copy_acl_role_label = &copy_acl_role_label_compat;
66734+ copy_acl_ip_label = &copy_acl_ip_label_compat;
66735+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
66736+ copy_role_transition = &copy_role_transition_compat;
66737+ copy_sprole_pw = &copy_sprole_pw_compat;
66738+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
66739+ copy_pointer_from_array = &copy_pointer_from_array_compat;
66740+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
66741+ } else {
66742+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
66743+ copy_gr_arg = &copy_gr_arg_normal;
66744+ copy_acl_object_label = &copy_acl_object_label_normal;
66745+ copy_acl_subject_label = &copy_acl_subject_label_normal;
66746+ copy_acl_role_label = &copy_acl_role_label_normal;
66747+ copy_acl_ip_label = &copy_acl_ip_label_normal;
66748+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
66749+ copy_role_transition = &copy_role_transition_normal;
66750+ copy_sprole_pw = &copy_sprole_pw_normal;
66751+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
66752+ copy_pointer_from_array = &copy_pointer_from_array_normal;
66753+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
66754+ }
66755+ pax_close_kernel();
66756+#endif
66757+
66758+ req_count = get_gr_arg_wrapper_size();
66759+
66760+ if (count != req_count) {
66761+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
66762+ error = -EINVAL;
66763+ goto out;
66764+ }
66765+
66766+
66767+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
66768+ gr_auth_expires = 0;
66769+ gr_auth_attempts = 0;
66770+ }
66771+
66772+ error = copy_gr_arg_wrapper(buf, &uwrap);
66773+ if (error)
66774+ goto out;
66775+
66776+ error = copy_gr_arg(uwrap.arg, gr_usermode);
66777+ if (error)
66778+ goto out;
66779+
66780+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
66781+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
66782+ time_after(gr_auth_expires, get_seconds())) {
66783+ error = -EBUSY;
66784+ goto out;
66785+ }
66786+
66787+ /* if non-root trying to do anything other than use a special role,
66788+ do not attempt authentication, do not count towards authentication
66789+ locking
66790+ */
66791+
66792+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
66793+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
66794+ gr_is_global_nonroot(current_uid())) {
66795+ error = -EPERM;
66796+ goto out;
66797+ }
66798+
66799+ /* ensure pw and special role name are null terminated */
66800+
66801+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
66802+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
66803+
66804+ /* Okay.
66805+ * We have our enough of the argument structure..(we have yet
66806+ * to copy_from_user the tables themselves) . Copy the tables
66807+ * only if we need them, i.e. for loading operations. */
66808+
66809+ switch (gr_usermode->mode) {
66810+ case GR_STATUS:
66811+ if (gr_status & GR_READY) {
66812+ error = 1;
66813+ if (!gr_check_secure_terminal(current))
66814+ error = 3;
66815+ } else
66816+ error = 2;
66817+ goto out;
66818+ case GR_SHUTDOWN:
66819+ if ((gr_status & GR_READY)
66820+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
66821+ stop_machine(gr_rbac_disable, NULL, NULL);
66822+ free_variables();
66823+ memset(gr_usermode, 0, sizeof (struct gr_arg));
66824+ memset(gr_system_salt, 0, GR_SALT_LEN);
66825+ memset(gr_system_sum, 0, GR_SHA_LEN);
66826+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
66827+ } else if (gr_status & GR_READY) {
66828+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
66829+ error = -EPERM;
66830+ } else {
66831+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
66832+ error = -EAGAIN;
66833+ }
66834+ break;
66835+ case GR_ENABLE:
66836+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
66837+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
66838+ else {
66839+ if (gr_status & GR_READY)
66840+ error = -EAGAIN;
66841+ else
66842+ error = error2;
66843+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
66844+ }
66845+ break;
66846+ case GR_RELOAD:
66847+ if (!(gr_status & GR_READY)) {
66848+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
66849+ error = -EAGAIN;
66850+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
66851+ stop_machine(gr_rbac_disable, NULL, NULL);
66852+ free_variables();
66853+ error2 = gracl_init(gr_usermode);
66854+ if (!error2)
66855+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
66856+ else {
66857+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
66858+ error = error2;
66859+ }
66860+ } else {
66861+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
66862+ error = -EPERM;
66863+ }
66864+ break;
66865+ case GR_SEGVMOD:
66866+ if (unlikely(!(gr_status & GR_READY))) {
66867+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
66868+ error = -EAGAIN;
66869+ break;
66870+ }
66871+
66872+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
66873+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
66874+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
66875+ struct acl_subject_label *segvacl;
66876+ segvacl =
66877+ lookup_acl_subj_label(gr_usermode->segv_inode,
66878+ gr_usermode->segv_device,
66879+ current->role);
66880+ if (segvacl) {
66881+ segvacl->crashes = 0;
66882+ segvacl->expires = 0;
66883+ }
66884+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
66885+ gr_remove_uid(gr_usermode->segv_uid);
66886+ }
66887+ } else {
66888+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
66889+ error = -EPERM;
66890+ }
66891+ break;
66892+ case GR_SPROLE:
66893+ case GR_SPROLEPAM:
66894+ if (unlikely(!(gr_status & GR_READY))) {
66895+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
66896+ error = -EAGAIN;
66897+ break;
66898+ }
66899+
66900+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
66901+ current->role->expires = 0;
66902+ current->role->auth_attempts = 0;
66903+ }
66904+
66905+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
66906+ time_after(current->role->expires, get_seconds())) {
66907+ error = -EBUSY;
66908+ goto out;
66909+ }
66910+
66911+ if (lookup_special_role_auth
66912+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
66913+ && ((!sprole_salt && !sprole_sum)
66914+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
66915+ char *p = "";
66916+ assign_special_role(gr_usermode->sp_role);
66917+ read_lock(&tasklist_lock);
66918+ if (current->real_parent)
66919+ p = current->real_parent->role->rolename;
66920+ read_unlock(&tasklist_lock);
66921+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
66922+ p, acl_sp_role_value);
66923+ } else {
66924+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
66925+ error = -EPERM;
66926+ if(!(current->role->auth_attempts++))
66927+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
66928+
66929+ goto out;
66930+ }
66931+ break;
66932+ case GR_UNSPROLE:
66933+ if (unlikely(!(gr_status & GR_READY))) {
66934+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
66935+ error = -EAGAIN;
66936+ break;
66937+ }
66938+
66939+ if (current->role->roletype & GR_ROLE_SPECIAL) {
66940+ char *p = "";
66941+ int i = 0;
66942+
66943+ read_lock(&tasklist_lock);
66944+ if (current->real_parent) {
66945+ p = current->real_parent->role->rolename;
66946+ i = current->real_parent->acl_role_id;
66947+ }
66948+ read_unlock(&tasklist_lock);
66949+
66950+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
66951+ gr_set_acls(1);
66952+ } else {
66953+ error = -EPERM;
66954+ goto out;
66955+ }
66956+ break;
66957+ default:
66958+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
66959+ error = -EINVAL;
66960+ break;
66961+ }
66962+
66963+ if (error != -EPERM)
66964+ goto out;
66965+
66966+ if(!(gr_auth_attempts++))
66967+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
66968+
66969+ out:
66970+ mutex_unlock(&gr_dev_mutex);
66971+
66972+ if (!error)
66973+ error = req_count;
66974+
66975+ return error;
66976+}
66977+
66978+/* must be called with
66979+ rcu_read_lock();
66980+ read_lock(&tasklist_lock);
66981+ read_lock(&grsec_exec_file_lock);
66982+*/
66983+int gr_apply_subject_to_task(struct task_struct *task)
66984+{
66985+ struct acl_object_label *obj;
66986+ char *tmpname;
66987+ struct acl_subject_label *tmpsubj;
66988+ struct file *filp;
66989+ struct name_entry *nmatch;
66990+
66991+ filp = task->exec_file;
66992+ if (filp == NULL)
66993+ return 0;
66994+
66995+ /* the following is to apply the correct subject
66996+ on binaries running when the RBAC system
66997+ is enabled, when the binaries have been
66998+ replaced or deleted since their execution
66999+ -----
67000+ when the RBAC system starts, the inode/dev
67001+ from exec_file will be one the RBAC system
67002+ is unaware of. It only knows the inode/dev
67003+ of the present file on disk, or the absence
67004+ of it.
67005+ */
67006+ preempt_disable();
67007+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67008+
67009+ nmatch = lookup_name_entry(tmpname);
67010+ preempt_enable();
67011+ tmpsubj = NULL;
67012+ if (nmatch) {
67013+ if (nmatch->deleted)
67014+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67015+ else
67016+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67017+ if (tmpsubj != NULL)
67018+ task->acl = tmpsubj;
67019+ }
67020+ if (tmpsubj == NULL)
67021+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
67022+ task->role);
67023+ if (task->acl) {
67024+ task->is_writable = 0;
67025+ /* ignore additional mmap checks for processes that are writable
67026+ by the default ACL */
67027+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
67028+ if (unlikely(obj->mode & GR_WRITE))
67029+ task->is_writable = 1;
67030+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67031+ if (unlikely(obj->mode & GR_WRITE))
67032+ task->is_writable = 1;
67033+
67034+ gr_set_proc_res(task);
67035+
67036+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67037+ 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);
67038+#endif
67039+ } else {
67040+ return 1;
67041+ }
67042+
67043+ return 0;
67044+}
67045+
67046+int
67047+gr_set_acls(const int type)
67048+{
67049+ struct task_struct *task, *task2;
67050+ struct acl_role_label *role = current->role;
67051+ __u16 acl_role_id = current->acl_role_id;
67052+ const struct cred *cred;
67053+ int ret;
67054+
67055+ rcu_read_lock();
67056+ read_lock(&tasklist_lock);
67057+ read_lock(&grsec_exec_file_lock);
67058+ do_each_thread(task2, task) {
67059+ /* check to see if we're called from the exit handler,
67060+ if so, only replace ACLs that have inherited the admin
67061+ ACL */
67062+
67063+ if (type && (task->role != role ||
67064+ task->acl_role_id != acl_role_id))
67065+ continue;
67066+
67067+ task->acl_role_id = 0;
67068+ task->acl_sp_role = 0;
67069+
67070+ if (task->exec_file) {
67071+ cred = __task_cred(task);
67072+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
67073+ ret = gr_apply_subject_to_task(task);
67074+ if (ret) {
67075+ read_unlock(&grsec_exec_file_lock);
67076+ read_unlock(&tasklist_lock);
67077+ rcu_read_unlock();
67078+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
67079+ return ret;
67080+ }
67081+ } else {
67082+ // it's a kernel process
67083+ task->role = kernel_role;
67084+ task->acl = kernel_role->root_label;
67085+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
67086+ task->acl->mode &= ~GR_PROCFIND;
67087+#endif
67088+ }
67089+ } while_each_thread(task2, task);
67090+ read_unlock(&grsec_exec_file_lock);
67091+ read_unlock(&tasklist_lock);
67092+ rcu_read_unlock();
67093+
67094+ return 0;
67095+}
67096+
67097+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
67098+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
67099+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
67100+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
67101+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
67102+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
67103+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
67104+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
67105+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
67106+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
67107+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
67108+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
67109+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
67110+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
67111+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
67112+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
67113+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
67114+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
67115+};
67116+
67117+void
67118+gr_learn_resource(const struct task_struct *task,
67119+ const int res, const unsigned long wanted, const int gt)
67120+{
67121+ struct acl_subject_label *acl;
67122+ const struct cred *cred;
67123+
67124+ if (unlikely((gr_status & GR_READY) &&
67125+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
67126+ goto skip_reslog;
67127+
67128+ gr_log_resource(task, res, wanted, gt);
67129+skip_reslog:
67130+
67131+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
67132+ return;
67133+
67134+ acl = task->acl;
67135+
67136+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
67137+ !(acl->resmask & (1U << (unsigned short) res))))
67138+ return;
67139+
67140+ if (wanted >= acl->res[res].rlim_cur) {
67141+ unsigned long res_add;
67142+
67143+ res_add = wanted + res_learn_bumps[res];
67144+
67145+ acl->res[res].rlim_cur = res_add;
67146+
67147+ if (wanted > acl->res[res].rlim_max)
67148+ acl->res[res].rlim_max = res_add;
67149+
67150+ /* only log the subject filename, since resource logging is supported for
67151+ single-subject learning only */
67152+ rcu_read_lock();
67153+ cred = __task_cred(task);
67154+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
67155+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
67156+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
67157+ "", (unsigned long) res, &task->signal->saved_ip);
67158+ rcu_read_unlock();
67159+ }
67160+
67161+ return;
67162+}
67163+EXPORT_SYMBOL(gr_learn_resource);
67164+#endif
67165+
67166+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
67167+void
67168+pax_set_initial_flags(struct linux_binprm *bprm)
67169+{
67170+ struct task_struct *task = current;
67171+ struct acl_subject_label *proc;
67172+ unsigned long flags;
67173+
67174+ if (unlikely(!(gr_status & GR_READY)))
67175+ return;
67176+
67177+ flags = pax_get_flags(task);
67178+
67179+ proc = task->acl;
67180+
67181+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
67182+ flags &= ~MF_PAX_PAGEEXEC;
67183+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
67184+ flags &= ~MF_PAX_SEGMEXEC;
67185+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
67186+ flags &= ~MF_PAX_RANDMMAP;
67187+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
67188+ flags &= ~MF_PAX_EMUTRAMP;
67189+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
67190+ flags &= ~MF_PAX_MPROTECT;
67191+
67192+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
67193+ flags |= MF_PAX_PAGEEXEC;
67194+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
67195+ flags |= MF_PAX_SEGMEXEC;
67196+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
67197+ flags |= MF_PAX_RANDMMAP;
67198+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
67199+ flags |= MF_PAX_EMUTRAMP;
67200+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
67201+ flags |= MF_PAX_MPROTECT;
67202+
67203+ pax_set_flags(task, flags);
67204+
67205+ return;
67206+}
67207+#endif
67208+
67209+int
67210+gr_handle_proc_ptrace(struct task_struct *task)
67211+{
67212+ struct file *filp;
67213+ struct task_struct *tmp = task;
67214+ struct task_struct *curtemp = current;
67215+ __u32 retmode;
67216+
67217+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67218+ if (unlikely(!(gr_status & GR_READY)))
67219+ return 0;
67220+#endif
67221+
67222+ read_lock(&tasklist_lock);
67223+ read_lock(&grsec_exec_file_lock);
67224+ filp = task->exec_file;
67225+
67226+ while (task_pid_nr(tmp) > 0) {
67227+ if (tmp == curtemp)
67228+ break;
67229+ tmp = tmp->real_parent;
67230+ }
67231+
67232+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67233+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
67234+ read_unlock(&grsec_exec_file_lock);
67235+ read_unlock(&tasklist_lock);
67236+ return 1;
67237+ }
67238+
67239+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67240+ if (!(gr_status & GR_READY)) {
67241+ read_unlock(&grsec_exec_file_lock);
67242+ read_unlock(&tasklist_lock);
67243+ return 0;
67244+ }
67245+#endif
67246+
67247+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
67248+ read_unlock(&grsec_exec_file_lock);
67249+ read_unlock(&tasklist_lock);
67250+
67251+ if (retmode & GR_NOPTRACE)
67252+ return 1;
67253+
67254+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
67255+ && (current->acl != task->acl || (current->acl != current->role->root_label
67256+ && task_pid_nr(current) != task_pid_nr(task))))
67257+ return 1;
67258+
67259+ return 0;
67260+}
67261+
67262+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
67263+{
67264+ if (unlikely(!(gr_status & GR_READY)))
67265+ return;
67266+
67267+ if (!(current->role->roletype & GR_ROLE_GOD))
67268+ return;
67269+
67270+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
67271+ p->role->rolename, gr_task_roletype_to_char(p),
67272+ p->acl->filename);
67273+}
67274+
67275+int
67276+gr_handle_ptrace(struct task_struct *task, const long request)
67277+{
67278+ struct task_struct *tmp = task;
67279+ struct task_struct *curtemp = current;
67280+ __u32 retmode;
67281+
67282+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67283+ if (unlikely(!(gr_status & GR_READY)))
67284+ return 0;
67285+#endif
67286+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67287+ read_lock(&tasklist_lock);
67288+ while (task_pid_nr(tmp) > 0) {
67289+ if (tmp == curtemp)
67290+ break;
67291+ tmp = tmp->real_parent;
67292+ }
67293+
67294+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67295+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
67296+ read_unlock(&tasklist_lock);
67297+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67298+ return 1;
67299+ }
67300+ read_unlock(&tasklist_lock);
67301+ }
67302+
67303+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67304+ if (!(gr_status & GR_READY))
67305+ return 0;
67306+#endif
67307+
67308+ read_lock(&grsec_exec_file_lock);
67309+ if (unlikely(!task->exec_file)) {
67310+ read_unlock(&grsec_exec_file_lock);
67311+ return 0;
67312+ }
67313+
67314+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
67315+ read_unlock(&grsec_exec_file_lock);
67316+
67317+ if (retmode & GR_NOPTRACE) {
67318+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67319+ return 1;
67320+ }
67321+
67322+ if (retmode & GR_PTRACERD) {
67323+ switch (request) {
67324+ case PTRACE_SEIZE:
67325+ case PTRACE_POKETEXT:
67326+ case PTRACE_POKEDATA:
67327+ case PTRACE_POKEUSR:
67328+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
67329+ case PTRACE_SETREGS:
67330+ case PTRACE_SETFPREGS:
67331+#endif
67332+#ifdef CONFIG_X86
67333+ case PTRACE_SETFPXREGS:
67334+#endif
67335+#ifdef CONFIG_ALTIVEC
67336+ case PTRACE_SETVRREGS:
67337+#endif
67338+ return 1;
67339+ default:
67340+ return 0;
67341+ }
67342+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
67343+ !(current->role->roletype & GR_ROLE_GOD) &&
67344+ (current->acl != task->acl)) {
67345+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67346+ return 1;
67347+ }
67348+
67349+ return 0;
67350+}
67351+
67352+static int is_writable_mmap(const struct file *filp)
67353+{
67354+ struct task_struct *task = current;
67355+ struct acl_object_label *obj, *obj2;
67356+
67357+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
67358+ !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))) {
67359+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
67360+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
67361+ task->role->root_label);
67362+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
67363+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
67364+ return 1;
67365+ }
67366+ }
67367+ return 0;
67368+}
67369+
67370+int
67371+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
67372+{
67373+ __u32 mode;
67374+
67375+ if (unlikely(!file || !(prot & PROT_EXEC)))
67376+ return 1;
67377+
67378+ if (is_writable_mmap(file))
67379+ return 0;
67380+
67381+ mode =
67382+ gr_search_file(file->f_path.dentry,
67383+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67384+ file->f_path.mnt);
67385+
67386+ if (!gr_tpe_allow(file))
67387+ return 0;
67388+
67389+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67390+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67391+ return 0;
67392+ } else if (unlikely(!(mode & GR_EXEC))) {
67393+ return 0;
67394+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67395+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67396+ return 1;
67397+ }
67398+
67399+ return 1;
67400+}
67401+
67402+int
67403+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
67404+{
67405+ __u32 mode;
67406+
67407+ if (unlikely(!file || !(prot & PROT_EXEC)))
67408+ return 1;
67409+
67410+ if (is_writable_mmap(file))
67411+ return 0;
67412+
67413+ mode =
67414+ gr_search_file(file->f_path.dentry,
67415+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67416+ file->f_path.mnt);
67417+
67418+ if (!gr_tpe_allow(file))
67419+ return 0;
67420+
67421+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67422+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67423+ return 0;
67424+ } else if (unlikely(!(mode & GR_EXEC))) {
67425+ return 0;
67426+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67427+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67428+ return 1;
67429+ }
67430+
67431+ return 1;
67432+}
67433+
67434+void
67435+gr_acl_handle_psacct(struct task_struct *task, const long code)
67436+{
67437+ unsigned long runtime;
67438+ unsigned long cputime;
67439+ unsigned int wday, cday;
67440+ __u8 whr, chr;
67441+ __u8 wmin, cmin;
67442+ __u8 wsec, csec;
67443+ struct timespec timeval;
67444+
67445+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
67446+ !(task->acl->mode & GR_PROCACCT)))
67447+ return;
67448+
67449+ do_posix_clock_monotonic_gettime(&timeval);
67450+ runtime = timeval.tv_sec - task->start_time.tv_sec;
67451+ wday = runtime / (3600 * 24);
67452+ runtime -= wday * (3600 * 24);
67453+ whr = runtime / 3600;
67454+ runtime -= whr * 3600;
67455+ wmin = runtime / 60;
67456+ runtime -= wmin * 60;
67457+ wsec = runtime;
67458+
67459+ cputime = (task->utime + task->stime) / HZ;
67460+ cday = cputime / (3600 * 24);
67461+ cputime -= cday * (3600 * 24);
67462+ chr = cputime / 3600;
67463+ cputime -= chr * 3600;
67464+ cmin = cputime / 60;
67465+ cputime -= cmin * 60;
67466+ csec = cputime;
67467+
67468+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
67469+
67470+ return;
67471+}
67472+
67473+void gr_set_kernel_label(struct task_struct *task)
67474+{
67475+ if (gr_status & GR_READY) {
67476+ task->role = kernel_role;
67477+ task->acl = kernel_role->root_label;
67478+ }
67479+ return;
67480+}
67481+
67482+#ifdef CONFIG_TASKSTATS
67483+int gr_is_taskstats_denied(int pid)
67484+{
67485+ struct task_struct *task;
67486+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67487+ const struct cred *cred;
67488+#endif
67489+ int ret = 0;
67490+
67491+ /* restrict taskstats viewing to un-chrooted root users
67492+ who have the 'view' subject flag if the RBAC system is enabled
67493+ */
67494+
67495+ rcu_read_lock();
67496+ read_lock(&tasklist_lock);
67497+ task = find_task_by_vpid(pid);
67498+ if (task) {
67499+#ifdef CONFIG_GRKERNSEC_CHROOT
67500+ if (proc_is_chrooted(task))
67501+ ret = -EACCES;
67502+#endif
67503+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67504+ cred = __task_cred(task);
67505+#ifdef CONFIG_GRKERNSEC_PROC_USER
67506+ if (gr_is_global_nonroot(cred->uid))
67507+ ret = -EACCES;
67508+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67509+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
67510+ ret = -EACCES;
67511+#endif
67512+#endif
67513+ if (gr_status & GR_READY) {
67514+ if (!(task->acl->mode & GR_VIEW))
67515+ ret = -EACCES;
67516+ }
67517+ } else
67518+ ret = -ENOENT;
67519+
67520+ read_unlock(&tasklist_lock);
67521+ rcu_read_unlock();
67522+
67523+ return ret;
67524+}
67525+#endif
67526+
67527+/* AUXV entries are filled via a descendant of search_binary_handler
67528+ after we've already applied the subject for the target
67529+*/
67530+int gr_acl_enable_at_secure(void)
67531+{
67532+ if (unlikely(!(gr_status & GR_READY)))
67533+ return 0;
67534+
67535+ if (current->acl->mode & GR_ATSECURE)
67536+ return 1;
67537+
67538+ return 0;
67539+}
67540+
67541+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
67542+{
67543+ struct task_struct *task = current;
67544+ struct dentry *dentry = file->f_path.dentry;
67545+ struct vfsmount *mnt = file->f_path.mnt;
67546+ struct acl_object_label *obj, *tmp;
67547+ struct acl_subject_label *subj;
67548+ unsigned int bufsize;
67549+ int is_not_root;
67550+ char *path;
67551+ dev_t dev = __get_dev(dentry);
67552+
67553+ if (unlikely(!(gr_status & GR_READY)))
67554+ return 1;
67555+
67556+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67557+ return 1;
67558+
67559+ /* ignore Eric Biederman */
67560+ if (IS_PRIVATE(dentry->d_inode))
67561+ return 1;
67562+
67563+ subj = task->acl;
67564+ read_lock(&gr_inode_lock);
67565+ do {
67566+ obj = lookup_acl_obj_label(ino, dev, subj);
67567+ if (obj != NULL) {
67568+ read_unlock(&gr_inode_lock);
67569+ return (obj->mode & GR_FIND) ? 1 : 0;
67570+ }
67571+ } while ((subj = subj->parent_subject));
67572+ read_unlock(&gr_inode_lock);
67573+
67574+ /* this is purely an optimization since we're looking for an object
67575+ for the directory we're doing a readdir on
67576+ if it's possible for any globbed object to match the entry we're
67577+ filling into the directory, then the object we find here will be
67578+ an anchor point with attached globbed objects
67579+ */
67580+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
67581+ if (obj->globbed == NULL)
67582+ return (obj->mode & GR_FIND) ? 1 : 0;
67583+
67584+ is_not_root = ((obj->filename[0] == '/') &&
67585+ (obj->filename[1] == '\0')) ? 0 : 1;
67586+ bufsize = PAGE_SIZE - namelen - is_not_root;
67587+
67588+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
67589+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
67590+ return 1;
67591+
67592+ preempt_disable();
67593+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67594+ bufsize);
67595+
67596+ bufsize = strlen(path);
67597+
67598+ /* if base is "/", don't append an additional slash */
67599+ if (is_not_root)
67600+ *(path + bufsize) = '/';
67601+ memcpy(path + bufsize + is_not_root, name, namelen);
67602+ *(path + bufsize + namelen + is_not_root) = '\0';
67603+
67604+ tmp = obj->globbed;
67605+ while (tmp) {
67606+ if (!glob_match(tmp->filename, path)) {
67607+ preempt_enable();
67608+ return (tmp->mode & GR_FIND) ? 1 : 0;
67609+ }
67610+ tmp = tmp->next;
67611+ }
67612+ preempt_enable();
67613+ return (obj->mode & GR_FIND) ? 1 : 0;
67614+}
67615+
67616+void gr_put_exec_file(struct task_struct *task)
67617+{
67618+ struct file *filp;
67619+
67620+ write_lock(&grsec_exec_file_lock);
67621+ filp = task->exec_file;
67622+ task->exec_file = NULL;
67623+ write_unlock(&grsec_exec_file_lock);
67624+
67625+ if (filp)
67626+ fput(filp);
67627+
67628+ return;
67629+}
67630+
67631+
67632+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
67633+EXPORT_SYMBOL(gr_acl_is_enabled);
67634+#endif
67635+EXPORT_SYMBOL(gr_set_kernel_label);
67636+#ifdef CONFIG_SECURITY
67637+EXPORT_SYMBOL(gr_check_user_change);
67638+EXPORT_SYMBOL(gr_check_group_change);
67639+#endif
67640+
67641diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
67642new file mode 100644
67643index 0000000..34fefda
67644--- /dev/null
67645+++ b/grsecurity/gracl_alloc.c
67646@@ -0,0 +1,105 @@
67647+#include <linux/kernel.h>
67648+#include <linux/mm.h>
67649+#include <linux/slab.h>
67650+#include <linux/vmalloc.h>
67651+#include <linux/gracl.h>
67652+#include <linux/grsecurity.h>
67653+
67654+static unsigned long alloc_stack_next = 1;
67655+static unsigned long alloc_stack_size = 1;
67656+static void **alloc_stack;
67657+
67658+static __inline__ int
67659+alloc_pop(void)
67660+{
67661+ if (alloc_stack_next == 1)
67662+ return 0;
67663+
67664+ kfree(alloc_stack[alloc_stack_next - 2]);
67665+
67666+ alloc_stack_next--;
67667+
67668+ return 1;
67669+}
67670+
67671+static __inline__ int
67672+alloc_push(void *buf)
67673+{
67674+ if (alloc_stack_next >= alloc_stack_size)
67675+ return 1;
67676+
67677+ alloc_stack[alloc_stack_next - 1] = buf;
67678+
67679+ alloc_stack_next++;
67680+
67681+ return 0;
67682+}
67683+
67684+void *
67685+acl_alloc(unsigned long len)
67686+{
67687+ void *ret = NULL;
67688+
67689+ if (!len || len > PAGE_SIZE)
67690+ goto out;
67691+
67692+ ret = kmalloc(len, GFP_KERNEL);
67693+
67694+ if (ret) {
67695+ if (alloc_push(ret)) {
67696+ kfree(ret);
67697+ ret = NULL;
67698+ }
67699+ }
67700+
67701+out:
67702+ return ret;
67703+}
67704+
67705+void *
67706+acl_alloc_num(unsigned long num, unsigned long len)
67707+{
67708+ if (!len || (num > (PAGE_SIZE / len)))
67709+ return NULL;
67710+
67711+ return acl_alloc(num * len);
67712+}
67713+
67714+void
67715+acl_free_all(void)
67716+{
67717+ if (gr_acl_is_enabled() || !alloc_stack)
67718+ return;
67719+
67720+ while (alloc_pop()) ;
67721+
67722+ if (alloc_stack) {
67723+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
67724+ kfree(alloc_stack);
67725+ else
67726+ vfree(alloc_stack);
67727+ }
67728+
67729+ alloc_stack = NULL;
67730+ alloc_stack_size = 1;
67731+ alloc_stack_next = 1;
67732+
67733+ return;
67734+}
67735+
67736+int
67737+acl_alloc_stack_init(unsigned long size)
67738+{
67739+ if ((size * sizeof (void *)) <= PAGE_SIZE)
67740+ alloc_stack =
67741+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
67742+ else
67743+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
67744+
67745+ alloc_stack_size = size;
67746+
67747+ if (!alloc_stack)
67748+ return 0;
67749+ else
67750+ return 1;
67751+}
67752diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
67753new file mode 100644
67754index 0000000..bdd51ea
67755--- /dev/null
67756+++ b/grsecurity/gracl_cap.c
67757@@ -0,0 +1,110 @@
67758+#include <linux/kernel.h>
67759+#include <linux/module.h>
67760+#include <linux/sched.h>
67761+#include <linux/gracl.h>
67762+#include <linux/grsecurity.h>
67763+#include <linux/grinternal.h>
67764+
67765+extern const char *captab_log[];
67766+extern int captab_log_entries;
67767+
67768+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
67769+{
67770+ struct acl_subject_label *curracl;
67771+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
67772+ kernel_cap_t cap_audit = __cap_empty_set;
67773+
67774+ if (!gr_acl_is_enabled())
67775+ return 1;
67776+
67777+ curracl = task->acl;
67778+
67779+ cap_drop = curracl->cap_lower;
67780+ cap_mask = curracl->cap_mask;
67781+ cap_audit = curracl->cap_invert_audit;
67782+
67783+ while ((curracl = curracl->parent_subject)) {
67784+ /* if the cap isn't specified in the current computed mask but is specified in the
67785+ current level subject, and is lowered in the current level subject, then add
67786+ it to the set of dropped capabilities
67787+ otherwise, add the current level subject's mask to the current computed mask
67788+ */
67789+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
67790+ cap_raise(cap_mask, cap);
67791+ if (cap_raised(curracl->cap_lower, cap))
67792+ cap_raise(cap_drop, cap);
67793+ if (cap_raised(curracl->cap_invert_audit, cap))
67794+ cap_raise(cap_audit, cap);
67795+ }
67796+ }
67797+
67798+ if (!cap_raised(cap_drop, cap)) {
67799+ if (cap_raised(cap_audit, cap))
67800+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
67801+ return 1;
67802+ }
67803+
67804+ curracl = task->acl;
67805+
67806+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
67807+ && cap_raised(cred->cap_effective, cap)) {
67808+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
67809+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
67810+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
67811+ gr_to_filename(task->exec_file->f_path.dentry,
67812+ task->exec_file->f_path.mnt) : curracl->filename,
67813+ curracl->filename, 0UL,
67814+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
67815+ return 1;
67816+ }
67817+
67818+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
67819+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
67820+
67821+ return 0;
67822+}
67823+
67824+int
67825+gr_acl_is_capable(const int cap)
67826+{
67827+ return gr_task_acl_is_capable(current, current_cred(), cap);
67828+}
67829+
67830+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
67831+{
67832+ struct acl_subject_label *curracl;
67833+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
67834+
67835+ if (!gr_acl_is_enabled())
67836+ return 1;
67837+
67838+ curracl = task->acl;
67839+
67840+ cap_drop = curracl->cap_lower;
67841+ cap_mask = curracl->cap_mask;
67842+
67843+ while ((curracl = curracl->parent_subject)) {
67844+ /* if the cap isn't specified in the current computed mask but is specified in the
67845+ current level subject, and is lowered in the current level subject, then add
67846+ it to the set of dropped capabilities
67847+ otherwise, add the current level subject's mask to the current computed mask
67848+ */
67849+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
67850+ cap_raise(cap_mask, cap);
67851+ if (cap_raised(curracl->cap_lower, cap))
67852+ cap_raise(cap_drop, cap);
67853+ }
67854+ }
67855+
67856+ if (!cap_raised(cap_drop, cap))
67857+ return 1;
67858+
67859+ return 0;
67860+}
67861+
67862+int
67863+gr_acl_is_capable_nolog(const int cap)
67864+{
67865+ return gr_task_acl_is_capable_nolog(current, cap);
67866+}
67867+
67868diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
67869new file mode 100644
67870index 0000000..a43dd06
67871--- /dev/null
67872+++ b/grsecurity/gracl_compat.c
67873@@ -0,0 +1,269 @@
67874+#include <linux/kernel.h>
67875+#include <linux/gracl.h>
67876+#include <linux/compat.h>
67877+#include <linux/gracl_compat.h>
67878+
67879+#include <asm/uaccess.h>
67880+
67881+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
67882+{
67883+ struct gr_arg_wrapper_compat uwrapcompat;
67884+
67885+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
67886+ return -EFAULT;
67887+
67888+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
67889+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
67890+ return -EINVAL;
67891+
67892+ uwrap->arg = compat_ptr(uwrapcompat.arg);
67893+ uwrap->version = uwrapcompat.version;
67894+ uwrap->size = sizeof(struct gr_arg);
67895+
67896+ return 0;
67897+}
67898+
67899+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
67900+{
67901+ struct gr_arg_compat argcompat;
67902+
67903+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
67904+ return -EFAULT;
67905+
67906+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
67907+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
67908+ arg->role_db.num_roles = argcompat.role_db.num_roles;
67909+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
67910+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
67911+ arg->role_db.num_objects = argcompat.role_db.num_objects;
67912+
67913+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
67914+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
67915+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
67916+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
67917+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
67918+ arg->segv_device = argcompat.segv_device;
67919+ arg->segv_inode = argcompat.segv_inode;
67920+ arg->segv_uid = argcompat.segv_uid;
67921+ arg->num_sprole_pws = argcompat.num_sprole_pws;
67922+ arg->mode = argcompat.mode;
67923+
67924+ return 0;
67925+}
67926+
67927+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
67928+{
67929+ struct acl_object_label_compat objcompat;
67930+
67931+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
67932+ return -EFAULT;
67933+
67934+ obj->filename = compat_ptr(objcompat.filename);
67935+ obj->inode = objcompat.inode;
67936+ obj->device = objcompat.device;
67937+ obj->mode = objcompat.mode;
67938+
67939+ obj->nested = compat_ptr(objcompat.nested);
67940+ obj->globbed = compat_ptr(objcompat.globbed);
67941+
67942+ obj->prev = compat_ptr(objcompat.prev);
67943+ obj->next = compat_ptr(objcompat.next);
67944+
67945+ return 0;
67946+}
67947+
67948+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
67949+{
67950+ unsigned int i;
67951+ struct acl_subject_label_compat subjcompat;
67952+
67953+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
67954+ return -EFAULT;
67955+
67956+ subj->filename = compat_ptr(subjcompat.filename);
67957+ subj->inode = subjcompat.inode;
67958+ subj->device = subjcompat.device;
67959+ subj->mode = subjcompat.mode;
67960+ subj->cap_mask = subjcompat.cap_mask;
67961+ subj->cap_lower = subjcompat.cap_lower;
67962+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
67963+
67964+ for (i = 0; i < GR_NLIMITS; i++) {
67965+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
67966+ subj->res[i].rlim_cur = RLIM_INFINITY;
67967+ else
67968+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
67969+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
67970+ subj->res[i].rlim_max = RLIM_INFINITY;
67971+ else
67972+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
67973+ }
67974+ subj->resmask = subjcompat.resmask;
67975+
67976+ subj->user_trans_type = subjcompat.user_trans_type;
67977+ subj->group_trans_type = subjcompat.group_trans_type;
67978+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
67979+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
67980+ subj->user_trans_num = subjcompat.user_trans_num;
67981+ subj->group_trans_num = subjcompat.group_trans_num;
67982+
67983+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
67984+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
67985+ subj->ip_type = subjcompat.ip_type;
67986+ subj->ips = compat_ptr(subjcompat.ips);
67987+ subj->ip_num = subjcompat.ip_num;
67988+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
67989+
67990+ subj->crashes = subjcompat.crashes;
67991+ subj->expires = subjcompat.expires;
67992+
67993+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
67994+ subj->hash = compat_ptr(subjcompat.hash);
67995+ subj->prev = compat_ptr(subjcompat.prev);
67996+ subj->next = compat_ptr(subjcompat.next);
67997+
67998+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
67999+ subj->obj_hash_size = subjcompat.obj_hash_size;
68000+ subj->pax_flags = subjcompat.pax_flags;
68001+
68002+ return 0;
68003+}
68004+
68005+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
68006+{
68007+ struct acl_role_label_compat rolecompat;
68008+
68009+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
68010+ return -EFAULT;
68011+
68012+ role->rolename = compat_ptr(rolecompat.rolename);
68013+ role->uidgid = rolecompat.uidgid;
68014+ role->roletype = rolecompat.roletype;
68015+
68016+ role->auth_attempts = rolecompat.auth_attempts;
68017+ role->expires = rolecompat.expires;
68018+
68019+ role->root_label = compat_ptr(rolecompat.root_label);
68020+ role->hash = compat_ptr(rolecompat.hash);
68021+
68022+ role->prev = compat_ptr(rolecompat.prev);
68023+ role->next = compat_ptr(rolecompat.next);
68024+
68025+ role->transitions = compat_ptr(rolecompat.transitions);
68026+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
68027+ role->domain_children = compat_ptr(rolecompat.domain_children);
68028+ role->domain_child_num = rolecompat.domain_child_num;
68029+
68030+ role->umask = rolecompat.umask;
68031+
68032+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
68033+ role->subj_hash_size = rolecompat.subj_hash_size;
68034+
68035+ return 0;
68036+}
68037+
68038+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
68039+{
68040+ struct role_allowed_ip_compat roleip_compat;
68041+
68042+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
68043+ return -EFAULT;
68044+
68045+ roleip->addr = roleip_compat.addr;
68046+ roleip->netmask = roleip_compat.netmask;
68047+
68048+ roleip->prev = compat_ptr(roleip_compat.prev);
68049+ roleip->next = compat_ptr(roleip_compat.next);
68050+
68051+ return 0;
68052+}
68053+
68054+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
68055+{
68056+ struct role_transition_compat trans_compat;
68057+
68058+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
68059+ return -EFAULT;
68060+
68061+ trans->rolename = compat_ptr(trans_compat.rolename);
68062+
68063+ trans->prev = compat_ptr(trans_compat.prev);
68064+ trans->next = compat_ptr(trans_compat.next);
68065+
68066+ return 0;
68067+
68068+}
68069+
68070+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
68071+{
68072+ struct gr_hash_struct_compat hash_compat;
68073+
68074+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
68075+ return -EFAULT;
68076+
68077+ hash->table = compat_ptr(hash_compat.table);
68078+ hash->nametable = compat_ptr(hash_compat.nametable);
68079+ hash->first = compat_ptr(hash_compat.first);
68080+
68081+ hash->table_size = hash_compat.table_size;
68082+ hash->used_size = hash_compat.used_size;
68083+
68084+ hash->type = hash_compat.type;
68085+
68086+ return 0;
68087+}
68088+
68089+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
68090+{
68091+ compat_uptr_t ptrcompat;
68092+
68093+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
68094+ return -EFAULT;
68095+
68096+ *(void **)ptr = compat_ptr(ptrcompat);
68097+
68098+ return 0;
68099+}
68100+
68101+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
68102+{
68103+ struct acl_ip_label_compat ip_compat;
68104+
68105+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
68106+ return -EFAULT;
68107+
68108+ ip->iface = compat_ptr(ip_compat.iface);
68109+ ip->addr = ip_compat.addr;
68110+ ip->netmask = ip_compat.netmask;
68111+ ip->low = ip_compat.low;
68112+ ip->high = ip_compat.high;
68113+ ip->mode = ip_compat.mode;
68114+ ip->type = ip_compat.type;
68115+
68116+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
68117+
68118+ ip->prev = compat_ptr(ip_compat.prev);
68119+ ip->next = compat_ptr(ip_compat.next);
68120+
68121+ return 0;
68122+}
68123+
68124+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
68125+{
68126+ struct sprole_pw_compat pw_compat;
68127+
68128+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
68129+ return -EFAULT;
68130+
68131+ pw->rolename = compat_ptr(pw_compat.rolename);
68132+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
68133+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
68134+
68135+ return 0;
68136+}
68137+
68138+size_t get_gr_arg_wrapper_size_compat(void)
68139+{
68140+ return sizeof(struct gr_arg_wrapper_compat);
68141+}
68142+
68143diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
68144new file mode 100644
68145index 0000000..a340c17
68146--- /dev/null
68147+++ b/grsecurity/gracl_fs.c
68148@@ -0,0 +1,431 @@
68149+#include <linux/kernel.h>
68150+#include <linux/sched.h>
68151+#include <linux/types.h>
68152+#include <linux/fs.h>
68153+#include <linux/file.h>
68154+#include <linux/stat.h>
68155+#include <linux/grsecurity.h>
68156+#include <linux/grinternal.h>
68157+#include <linux/gracl.h>
68158+
68159+umode_t
68160+gr_acl_umask(void)
68161+{
68162+ if (unlikely(!gr_acl_is_enabled()))
68163+ return 0;
68164+
68165+ return current->role->umask;
68166+}
68167+
68168+__u32
68169+gr_acl_handle_hidden_file(const struct dentry * dentry,
68170+ const struct vfsmount * mnt)
68171+{
68172+ __u32 mode;
68173+
68174+ if (unlikely(!dentry->d_inode))
68175+ return GR_FIND;
68176+
68177+ mode =
68178+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
68179+
68180+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
68181+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68182+ return mode;
68183+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
68184+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68185+ return 0;
68186+ } else if (unlikely(!(mode & GR_FIND)))
68187+ return 0;
68188+
68189+ return GR_FIND;
68190+}
68191+
68192+__u32
68193+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68194+ int acc_mode)
68195+{
68196+ __u32 reqmode = GR_FIND;
68197+ __u32 mode;
68198+
68199+ if (unlikely(!dentry->d_inode))
68200+ return reqmode;
68201+
68202+ if (acc_mode & MAY_APPEND)
68203+ reqmode |= GR_APPEND;
68204+ else if (acc_mode & MAY_WRITE)
68205+ reqmode |= GR_WRITE;
68206+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
68207+ reqmode |= GR_READ;
68208+
68209+ mode =
68210+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68211+ mnt);
68212+
68213+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68214+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68215+ reqmode & GR_READ ? " reading" : "",
68216+ reqmode & GR_WRITE ? " writing" : reqmode &
68217+ GR_APPEND ? " appending" : "");
68218+ return reqmode;
68219+ } else
68220+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68221+ {
68222+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68223+ reqmode & GR_READ ? " reading" : "",
68224+ reqmode & GR_WRITE ? " writing" : reqmode &
68225+ GR_APPEND ? " appending" : "");
68226+ return 0;
68227+ } else if (unlikely((mode & reqmode) != reqmode))
68228+ return 0;
68229+
68230+ return reqmode;
68231+}
68232+
68233+__u32
68234+gr_acl_handle_creat(const struct dentry * dentry,
68235+ const struct dentry * p_dentry,
68236+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
68237+ const int imode)
68238+{
68239+ __u32 reqmode = GR_WRITE | GR_CREATE;
68240+ __u32 mode;
68241+
68242+ if (acc_mode & MAY_APPEND)
68243+ reqmode |= GR_APPEND;
68244+ // if a directory was required or the directory already exists, then
68245+ // don't count this open as a read
68246+ if ((acc_mode & MAY_READ) &&
68247+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
68248+ reqmode |= GR_READ;
68249+ if ((open_flags & O_CREAT) &&
68250+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68251+ reqmode |= GR_SETID;
68252+
68253+ mode =
68254+ gr_check_create(dentry, p_dentry, p_mnt,
68255+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68256+
68257+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68258+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68259+ reqmode & GR_READ ? " reading" : "",
68260+ reqmode & GR_WRITE ? " writing" : reqmode &
68261+ GR_APPEND ? " appending" : "");
68262+ return reqmode;
68263+ } else
68264+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68265+ {
68266+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68267+ reqmode & GR_READ ? " reading" : "",
68268+ reqmode & GR_WRITE ? " writing" : reqmode &
68269+ GR_APPEND ? " appending" : "");
68270+ return 0;
68271+ } else if (unlikely((mode & reqmode) != reqmode))
68272+ return 0;
68273+
68274+ return reqmode;
68275+}
68276+
68277+__u32
68278+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
68279+ const int fmode)
68280+{
68281+ __u32 mode, reqmode = GR_FIND;
68282+
68283+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
68284+ reqmode |= GR_EXEC;
68285+ if (fmode & S_IWOTH)
68286+ reqmode |= GR_WRITE;
68287+ if (fmode & S_IROTH)
68288+ reqmode |= GR_READ;
68289+
68290+ mode =
68291+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68292+ mnt);
68293+
68294+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68295+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68296+ reqmode & GR_READ ? " reading" : "",
68297+ reqmode & GR_WRITE ? " writing" : "",
68298+ reqmode & GR_EXEC ? " executing" : "");
68299+ return reqmode;
68300+ } else
68301+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68302+ {
68303+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68304+ reqmode & GR_READ ? " reading" : "",
68305+ reqmode & GR_WRITE ? " writing" : "",
68306+ reqmode & GR_EXEC ? " executing" : "");
68307+ return 0;
68308+ } else if (unlikely((mode & reqmode) != reqmode))
68309+ return 0;
68310+
68311+ return reqmode;
68312+}
68313+
68314+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
68315+{
68316+ __u32 mode;
68317+
68318+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
68319+
68320+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68321+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
68322+ return mode;
68323+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68324+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
68325+ return 0;
68326+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
68327+ return 0;
68328+
68329+ return (reqmode);
68330+}
68331+
68332+__u32
68333+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68334+{
68335+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
68336+}
68337+
68338+__u32
68339+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
68340+{
68341+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
68342+}
68343+
68344+__u32
68345+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
68346+{
68347+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
68348+}
68349+
68350+__u32
68351+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
68352+{
68353+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
68354+}
68355+
68356+__u32
68357+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
68358+ umode_t *modeptr)
68359+{
68360+ umode_t mode;
68361+
68362+ *modeptr &= ~gr_acl_umask();
68363+ mode = *modeptr;
68364+
68365+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
68366+ return 1;
68367+
68368+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
68369+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
68370+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
68371+ GR_CHMOD_ACL_MSG);
68372+ } else {
68373+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
68374+ }
68375+}
68376+
68377+__u32
68378+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
68379+{
68380+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
68381+}
68382+
68383+__u32
68384+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
68385+{
68386+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
68387+}
68388+
68389+__u32
68390+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
68391+{
68392+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
68393+}
68394+
68395+__u32
68396+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
68397+{
68398+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
68399+ GR_UNIXCONNECT_ACL_MSG);
68400+}
68401+
68402+/* hardlinks require at minimum create and link permission,
68403+ any additional privilege required is based on the
68404+ privilege of the file being linked to
68405+*/
68406+__u32
68407+gr_acl_handle_link(const struct dentry * new_dentry,
68408+ const struct dentry * parent_dentry,
68409+ const struct vfsmount * parent_mnt,
68410+ const struct dentry * old_dentry,
68411+ const struct vfsmount * old_mnt, const struct filename *to)
68412+{
68413+ __u32 mode;
68414+ __u32 needmode = GR_CREATE | GR_LINK;
68415+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
68416+
68417+ mode =
68418+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
68419+ old_mnt);
68420+
68421+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
68422+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68423+ return mode;
68424+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68425+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68426+ return 0;
68427+ } else if (unlikely((mode & needmode) != needmode))
68428+ return 0;
68429+
68430+ return 1;
68431+}
68432+
68433+__u32
68434+gr_acl_handle_symlink(const struct dentry * new_dentry,
68435+ const struct dentry * parent_dentry,
68436+ const struct vfsmount * parent_mnt, const struct filename *from)
68437+{
68438+ __u32 needmode = GR_WRITE | GR_CREATE;
68439+ __u32 mode;
68440+
68441+ mode =
68442+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
68443+ GR_CREATE | GR_AUDIT_CREATE |
68444+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
68445+
68446+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
68447+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68448+ return mode;
68449+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68450+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68451+ return 0;
68452+ } else if (unlikely((mode & needmode) != needmode))
68453+ return 0;
68454+
68455+ return (GR_WRITE | GR_CREATE);
68456+}
68457+
68458+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)
68459+{
68460+ __u32 mode;
68461+
68462+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68463+
68464+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68465+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
68466+ return mode;
68467+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68468+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
68469+ return 0;
68470+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
68471+ return 0;
68472+
68473+ return (reqmode);
68474+}
68475+
68476+__u32
68477+gr_acl_handle_mknod(const struct dentry * new_dentry,
68478+ const struct dentry * parent_dentry,
68479+ const struct vfsmount * parent_mnt,
68480+ const int mode)
68481+{
68482+ __u32 reqmode = GR_WRITE | GR_CREATE;
68483+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68484+ reqmode |= GR_SETID;
68485+
68486+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68487+ reqmode, GR_MKNOD_ACL_MSG);
68488+}
68489+
68490+__u32
68491+gr_acl_handle_mkdir(const struct dentry *new_dentry,
68492+ const struct dentry *parent_dentry,
68493+ const struct vfsmount *parent_mnt)
68494+{
68495+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68496+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
68497+}
68498+
68499+#define RENAME_CHECK_SUCCESS(old, new) \
68500+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
68501+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
68502+
68503+int
68504+gr_acl_handle_rename(struct dentry *new_dentry,
68505+ struct dentry *parent_dentry,
68506+ const struct vfsmount *parent_mnt,
68507+ struct dentry *old_dentry,
68508+ struct inode *old_parent_inode,
68509+ struct vfsmount *old_mnt, const struct filename *newname)
68510+{
68511+ __u32 comp1, comp2;
68512+ int error = 0;
68513+
68514+ if (unlikely(!gr_acl_is_enabled()))
68515+ return 0;
68516+
68517+ if (!new_dentry->d_inode) {
68518+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
68519+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
68520+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
68521+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
68522+ GR_DELETE | GR_AUDIT_DELETE |
68523+ GR_AUDIT_READ | GR_AUDIT_WRITE |
68524+ GR_SUPPRESS, old_mnt);
68525+ } else {
68526+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
68527+ GR_CREATE | GR_DELETE |
68528+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
68529+ GR_AUDIT_READ | GR_AUDIT_WRITE |
68530+ GR_SUPPRESS, parent_mnt);
68531+ comp2 =
68532+ gr_search_file(old_dentry,
68533+ GR_READ | GR_WRITE | GR_AUDIT_READ |
68534+ GR_DELETE | GR_AUDIT_DELETE |
68535+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
68536+ }
68537+
68538+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
68539+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
68540+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
68541+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
68542+ && !(comp2 & GR_SUPPRESS)) {
68543+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
68544+ error = -EACCES;
68545+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
68546+ error = -EACCES;
68547+
68548+ return error;
68549+}
68550+
68551+void
68552+gr_acl_handle_exit(void)
68553+{
68554+ u16 id;
68555+ char *rolename;
68556+
68557+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
68558+ !(current->role->roletype & GR_ROLE_PERSIST))) {
68559+ id = current->acl_role_id;
68560+ rolename = current->role->rolename;
68561+ gr_set_acls(1);
68562+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
68563+ }
68564+
68565+ gr_put_exec_file(current);
68566+ return;
68567+}
68568+
68569+int
68570+gr_acl_handle_procpidmem(const struct task_struct *task)
68571+{
68572+ if (unlikely(!gr_acl_is_enabled()))
68573+ return 0;
68574+
68575+ if (task != current && task->acl->mode & GR_PROTPROCFD)
68576+ return -EACCES;
68577+
68578+ return 0;
68579+}
68580diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
68581new file mode 100644
68582index 0000000..8132048
68583--- /dev/null
68584+++ b/grsecurity/gracl_ip.c
68585@@ -0,0 +1,387 @@
68586+#include <linux/kernel.h>
68587+#include <asm/uaccess.h>
68588+#include <asm/errno.h>
68589+#include <net/sock.h>
68590+#include <linux/file.h>
68591+#include <linux/fs.h>
68592+#include <linux/net.h>
68593+#include <linux/in.h>
68594+#include <linux/skbuff.h>
68595+#include <linux/ip.h>
68596+#include <linux/udp.h>
68597+#include <linux/types.h>
68598+#include <linux/sched.h>
68599+#include <linux/netdevice.h>
68600+#include <linux/inetdevice.h>
68601+#include <linux/gracl.h>
68602+#include <linux/grsecurity.h>
68603+#include <linux/grinternal.h>
68604+
68605+#define GR_BIND 0x01
68606+#define GR_CONNECT 0x02
68607+#define GR_INVERT 0x04
68608+#define GR_BINDOVERRIDE 0x08
68609+#define GR_CONNECTOVERRIDE 0x10
68610+#define GR_SOCK_FAMILY 0x20
68611+
68612+static const char * gr_protocols[IPPROTO_MAX] = {
68613+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
68614+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
68615+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
68616+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
68617+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
68618+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
68619+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
68620+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
68621+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
68622+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
68623+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
68624+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
68625+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
68626+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
68627+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
68628+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
68629+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
68630+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
68631+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
68632+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
68633+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
68634+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
68635+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
68636+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
68637+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
68638+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
68639+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
68640+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
68641+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
68642+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
68643+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
68644+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
68645+ };
68646+
68647+static const char * gr_socktypes[SOCK_MAX] = {
68648+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
68649+ "unknown:7", "unknown:8", "unknown:9", "packet"
68650+ };
68651+
68652+static const char * gr_sockfamilies[AF_MAX+1] = {
68653+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
68654+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
68655+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
68656+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
68657+ };
68658+
68659+const char *
68660+gr_proto_to_name(unsigned char proto)
68661+{
68662+ return gr_protocols[proto];
68663+}
68664+
68665+const char *
68666+gr_socktype_to_name(unsigned char type)
68667+{
68668+ return gr_socktypes[type];
68669+}
68670+
68671+const char *
68672+gr_sockfamily_to_name(unsigned char family)
68673+{
68674+ return gr_sockfamilies[family];
68675+}
68676+
68677+int
68678+gr_search_socket(const int domain, const int type, const int protocol)
68679+{
68680+ struct acl_subject_label *curr;
68681+ const struct cred *cred = current_cred();
68682+
68683+ if (unlikely(!gr_acl_is_enabled()))
68684+ goto exit;
68685+
68686+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
68687+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
68688+ goto exit; // let the kernel handle it
68689+
68690+ curr = current->acl;
68691+
68692+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
68693+ /* the family is allowed, if this is PF_INET allow it only if
68694+ the extra sock type/protocol checks pass */
68695+ if (domain == PF_INET)
68696+ goto inet_check;
68697+ goto exit;
68698+ } else {
68699+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
68700+ __u32 fakeip = 0;
68701+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68702+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68703+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68704+ gr_to_filename(current->exec_file->f_path.dentry,
68705+ current->exec_file->f_path.mnt) :
68706+ curr->filename, curr->filename,
68707+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
68708+ &current->signal->saved_ip);
68709+ goto exit;
68710+ }
68711+ goto exit_fail;
68712+ }
68713+
68714+inet_check:
68715+ /* the rest of this checking is for IPv4 only */
68716+ if (!curr->ips)
68717+ goto exit;
68718+
68719+ if ((curr->ip_type & (1U << type)) &&
68720+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
68721+ goto exit;
68722+
68723+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
68724+ /* we don't place acls on raw sockets , and sometimes
68725+ dgram/ip sockets are opened for ioctl and not
68726+ bind/connect, so we'll fake a bind learn log */
68727+ if (type == SOCK_RAW || type == SOCK_PACKET) {
68728+ __u32 fakeip = 0;
68729+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68730+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68731+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68732+ gr_to_filename(current->exec_file->f_path.dentry,
68733+ current->exec_file->f_path.mnt) :
68734+ curr->filename, curr->filename,
68735+ &fakeip, 0, type,
68736+ protocol, GR_CONNECT, &current->signal->saved_ip);
68737+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
68738+ __u32 fakeip = 0;
68739+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68740+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68741+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68742+ gr_to_filename(current->exec_file->f_path.dentry,
68743+ current->exec_file->f_path.mnt) :
68744+ curr->filename, curr->filename,
68745+ &fakeip, 0, type,
68746+ protocol, GR_BIND, &current->signal->saved_ip);
68747+ }
68748+ /* we'll log when they use connect or bind */
68749+ goto exit;
68750+ }
68751+
68752+exit_fail:
68753+ if (domain == PF_INET)
68754+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
68755+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
68756+ else
68757+#ifndef CONFIG_IPV6
68758+ if (domain != PF_INET6)
68759+#endif
68760+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
68761+ gr_socktype_to_name(type), protocol);
68762+
68763+ return 0;
68764+exit:
68765+ return 1;
68766+}
68767+
68768+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)
68769+{
68770+ if ((ip->mode & mode) &&
68771+ (ip_port >= ip->low) &&
68772+ (ip_port <= ip->high) &&
68773+ ((ntohl(ip_addr) & our_netmask) ==
68774+ (ntohl(our_addr) & our_netmask))
68775+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
68776+ && (ip->type & (1U << type))) {
68777+ if (ip->mode & GR_INVERT)
68778+ return 2; // specifically denied
68779+ else
68780+ return 1; // allowed
68781+ }
68782+
68783+ return 0; // not specifically allowed, may continue parsing
68784+}
68785+
68786+static int
68787+gr_search_connectbind(const int full_mode, struct sock *sk,
68788+ struct sockaddr_in *addr, const int type)
68789+{
68790+ char iface[IFNAMSIZ] = {0};
68791+ struct acl_subject_label *curr;
68792+ struct acl_ip_label *ip;
68793+ struct inet_sock *isk;
68794+ struct net_device *dev;
68795+ struct in_device *idev;
68796+ unsigned long i;
68797+ int ret;
68798+ int mode = full_mode & (GR_BIND | GR_CONNECT);
68799+ __u32 ip_addr = 0;
68800+ __u32 our_addr;
68801+ __u32 our_netmask;
68802+ char *p;
68803+ __u16 ip_port = 0;
68804+ const struct cred *cred = current_cred();
68805+
68806+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
68807+ return 0;
68808+
68809+ curr = current->acl;
68810+ isk = inet_sk(sk);
68811+
68812+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
68813+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
68814+ addr->sin_addr.s_addr = curr->inaddr_any_override;
68815+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
68816+ struct sockaddr_in saddr;
68817+ int err;
68818+
68819+ saddr.sin_family = AF_INET;
68820+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
68821+ saddr.sin_port = isk->inet_sport;
68822+
68823+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
68824+ if (err)
68825+ return err;
68826+
68827+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
68828+ if (err)
68829+ return err;
68830+ }
68831+
68832+ if (!curr->ips)
68833+ return 0;
68834+
68835+ ip_addr = addr->sin_addr.s_addr;
68836+ ip_port = ntohs(addr->sin_port);
68837+
68838+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
68839+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68840+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68841+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68842+ gr_to_filename(current->exec_file->f_path.dentry,
68843+ current->exec_file->f_path.mnt) :
68844+ curr->filename, curr->filename,
68845+ &ip_addr, ip_port, type,
68846+ sk->sk_protocol, mode, &current->signal->saved_ip);
68847+ return 0;
68848+ }
68849+
68850+ for (i = 0; i < curr->ip_num; i++) {
68851+ ip = *(curr->ips + i);
68852+ if (ip->iface != NULL) {
68853+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
68854+ p = strchr(iface, ':');
68855+ if (p != NULL)
68856+ *p = '\0';
68857+ dev = dev_get_by_name(sock_net(sk), iface);
68858+ if (dev == NULL)
68859+ continue;
68860+ idev = in_dev_get(dev);
68861+ if (idev == NULL) {
68862+ dev_put(dev);
68863+ continue;
68864+ }
68865+ rcu_read_lock();
68866+ for_ifa(idev) {
68867+ if (!strcmp(ip->iface, ifa->ifa_label)) {
68868+ our_addr = ifa->ifa_address;
68869+ our_netmask = 0xffffffff;
68870+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
68871+ if (ret == 1) {
68872+ rcu_read_unlock();
68873+ in_dev_put(idev);
68874+ dev_put(dev);
68875+ return 0;
68876+ } else if (ret == 2) {
68877+ rcu_read_unlock();
68878+ in_dev_put(idev);
68879+ dev_put(dev);
68880+ goto denied;
68881+ }
68882+ }
68883+ } endfor_ifa(idev);
68884+ rcu_read_unlock();
68885+ in_dev_put(idev);
68886+ dev_put(dev);
68887+ } else {
68888+ our_addr = ip->addr;
68889+ our_netmask = ip->netmask;
68890+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
68891+ if (ret == 1)
68892+ return 0;
68893+ else if (ret == 2)
68894+ goto denied;
68895+ }
68896+ }
68897+
68898+denied:
68899+ if (mode == GR_BIND)
68900+ 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));
68901+ else if (mode == GR_CONNECT)
68902+ 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));
68903+
68904+ return -EACCES;
68905+}
68906+
68907+int
68908+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
68909+{
68910+ /* always allow disconnection of dgram sockets with connect */
68911+ if (addr->sin_family == AF_UNSPEC)
68912+ return 0;
68913+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
68914+}
68915+
68916+int
68917+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
68918+{
68919+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
68920+}
68921+
68922+int gr_search_listen(struct socket *sock)
68923+{
68924+ struct sock *sk = sock->sk;
68925+ struct sockaddr_in addr;
68926+
68927+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
68928+ addr.sin_port = inet_sk(sk)->inet_sport;
68929+
68930+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
68931+}
68932+
68933+int gr_search_accept(struct socket *sock)
68934+{
68935+ struct sock *sk = sock->sk;
68936+ struct sockaddr_in addr;
68937+
68938+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
68939+ addr.sin_port = inet_sk(sk)->inet_sport;
68940+
68941+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
68942+}
68943+
68944+int
68945+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
68946+{
68947+ if (addr)
68948+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
68949+ else {
68950+ struct sockaddr_in sin;
68951+ const struct inet_sock *inet = inet_sk(sk);
68952+
68953+ sin.sin_addr.s_addr = inet->inet_daddr;
68954+ sin.sin_port = inet->inet_dport;
68955+
68956+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
68957+ }
68958+}
68959+
68960+int
68961+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
68962+{
68963+ struct sockaddr_in sin;
68964+
68965+ if (unlikely(skb->len < sizeof (struct udphdr)))
68966+ return 0; // skip this packet
68967+
68968+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
68969+ sin.sin_port = udp_hdr(skb)->source;
68970+
68971+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
68972+}
68973diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
68974new file mode 100644
68975index 0000000..25f54ef
68976--- /dev/null
68977+++ b/grsecurity/gracl_learn.c
68978@@ -0,0 +1,207 @@
68979+#include <linux/kernel.h>
68980+#include <linux/mm.h>
68981+#include <linux/sched.h>
68982+#include <linux/poll.h>
68983+#include <linux/string.h>
68984+#include <linux/file.h>
68985+#include <linux/types.h>
68986+#include <linux/vmalloc.h>
68987+#include <linux/grinternal.h>
68988+
68989+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
68990+ size_t count, loff_t *ppos);
68991+extern int gr_acl_is_enabled(void);
68992+
68993+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
68994+static int gr_learn_attached;
68995+
68996+/* use a 512k buffer */
68997+#define LEARN_BUFFER_SIZE (512 * 1024)
68998+
68999+static DEFINE_SPINLOCK(gr_learn_lock);
69000+static DEFINE_MUTEX(gr_learn_user_mutex);
69001+
69002+/* we need to maintain two buffers, so that the kernel context of grlearn
69003+ uses a semaphore around the userspace copying, and the other kernel contexts
69004+ use a spinlock when copying into the buffer, since they cannot sleep
69005+*/
69006+static char *learn_buffer;
69007+static char *learn_buffer_user;
69008+static int learn_buffer_len;
69009+static int learn_buffer_user_len;
69010+
69011+static ssize_t
69012+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
69013+{
69014+ DECLARE_WAITQUEUE(wait, current);
69015+ ssize_t retval = 0;
69016+
69017+ add_wait_queue(&learn_wait, &wait);
69018+ set_current_state(TASK_INTERRUPTIBLE);
69019+ do {
69020+ mutex_lock(&gr_learn_user_mutex);
69021+ spin_lock(&gr_learn_lock);
69022+ if (learn_buffer_len)
69023+ break;
69024+ spin_unlock(&gr_learn_lock);
69025+ mutex_unlock(&gr_learn_user_mutex);
69026+ if (file->f_flags & O_NONBLOCK) {
69027+ retval = -EAGAIN;
69028+ goto out;
69029+ }
69030+ if (signal_pending(current)) {
69031+ retval = -ERESTARTSYS;
69032+ goto out;
69033+ }
69034+
69035+ schedule();
69036+ } while (1);
69037+
69038+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
69039+ learn_buffer_user_len = learn_buffer_len;
69040+ retval = learn_buffer_len;
69041+ learn_buffer_len = 0;
69042+
69043+ spin_unlock(&gr_learn_lock);
69044+
69045+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
69046+ retval = -EFAULT;
69047+
69048+ mutex_unlock(&gr_learn_user_mutex);
69049+out:
69050+ set_current_state(TASK_RUNNING);
69051+ remove_wait_queue(&learn_wait, &wait);
69052+ return retval;
69053+}
69054+
69055+static unsigned int
69056+poll_learn(struct file * file, poll_table * wait)
69057+{
69058+ poll_wait(file, &learn_wait, wait);
69059+
69060+ if (learn_buffer_len)
69061+ return (POLLIN | POLLRDNORM);
69062+
69063+ return 0;
69064+}
69065+
69066+void
69067+gr_clear_learn_entries(void)
69068+{
69069+ char *tmp;
69070+
69071+ mutex_lock(&gr_learn_user_mutex);
69072+ spin_lock(&gr_learn_lock);
69073+ tmp = learn_buffer;
69074+ learn_buffer = NULL;
69075+ spin_unlock(&gr_learn_lock);
69076+ if (tmp)
69077+ vfree(tmp);
69078+ if (learn_buffer_user != NULL) {
69079+ vfree(learn_buffer_user);
69080+ learn_buffer_user = NULL;
69081+ }
69082+ learn_buffer_len = 0;
69083+ mutex_unlock(&gr_learn_user_mutex);
69084+
69085+ return;
69086+}
69087+
69088+void
69089+gr_add_learn_entry(const char *fmt, ...)
69090+{
69091+ va_list args;
69092+ unsigned int len;
69093+
69094+ if (!gr_learn_attached)
69095+ return;
69096+
69097+ spin_lock(&gr_learn_lock);
69098+
69099+ /* leave a gap at the end so we know when it's "full" but don't have to
69100+ compute the exact length of the string we're trying to append
69101+ */
69102+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
69103+ spin_unlock(&gr_learn_lock);
69104+ wake_up_interruptible(&learn_wait);
69105+ return;
69106+ }
69107+ if (learn_buffer == NULL) {
69108+ spin_unlock(&gr_learn_lock);
69109+ return;
69110+ }
69111+
69112+ va_start(args, fmt);
69113+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
69114+ va_end(args);
69115+
69116+ learn_buffer_len += len + 1;
69117+
69118+ spin_unlock(&gr_learn_lock);
69119+ wake_up_interruptible(&learn_wait);
69120+
69121+ return;
69122+}
69123+
69124+static int
69125+open_learn(struct inode *inode, struct file *file)
69126+{
69127+ if (file->f_mode & FMODE_READ && gr_learn_attached)
69128+ return -EBUSY;
69129+ if (file->f_mode & FMODE_READ) {
69130+ int retval = 0;
69131+ mutex_lock(&gr_learn_user_mutex);
69132+ if (learn_buffer == NULL)
69133+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
69134+ if (learn_buffer_user == NULL)
69135+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
69136+ if (learn_buffer == NULL) {
69137+ retval = -ENOMEM;
69138+ goto out_error;
69139+ }
69140+ if (learn_buffer_user == NULL) {
69141+ retval = -ENOMEM;
69142+ goto out_error;
69143+ }
69144+ learn_buffer_len = 0;
69145+ learn_buffer_user_len = 0;
69146+ gr_learn_attached = 1;
69147+out_error:
69148+ mutex_unlock(&gr_learn_user_mutex);
69149+ return retval;
69150+ }
69151+ return 0;
69152+}
69153+
69154+static int
69155+close_learn(struct inode *inode, struct file *file)
69156+{
69157+ if (file->f_mode & FMODE_READ) {
69158+ char *tmp = NULL;
69159+ mutex_lock(&gr_learn_user_mutex);
69160+ spin_lock(&gr_learn_lock);
69161+ tmp = learn_buffer;
69162+ learn_buffer = NULL;
69163+ spin_unlock(&gr_learn_lock);
69164+ if (tmp)
69165+ vfree(tmp);
69166+ if (learn_buffer_user != NULL) {
69167+ vfree(learn_buffer_user);
69168+ learn_buffer_user = NULL;
69169+ }
69170+ learn_buffer_len = 0;
69171+ learn_buffer_user_len = 0;
69172+ gr_learn_attached = 0;
69173+ mutex_unlock(&gr_learn_user_mutex);
69174+ }
69175+
69176+ return 0;
69177+}
69178+
69179+const struct file_operations grsec_fops = {
69180+ .read = read_learn,
69181+ .write = write_grsec_handler,
69182+ .open = open_learn,
69183+ .release = close_learn,
69184+ .poll = poll_learn,
69185+};
69186diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
69187new file mode 100644
69188index 0000000..39645c9
69189--- /dev/null
69190+++ b/grsecurity/gracl_res.c
69191@@ -0,0 +1,68 @@
69192+#include <linux/kernel.h>
69193+#include <linux/sched.h>
69194+#include <linux/gracl.h>
69195+#include <linux/grinternal.h>
69196+
69197+static const char *restab_log[] = {
69198+ [RLIMIT_CPU] = "RLIMIT_CPU",
69199+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
69200+ [RLIMIT_DATA] = "RLIMIT_DATA",
69201+ [RLIMIT_STACK] = "RLIMIT_STACK",
69202+ [RLIMIT_CORE] = "RLIMIT_CORE",
69203+ [RLIMIT_RSS] = "RLIMIT_RSS",
69204+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
69205+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
69206+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
69207+ [RLIMIT_AS] = "RLIMIT_AS",
69208+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
69209+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
69210+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
69211+ [RLIMIT_NICE] = "RLIMIT_NICE",
69212+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
69213+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
69214+ [GR_CRASH_RES] = "RLIMIT_CRASH"
69215+};
69216+
69217+void
69218+gr_log_resource(const struct task_struct *task,
69219+ const int res, const unsigned long wanted, const int gt)
69220+{
69221+ const struct cred *cred;
69222+ unsigned long rlim;
69223+
69224+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
69225+ return;
69226+
69227+ // not yet supported resource
69228+ if (unlikely(!restab_log[res]))
69229+ return;
69230+
69231+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
69232+ rlim = task_rlimit_max(task, res);
69233+ else
69234+ rlim = task_rlimit(task, res);
69235+
69236+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
69237+ return;
69238+
69239+ rcu_read_lock();
69240+ cred = __task_cred(task);
69241+
69242+ if (res == RLIMIT_NPROC &&
69243+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
69244+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
69245+ goto out_rcu_unlock;
69246+ else if (res == RLIMIT_MEMLOCK &&
69247+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
69248+ goto out_rcu_unlock;
69249+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
69250+ goto out_rcu_unlock;
69251+ rcu_read_unlock();
69252+
69253+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
69254+
69255+ return;
69256+out_rcu_unlock:
69257+ rcu_read_unlock();
69258+ return;
69259+}
69260diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
69261new file mode 100644
69262index 0000000..3c38bfe
69263--- /dev/null
69264+++ b/grsecurity/gracl_segv.c
69265@@ -0,0 +1,305 @@
69266+#include <linux/kernel.h>
69267+#include <linux/mm.h>
69268+#include <asm/uaccess.h>
69269+#include <asm/errno.h>
69270+#include <asm/mman.h>
69271+#include <net/sock.h>
69272+#include <linux/file.h>
69273+#include <linux/fs.h>
69274+#include <linux/net.h>
69275+#include <linux/in.h>
69276+#include <linux/slab.h>
69277+#include <linux/types.h>
69278+#include <linux/sched.h>
69279+#include <linux/timer.h>
69280+#include <linux/gracl.h>
69281+#include <linux/grsecurity.h>
69282+#include <linux/grinternal.h>
69283+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69284+#include <linux/magic.h>
69285+#include <linux/pagemap.h>
69286+#include "../fs/btrfs/async-thread.h"
69287+#include "../fs/btrfs/ctree.h"
69288+#include "../fs/btrfs/btrfs_inode.h"
69289+#endif
69290+
69291+static struct crash_uid *uid_set;
69292+static unsigned short uid_used;
69293+static DEFINE_SPINLOCK(gr_uid_lock);
69294+extern rwlock_t gr_inode_lock;
69295+extern struct acl_subject_label *
69296+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
69297+ struct acl_role_label *role);
69298+
69299+static inline dev_t __get_dev(const struct dentry *dentry)
69300+{
69301+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69302+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69303+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
69304+ else
69305+#endif
69306+ return dentry->d_sb->s_dev;
69307+}
69308+
69309+int
69310+gr_init_uidset(void)
69311+{
69312+ uid_set =
69313+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
69314+ uid_used = 0;
69315+
69316+ return uid_set ? 1 : 0;
69317+}
69318+
69319+void
69320+gr_free_uidset(void)
69321+{
69322+ if (uid_set)
69323+ kfree(uid_set);
69324+
69325+ return;
69326+}
69327+
69328+int
69329+gr_find_uid(const uid_t uid)
69330+{
69331+ struct crash_uid *tmp = uid_set;
69332+ uid_t buid;
69333+ int low = 0, high = uid_used - 1, mid;
69334+
69335+ while (high >= low) {
69336+ mid = (low + high) >> 1;
69337+ buid = tmp[mid].uid;
69338+ if (buid == uid)
69339+ return mid;
69340+ if (buid > uid)
69341+ high = mid - 1;
69342+ if (buid < uid)
69343+ low = mid + 1;
69344+ }
69345+
69346+ return -1;
69347+}
69348+
69349+static __inline__ void
69350+gr_insertsort(void)
69351+{
69352+ unsigned short i, j;
69353+ struct crash_uid index;
69354+
69355+ for (i = 1; i < uid_used; i++) {
69356+ index = uid_set[i];
69357+ j = i;
69358+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
69359+ uid_set[j] = uid_set[j - 1];
69360+ j--;
69361+ }
69362+ uid_set[j] = index;
69363+ }
69364+
69365+ return;
69366+}
69367+
69368+static __inline__ void
69369+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
69370+{
69371+ int loc;
69372+ uid_t uid = GR_GLOBAL_UID(kuid);
69373+
69374+ if (uid_used == GR_UIDTABLE_MAX)
69375+ return;
69376+
69377+ loc = gr_find_uid(uid);
69378+
69379+ if (loc >= 0) {
69380+ uid_set[loc].expires = expires;
69381+ return;
69382+ }
69383+
69384+ uid_set[uid_used].uid = uid;
69385+ uid_set[uid_used].expires = expires;
69386+ uid_used++;
69387+
69388+ gr_insertsort();
69389+
69390+ return;
69391+}
69392+
69393+void
69394+gr_remove_uid(const unsigned short loc)
69395+{
69396+ unsigned short i;
69397+
69398+ for (i = loc + 1; i < uid_used; i++)
69399+ uid_set[i - 1] = uid_set[i];
69400+
69401+ uid_used--;
69402+
69403+ return;
69404+}
69405+
69406+int
69407+gr_check_crash_uid(const kuid_t kuid)
69408+{
69409+ int loc;
69410+ int ret = 0;
69411+ uid_t uid;
69412+
69413+ if (unlikely(!gr_acl_is_enabled()))
69414+ return 0;
69415+
69416+ uid = GR_GLOBAL_UID(kuid);
69417+
69418+ spin_lock(&gr_uid_lock);
69419+ loc = gr_find_uid(uid);
69420+
69421+ if (loc < 0)
69422+ goto out_unlock;
69423+
69424+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
69425+ gr_remove_uid(loc);
69426+ else
69427+ ret = 1;
69428+
69429+out_unlock:
69430+ spin_unlock(&gr_uid_lock);
69431+ return ret;
69432+}
69433+
69434+static __inline__ int
69435+proc_is_setxid(const struct cred *cred)
69436+{
69437+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
69438+ !uid_eq(cred->uid, cred->fsuid))
69439+ return 1;
69440+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
69441+ !gid_eq(cred->gid, cred->fsgid))
69442+ return 1;
69443+
69444+ return 0;
69445+}
69446+
69447+extern int gr_fake_force_sig(int sig, struct task_struct *t);
69448+
69449+void
69450+gr_handle_crash(struct task_struct *task, const int sig)
69451+{
69452+ struct acl_subject_label *curr;
69453+ struct task_struct *tsk, *tsk2;
69454+ const struct cred *cred;
69455+ const struct cred *cred2;
69456+
69457+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
69458+ return;
69459+
69460+ if (unlikely(!gr_acl_is_enabled()))
69461+ return;
69462+
69463+ curr = task->acl;
69464+
69465+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
69466+ return;
69467+
69468+ if (time_before_eq(curr->expires, get_seconds())) {
69469+ curr->expires = 0;
69470+ curr->crashes = 0;
69471+ }
69472+
69473+ curr->crashes++;
69474+
69475+ if (!curr->expires)
69476+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
69477+
69478+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
69479+ time_after(curr->expires, get_seconds())) {
69480+ rcu_read_lock();
69481+ cred = __task_cred(task);
69482+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
69483+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
69484+ spin_lock(&gr_uid_lock);
69485+ gr_insert_uid(cred->uid, curr->expires);
69486+ spin_unlock(&gr_uid_lock);
69487+ curr->expires = 0;
69488+ curr->crashes = 0;
69489+ read_lock(&tasklist_lock);
69490+ do_each_thread(tsk2, tsk) {
69491+ cred2 = __task_cred(tsk);
69492+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
69493+ gr_fake_force_sig(SIGKILL, tsk);
69494+ } while_each_thread(tsk2, tsk);
69495+ read_unlock(&tasklist_lock);
69496+ } else {
69497+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
69498+ read_lock(&tasklist_lock);
69499+ read_lock(&grsec_exec_file_lock);
69500+ do_each_thread(tsk2, tsk) {
69501+ if (likely(tsk != task)) {
69502+ // if this thread has the same subject as the one that triggered
69503+ // RES_CRASH and it's the same binary, kill it
69504+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
69505+ gr_fake_force_sig(SIGKILL, tsk);
69506+ }
69507+ } while_each_thread(tsk2, tsk);
69508+ read_unlock(&grsec_exec_file_lock);
69509+ read_unlock(&tasklist_lock);
69510+ }
69511+ rcu_read_unlock();
69512+ }
69513+
69514+ return;
69515+}
69516+
69517+int
69518+gr_check_crash_exec(const struct file *filp)
69519+{
69520+ struct acl_subject_label *curr;
69521+
69522+ if (unlikely(!gr_acl_is_enabled()))
69523+ return 0;
69524+
69525+ read_lock(&gr_inode_lock);
69526+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
69527+ __get_dev(filp->f_path.dentry),
69528+ current->role);
69529+ read_unlock(&gr_inode_lock);
69530+
69531+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
69532+ (!curr->crashes && !curr->expires))
69533+ return 0;
69534+
69535+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
69536+ time_after(curr->expires, get_seconds()))
69537+ return 1;
69538+ else if (time_before_eq(curr->expires, get_seconds())) {
69539+ curr->crashes = 0;
69540+ curr->expires = 0;
69541+ }
69542+
69543+ return 0;
69544+}
69545+
69546+void
69547+gr_handle_alertkill(struct task_struct *task)
69548+{
69549+ struct acl_subject_label *curracl;
69550+ __u32 curr_ip;
69551+ struct task_struct *p, *p2;
69552+
69553+ if (unlikely(!gr_acl_is_enabled()))
69554+ return;
69555+
69556+ curracl = task->acl;
69557+ curr_ip = task->signal->curr_ip;
69558+
69559+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
69560+ read_lock(&tasklist_lock);
69561+ do_each_thread(p2, p) {
69562+ if (p->signal->curr_ip == curr_ip)
69563+ gr_fake_force_sig(SIGKILL, p);
69564+ } while_each_thread(p2, p);
69565+ read_unlock(&tasklist_lock);
69566+ } else if (curracl->mode & GR_KILLPROC)
69567+ gr_fake_force_sig(SIGKILL, task);
69568+
69569+ return;
69570+}
69571diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
69572new file mode 100644
69573index 0000000..98011b0
69574--- /dev/null
69575+++ b/grsecurity/gracl_shm.c
69576@@ -0,0 +1,40 @@
69577+#include <linux/kernel.h>
69578+#include <linux/mm.h>
69579+#include <linux/sched.h>
69580+#include <linux/file.h>
69581+#include <linux/ipc.h>
69582+#include <linux/gracl.h>
69583+#include <linux/grsecurity.h>
69584+#include <linux/grinternal.h>
69585+
69586+int
69587+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69588+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69589+{
69590+ struct task_struct *task;
69591+
69592+ if (!gr_acl_is_enabled())
69593+ return 1;
69594+
69595+ rcu_read_lock();
69596+ read_lock(&tasklist_lock);
69597+
69598+ task = find_task_by_vpid(shm_cprid);
69599+
69600+ if (unlikely(!task))
69601+ task = find_task_by_vpid(shm_lapid);
69602+
69603+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
69604+ (task_pid_nr(task) == shm_lapid)) &&
69605+ (task->acl->mode & GR_PROTSHM) &&
69606+ (task->acl != current->acl))) {
69607+ read_unlock(&tasklist_lock);
69608+ rcu_read_unlock();
69609+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
69610+ return 0;
69611+ }
69612+ read_unlock(&tasklist_lock);
69613+ rcu_read_unlock();
69614+
69615+ return 1;
69616+}
69617diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
69618new file mode 100644
69619index 0000000..bc0be01
69620--- /dev/null
69621+++ b/grsecurity/grsec_chdir.c
69622@@ -0,0 +1,19 @@
69623+#include <linux/kernel.h>
69624+#include <linux/sched.h>
69625+#include <linux/fs.h>
69626+#include <linux/file.h>
69627+#include <linux/grsecurity.h>
69628+#include <linux/grinternal.h>
69629+
69630+void
69631+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
69632+{
69633+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69634+ if ((grsec_enable_chdir && grsec_enable_group &&
69635+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
69636+ !grsec_enable_group)) {
69637+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
69638+ }
69639+#endif
69640+ return;
69641+}
69642diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
69643new file mode 100644
69644index 0000000..bd6e105
69645--- /dev/null
69646+++ b/grsecurity/grsec_chroot.c
69647@@ -0,0 +1,370 @@
69648+#include <linux/kernel.h>
69649+#include <linux/module.h>
69650+#include <linux/sched.h>
69651+#include <linux/file.h>
69652+#include <linux/fs.h>
69653+#include <linux/mount.h>
69654+#include <linux/types.h>
69655+#include "../fs/mount.h"
69656+#include <linux/grsecurity.h>
69657+#include <linux/grinternal.h>
69658+
69659+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
69660+static int gr_init_ran;
69661+#endif
69662+
69663+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
69664+{
69665+#ifdef CONFIG_GRKERNSEC
69666+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
69667+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
69668+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
69669+ && gr_init_ran
69670+#endif
69671+ )
69672+ task->gr_is_chrooted = 1;
69673+ else {
69674+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
69675+ if (task_pid_nr(task) == 1 && !gr_init_ran)
69676+ gr_init_ran = 1;
69677+#endif
69678+ task->gr_is_chrooted = 0;
69679+ }
69680+
69681+ task->gr_chroot_dentry = path->dentry;
69682+#endif
69683+ return;
69684+}
69685+
69686+void gr_clear_chroot_entries(struct task_struct *task)
69687+{
69688+#ifdef CONFIG_GRKERNSEC
69689+ task->gr_is_chrooted = 0;
69690+ task->gr_chroot_dentry = NULL;
69691+#endif
69692+ return;
69693+}
69694+
69695+int
69696+gr_handle_chroot_unix(const pid_t pid)
69697+{
69698+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69699+ struct task_struct *p;
69700+
69701+ if (unlikely(!grsec_enable_chroot_unix))
69702+ return 1;
69703+
69704+ if (likely(!proc_is_chrooted(current)))
69705+ return 1;
69706+
69707+ rcu_read_lock();
69708+ read_lock(&tasklist_lock);
69709+ p = find_task_by_vpid_unrestricted(pid);
69710+ if (unlikely(p && !have_same_root(current, p))) {
69711+ read_unlock(&tasklist_lock);
69712+ rcu_read_unlock();
69713+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
69714+ return 0;
69715+ }
69716+ read_unlock(&tasklist_lock);
69717+ rcu_read_unlock();
69718+#endif
69719+ return 1;
69720+}
69721+
69722+int
69723+gr_handle_chroot_nice(void)
69724+{
69725+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69726+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
69727+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
69728+ return -EPERM;
69729+ }
69730+#endif
69731+ return 0;
69732+}
69733+
69734+int
69735+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
69736+{
69737+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69738+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
69739+ && proc_is_chrooted(current)) {
69740+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
69741+ return -EACCES;
69742+ }
69743+#endif
69744+ return 0;
69745+}
69746+
69747+int
69748+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
69749+{
69750+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69751+ struct task_struct *p;
69752+ int ret = 0;
69753+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
69754+ return ret;
69755+
69756+ read_lock(&tasklist_lock);
69757+ do_each_pid_task(pid, type, p) {
69758+ if (!have_same_root(current, p)) {
69759+ ret = 1;
69760+ goto out;
69761+ }
69762+ } while_each_pid_task(pid, type, p);
69763+out:
69764+ read_unlock(&tasklist_lock);
69765+ return ret;
69766+#endif
69767+ return 0;
69768+}
69769+
69770+int
69771+gr_pid_is_chrooted(struct task_struct *p)
69772+{
69773+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69774+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
69775+ return 0;
69776+
69777+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
69778+ !have_same_root(current, p)) {
69779+ return 1;
69780+ }
69781+#endif
69782+ return 0;
69783+}
69784+
69785+EXPORT_SYMBOL(gr_pid_is_chrooted);
69786+
69787+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
69788+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
69789+{
69790+ struct path path, currentroot;
69791+ int ret = 0;
69792+
69793+ path.dentry = (struct dentry *)u_dentry;
69794+ path.mnt = (struct vfsmount *)u_mnt;
69795+ get_fs_root(current->fs, &currentroot);
69796+ if (path_is_under(&path, &currentroot))
69797+ ret = 1;
69798+ path_put(&currentroot);
69799+
69800+ return ret;
69801+}
69802+#endif
69803+
69804+int
69805+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
69806+{
69807+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69808+ if (!grsec_enable_chroot_fchdir)
69809+ return 1;
69810+
69811+ if (!proc_is_chrooted(current))
69812+ return 1;
69813+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
69814+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
69815+ return 0;
69816+ }
69817+#endif
69818+ return 1;
69819+}
69820+
69821+int
69822+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69823+ const time_t shm_createtime)
69824+{
69825+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69826+ struct task_struct *p;
69827+ time_t starttime;
69828+
69829+ if (unlikely(!grsec_enable_chroot_shmat))
69830+ return 1;
69831+
69832+ if (likely(!proc_is_chrooted(current)))
69833+ return 1;
69834+
69835+ rcu_read_lock();
69836+ read_lock(&tasklist_lock);
69837+
69838+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
69839+ starttime = p->start_time.tv_sec;
69840+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
69841+ if (have_same_root(current, p)) {
69842+ goto allow;
69843+ } else {
69844+ read_unlock(&tasklist_lock);
69845+ rcu_read_unlock();
69846+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
69847+ return 0;
69848+ }
69849+ }
69850+ /* creator exited, pid reuse, fall through to next check */
69851+ }
69852+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
69853+ if (unlikely(!have_same_root(current, p))) {
69854+ read_unlock(&tasklist_lock);
69855+ rcu_read_unlock();
69856+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
69857+ return 0;
69858+ }
69859+ }
69860+
69861+allow:
69862+ read_unlock(&tasklist_lock);
69863+ rcu_read_unlock();
69864+#endif
69865+ return 1;
69866+}
69867+
69868+void
69869+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
69870+{
69871+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69872+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
69873+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
69874+#endif
69875+ return;
69876+}
69877+
69878+int
69879+gr_handle_chroot_mknod(const struct dentry *dentry,
69880+ const struct vfsmount *mnt, const int mode)
69881+{
69882+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69883+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
69884+ proc_is_chrooted(current)) {
69885+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
69886+ return -EPERM;
69887+ }
69888+#endif
69889+ return 0;
69890+}
69891+
69892+int
69893+gr_handle_chroot_mount(const struct dentry *dentry,
69894+ const struct vfsmount *mnt, const char *dev_name)
69895+{
69896+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69897+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
69898+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
69899+ return -EPERM;
69900+ }
69901+#endif
69902+ return 0;
69903+}
69904+
69905+int
69906+gr_handle_chroot_pivot(void)
69907+{
69908+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69909+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
69910+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
69911+ return -EPERM;
69912+ }
69913+#endif
69914+ return 0;
69915+}
69916+
69917+int
69918+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
69919+{
69920+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69921+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
69922+ !gr_is_outside_chroot(dentry, mnt)) {
69923+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
69924+ return -EPERM;
69925+ }
69926+#endif
69927+ return 0;
69928+}
69929+
69930+extern const char *captab_log[];
69931+extern int captab_log_entries;
69932+
69933+int
69934+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69935+{
69936+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69937+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
69938+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
69939+ if (cap_raised(chroot_caps, cap)) {
69940+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
69941+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
69942+ }
69943+ return 0;
69944+ }
69945+ }
69946+#endif
69947+ return 1;
69948+}
69949+
69950+int
69951+gr_chroot_is_capable(const int cap)
69952+{
69953+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69954+ return gr_task_chroot_is_capable(current, current_cred(), cap);
69955+#endif
69956+ return 1;
69957+}
69958+
69959+int
69960+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
69961+{
69962+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69963+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
69964+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
69965+ if (cap_raised(chroot_caps, cap)) {
69966+ return 0;
69967+ }
69968+ }
69969+#endif
69970+ return 1;
69971+}
69972+
69973+int
69974+gr_chroot_is_capable_nolog(const int cap)
69975+{
69976+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69977+ return gr_task_chroot_is_capable_nolog(current, cap);
69978+#endif
69979+ return 1;
69980+}
69981+
69982+int
69983+gr_handle_chroot_sysctl(const int op)
69984+{
69985+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69986+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
69987+ proc_is_chrooted(current))
69988+ return -EACCES;
69989+#endif
69990+ return 0;
69991+}
69992+
69993+void
69994+gr_handle_chroot_chdir(const struct path *path)
69995+{
69996+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69997+ if (grsec_enable_chroot_chdir)
69998+ set_fs_pwd(current->fs, path);
69999+#endif
70000+ return;
70001+}
70002+
70003+int
70004+gr_handle_chroot_chmod(const struct dentry *dentry,
70005+ const struct vfsmount *mnt, const int mode)
70006+{
70007+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
70008+ /* allow chmod +s on directories, but not files */
70009+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
70010+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
70011+ proc_is_chrooted(current)) {
70012+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
70013+ return -EPERM;
70014+ }
70015+#endif
70016+ return 0;
70017+}
70018diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
70019new file mode 100644
70020index 0000000..ce65ceb
70021--- /dev/null
70022+++ b/grsecurity/grsec_disabled.c
70023@@ -0,0 +1,434 @@
70024+#include <linux/kernel.h>
70025+#include <linux/module.h>
70026+#include <linux/sched.h>
70027+#include <linux/file.h>
70028+#include <linux/fs.h>
70029+#include <linux/kdev_t.h>
70030+#include <linux/net.h>
70031+#include <linux/in.h>
70032+#include <linux/ip.h>
70033+#include <linux/skbuff.h>
70034+#include <linux/sysctl.h>
70035+
70036+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
70037+void
70038+pax_set_initial_flags(struct linux_binprm *bprm)
70039+{
70040+ return;
70041+}
70042+#endif
70043+
70044+#ifdef CONFIG_SYSCTL
70045+__u32
70046+gr_handle_sysctl(const struct ctl_table * table, const int op)
70047+{
70048+ return 0;
70049+}
70050+#endif
70051+
70052+#ifdef CONFIG_TASKSTATS
70053+int gr_is_taskstats_denied(int pid)
70054+{
70055+ return 0;
70056+}
70057+#endif
70058+
70059+int
70060+gr_acl_is_enabled(void)
70061+{
70062+ return 0;
70063+}
70064+
70065+void
70066+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
70067+{
70068+ return;
70069+}
70070+
70071+int
70072+gr_handle_rawio(const struct inode *inode)
70073+{
70074+ return 0;
70075+}
70076+
70077+void
70078+gr_acl_handle_psacct(struct task_struct *task, const long code)
70079+{
70080+ return;
70081+}
70082+
70083+int
70084+gr_handle_ptrace(struct task_struct *task, const long request)
70085+{
70086+ return 0;
70087+}
70088+
70089+int
70090+gr_handle_proc_ptrace(struct task_struct *task)
70091+{
70092+ return 0;
70093+}
70094+
70095+int
70096+gr_set_acls(const int type)
70097+{
70098+ return 0;
70099+}
70100+
70101+int
70102+gr_check_hidden_task(const struct task_struct *tsk)
70103+{
70104+ return 0;
70105+}
70106+
70107+int
70108+gr_check_protected_task(const struct task_struct *task)
70109+{
70110+ return 0;
70111+}
70112+
70113+int
70114+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
70115+{
70116+ return 0;
70117+}
70118+
70119+void
70120+gr_copy_label(struct task_struct *tsk)
70121+{
70122+ return;
70123+}
70124+
70125+void
70126+gr_set_pax_flags(struct task_struct *task)
70127+{
70128+ return;
70129+}
70130+
70131+int
70132+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
70133+ const int unsafe_share)
70134+{
70135+ return 0;
70136+}
70137+
70138+void
70139+gr_handle_delete(const ino_t ino, const dev_t dev)
70140+{
70141+ return;
70142+}
70143+
70144+void
70145+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
70146+{
70147+ return;
70148+}
70149+
70150+void
70151+gr_handle_crash(struct task_struct *task, const int sig)
70152+{
70153+ return;
70154+}
70155+
70156+int
70157+gr_check_crash_exec(const struct file *filp)
70158+{
70159+ return 0;
70160+}
70161+
70162+int
70163+gr_check_crash_uid(const kuid_t uid)
70164+{
70165+ return 0;
70166+}
70167+
70168+void
70169+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
70170+ struct dentry *old_dentry,
70171+ struct dentry *new_dentry,
70172+ struct vfsmount *mnt, const __u8 replace)
70173+{
70174+ return;
70175+}
70176+
70177+int
70178+gr_search_socket(const int family, const int type, const int protocol)
70179+{
70180+ return 1;
70181+}
70182+
70183+int
70184+gr_search_connectbind(const int mode, const struct socket *sock,
70185+ const struct sockaddr_in *addr)
70186+{
70187+ return 0;
70188+}
70189+
70190+void
70191+gr_handle_alertkill(struct task_struct *task)
70192+{
70193+ return;
70194+}
70195+
70196+__u32
70197+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
70198+{
70199+ return 1;
70200+}
70201+
70202+__u32
70203+gr_acl_handle_hidden_file(const struct dentry * dentry,
70204+ const struct vfsmount * mnt)
70205+{
70206+ return 1;
70207+}
70208+
70209+__u32
70210+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70211+ int acc_mode)
70212+{
70213+ return 1;
70214+}
70215+
70216+__u32
70217+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70218+{
70219+ return 1;
70220+}
70221+
70222+__u32
70223+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
70224+{
70225+ return 1;
70226+}
70227+
70228+int
70229+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
70230+ unsigned int *vm_flags)
70231+{
70232+ return 1;
70233+}
70234+
70235+__u32
70236+gr_acl_handle_truncate(const struct dentry * dentry,
70237+ const struct vfsmount * mnt)
70238+{
70239+ return 1;
70240+}
70241+
70242+__u32
70243+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
70244+{
70245+ return 1;
70246+}
70247+
70248+__u32
70249+gr_acl_handle_access(const struct dentry * dentry,
70250+ const struct vfsmount * mnt, const int fmode)
70251+{
70252+ return 1;
70253+}
70254+
70255+__u32
70256+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
70257+ umode_t *mode)
70258+{
70259+ return 1;
70260+}
70261+
70262+__u32
70263+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
70264+{
70265+ return 1;
70266+}
70267+
70268+__u32
70269+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
70270+{
70271+ return 1;
70272+}
70273+
70274+void
70275+grsecurity_init(void)
70276+{
70277+ return;
70278+}
70279+
70280+umode_t gr_acl_umask(void)
70281+{
70282+ return 0;
70283+}
70284+
70285+__u32
70286+gr_acl_handle_mknod(const struct dentry * new_dentry,
70287+ const struct dentry * parent_dentry,
70288+ const struct vfsmount * parent_mnt,
70289+ const int mode)
70290+{
70291+ return 1;
70292+}
70293+
70294+__u32
70295+gr_acl_handle_mkdir(const struct dentry * new_dentry,
70296+ const struct dentry * parent_dentry,
70297+ const struct vfsmount * parent_mnt)
70298+{
70299+ return 1;
70300+}
70301+
70302+__u32
70303+gr_acl_handle_symlink(const struct dentry * new_dentry,
70304+ const struct dentry * parent_dentry,
70305+ const struct vfsmount * parent_mnt, const struct filename *from)
70306+{
70307+ return 1;
70308+}
70309+
70310+__u32
70311+gr_acl_handle_link(const struct dentry * new_dentry,
70312+ const struct dentry * parent_dentry,
70313+ const struct vfsmount * parent_mnt,
70314+ const struct dentry * old_dentry,
70315+ const struct vfsmount * old_mnt, const struct filename *to)
70316+{
70317+ return 1;
70318+}
70319+
70320+int
70321+gr_acl_handle_rename(const struct dentry *new_dentry,
70322+ const struct dentry *parent_dentry,
70323+ const struct vfsmount *parent_mnt,
70324+ const struct dentry *old_dentry,
70325+ const struct inode *old_parent_inode,
70326+ const struct vfsmount *old_mnt, const struct filename *newname)
70327+{
70328+ return 0;
70329+}
70330+
70331+int
70332+gr_acl_handle_filldir(const struct file *file, const char *name,
70333+ const int namelen, const ino_t ino)
70334+{
70335+ return 1;
70336+}
70337+
70338+int
70339+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70340+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
70341+{
70342+ return 1;
70343+}
70344+
70345+int
70346+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
70347+{
70348+ return 0;
70349+}
70350+
70351+int
70352+gr_search_accept(const struct socket *sock)
70353+{
70354+ return 0;
70355+}
70356+
70357+int
70358+gr_search_listen(const struct socket *sock)
70359+{
70360+ return 0;
70361+}
70362+
70363+int
70364+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
70365+{
70366+ return 0;
70367+}
70368+
70369+__u32
70370+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
70371+{
70372+ return 1;
70373+}
70374+
70375+__u32
70376+gr_acl_handle_creat(const struct dentry * dentry,
70377+ const struct dentry * p_dentry,
70378+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70379+ const int imode)
70380+{
70381+ return 1;
70382+}
70383+
70384+void
70385+gr_acl_handle_exit(void)
70386+{
70387+ return;
70388+}
70389+
70390+int
70391+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
70392+{
70393+ return 1;
70394+}
70395+
70396+void
70397+gr_set_role_label(const kuid_t uid, const kgid_t gid)
70398+{
70399+ return;
70400+}
70401+
70402+int
70403+gr_acl_handle_procpidmem(const struct task_struct *task)
70404+{
70405+ return 0;
70406+}
70407+
70408+int
70409+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
70410+{
70411+ return 0;
70412+}
70413+
70414+int
70415+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
70416+{
70417+ return 0;
70418+}
70419+
70420+void
70421+gr_set_kernel_label(struct task_struct *task)
70422+{
70423+ return;
70424+}
70425+
70426+int
70427+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
70428+{
70429+ return 0;
70430+}
70431+
70432+int
70433+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
70434+{
70435+ return 0;
70436+}
70437+
70438+int gr_acl_enable_at_secure(void)
70439+{
70440+ return 0;
70441+}
70442+
70443+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
70444+{
70445+ return dentry->d_sb->s_dev;
70446+}
70447+
70448+void gr_put_exec_file(struct task_struct *task)
70449+{
70450+ return;
70451+}
70452+
70453+EXPORT_SYMBOL(gr_set_kernel_label);
70454+#ifdef CONFIG_SECURITY
70455+EXPORT_SYMBOL(gr_check_user_change);
70456+EXPORT_SYMBOL(gr_check_group_change);
70457+#endif
70458diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
70459new file mode 100644
70460index 0000000..387032b
70461--- /dev/null
70462+++ b/grsecurity/grsec_exec.c
70463@@ -0,0 +1,187 @@
70464+#include <linux/kernel.h>
70465+#include <linux/sched.h>
70466+#include <linux/file.h>
70467+#include <linux/binfmts.h>
70468+#include <linux/fs.h>
70469+#include <linux/types.h>
70470+#include <linux/grdefs.h>
70471+#include <linux/grsecurity.h>
70472+#include <linux/grinternal.h>
70473+#include <linux/capability.h>
70474+#include <linux/module.h>
70475+#include <linux/compat.h>
70476+
70477+#include <asm/uaccess.h>
70478+
70479+#ifdef CONFIG_GRKERNSEC_EXECLOG
70480+static char gr_exec_arg_buf[132];
70481+static DEFINE_MUTEX(gr_exec_arg_mutex);
70482+#endif
70483+
70484+struct user_arg_ptr {
70485+#ifdef CONFIG_COMPAT
70486+ bool is_compat;
70487+#endif
70488+ union {
70489+ const char __user *const __user *native;
70490+#ifdef CONFIG_COMPAT
70491+ const compat_uptr_t __user *compat;
70492+#endif
70493+ } ptr;
70494+};
70495+
70496+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
70497+
70498+void
70499+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
70500+{
70501+#ifdef CONFIG_GRKERNSEC_EXECLOG
70502+ char *grarg = gr_exec_arg_buf;
70503+ unsigned int i, x, execlen = 0;
70504+ char c;
70505+
70506+ if (!((grsec_enable_execlog && grsec_enable_group &&
70507+ in_group_p(grsec_audit_gid))
70508+ || (grsec_enable_execlog && !grsec_enable_group)))
70509+ return;
70510+
70511+ mutex_lock(&gr_exec_arg_mutex);
70512+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
70513+
70514+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
70515+ const char __user *p;
70516+ unsigned int len;
70517+
70518+ p = get_user_arg_ptr(argv, i);
70519+ if (IS_ERR(p))
70520+ goto log;
70521+
70522+ len = strnlen_user(p, 128 - execlen);
70523+ if (len > 128 - execlen)
70524+ len = 128 - execlen;
70525+ else if (len > 0)
70526+ len--;
70527+ if (copy_from_user(grarg + execlen, p, len))
70528+ goto log;
70529+
70530+ /* rewrite unprintable characters */
70531+ for (x = 0; x < len; x++) {
70532+ c = *(grarg + execlen + x);
70533+ if (c < 32 || c > 126)
70534+ *(grarg + execlen + x) = ' ';
70535+ }
70536+
70537+ execlen += len;
70538+ *(grarg + execlen) = ' ';
70539+ *(grarg + execlen + 1) = '\0';
70540+ execlen++;
70541+ }
70542+
70543+ log:
70544+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
70545+ bprm->file->f_path.mnt, grarg);
70546+ mutex_unlock(&gr_exec_arg_mutex);
70547+#endif
70548+ return;
70549+}
70550+
70551+#ifdef CONFIG_GRKERNSEC
70552+extern int gr_acl_is_capable(const int cap);
70553+extern int gr_acl_is_capable_nolog(const int cap);
70554+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
70555+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
70556+extern int gr_chroot_is_capable(const int cap);
70557+extern int gr_chroot_is_capable_nolog(const int cap);
70558+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
70559+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
70560+#endif
70561+
70562+const char *captab_log[] = {
70563+ "CAP_CHOWN",
70564+ "CAP_DAC_OVERRIDE",
70565+ "CAP_DAC_READ_SEARCH",
70566+ "CAP_FOWNER",
70567+ "CAP_FSETID",
70568+ "CAP_KILL",
70569+ "CAP_SETGID",
70570+ "CAP_SETUID",
70571+ "CAP_SETPCAP",
70572+ "CAP_LINUX_IMMUTABLE",
70573+ "CAP_NET_BIND_SERVICE",
70574+ "CAP_NET_BROADCAST",
70575+ "CAP_NET_ADMIN",
70576+ "CAP_NET_RAW",
70577+ "CAP_IPC_LOCK",
70578+ "CAP_IPC_OWNER",
70579+ "CAP_SYS_MODULE",
70580+ "CAP_SYS_RAWIO",
70581+ "CAP_SYS_CHROOT",
70582+ "CAP_SYS_PTRACE",
70583+ "CAP_SYS_PACCT",
70584+ "CAP_SYS_ADMIN",
70585+ "CAP_SYS_BOOT",
70586+ "CAP_SYS_NICE",
70587+ "CAP_SYS_RESOURCE",
70588+ "CAP_SYS_TIME",
70589+ "CAP_SYS_TTY_CONFIG",
70590+ "CAP_MKNOD",
70591+ "CAP_LEASE",
70592+ "CAP_AUDIT_WRITE",
70593+ "CAP_AUDIT_CONTROL",
70594+ "CAP_SETFCAP",
70595+ "CAP_MAC_OVERRIDE",
70596+ "CAP_MAC_ADMIN",
70597+ "CAP_SYSLOG",
70598+ "CAP_WAKE_ALARM"
70599+};
70600+
70601+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
70602+
70603+int gr_is_capable(const int cap)
70604+{
70605+#ifdef CONFIG_GRKERNSEC
70606+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
70607+ return 1;
70608+ return 0;
70609+#else
70610+ return 1;
70611+#endif
70612+}
70613+
70614+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
70615+{
70616+#ifdef CONFIG_GRKERNSEC
70617+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
70618+ return 1;
70619+ return 0;
70620+#else
70621+ return 1;
70622+#endif
70623+}
70624+
70625+int gr_is_capable_nolog(const int cap)
70626+{
70627+#ifdef CONFIG_GRKERNSEC
70628+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
70629+ return 1;
70630+ return 0;
70631+#else
70632+ return 1;
70633+#endif
70634+}
70635+
70636+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
70637+{
70638+#ifdef CONFIG_GRKERNSEC
70639+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
70640+ return 1;
70641+ return 0;
70642+#else
70643+ return 1;
70644+#endif
70645+}
70646+
70647+EXPORT_SYMBOL(gr_is_capable);
70648+EXPORT_SYMBOL(gr_is_capable_nolog);
70649+EXPORT_SYMBOL(gr_task_is_capable);
70650+EXPORT_SYMBOL(gr_task_is_capable_nolog);
70651diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
70652new file mode 100644
70653index 0000000..06cc6ea
70654--- /dev/null
70655+++ b/grsecurity/grsec_fifo.c
70656@@ -0,0 +1,24 @@
70657+#include <linux/kernel.h>
70658+#include <linux/sched.h>
70659+#include <linux/fs.h>
70660+#include <linux/file.h>
70661+#include <linux/grinternal.h>
70662+
70663+int
70664+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
70665+ const struct dentry *dir, const int flag, const int acc_mode)
70666+{
70667+#ifdef CONFIG_GRKERNSEC_FIFO
70668+ const struct cred *cred = current_cred();
70669+
70670+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
70671+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
70672+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
70673+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
70674+ if (!inode_permission(dentry->d_inode, acc_mode))
70675+ 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));
70676+ return -EACCES;
70677+ }
70678+#endif
70679+ return 0;
70680+}
70681diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
70682new file mode 100644
70683index 0000000..8ca18bf
70684--- /dev/null
70685+++ b/grsecurity/grsec_fork.c
70686@@ -0,0 +1,23 @@
70687+#include <linux/kernel.h>
70688+#include <linux/sched.h>
70689+#include <linux/grsecurity.h>
70690+#include <linux/grinternal.h>
70691+#include <linux/errno.h>
70692+
70693+void
70694+gr_log_forkfail(const int retval)
70695+{
70696+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70697+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
70698+ switch (retval) {
70699+ case -EAGAIN:
70700+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
70701+ break;
70702+ case -ENOMEM:
70703+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
70704+ break;
70705+ }
70706+ }
70707+#endif
70708+ return;
70709+}
70710diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
70711new file mode 100644
70712index 0000000..99a0cb9
70713--- /dev/null
70714+++ b/grsecurity/grsec_init.c
70715@@ -0,0 +1,283 @@
70716+#include <linux/kernel.h>
70717+#include <linux/sched.h>
70718+#include <linux/mm.h>
70719+#include <linux/gracl.h>
70720+#include <linux/slab.h>
70721+#include <linux/vmalloc.h>
70722+#include <linux/percpu.h>
70723+#include <linux/module.h>
70724+
70725+int grsec_enable_ptrace_readexec;
70726+int grsec_enable_setxid;
70727+int grsec_enable_symlinkown;
70728+kgid_t grsec_symlinkown_gid;
70729+int grsec_enable_brute;
70730+int grsec_enable_link;
70731+int grsec_enable_dmesg;
70732+int grsec_enable_harden_ptrace;
70733+int grsec_enable_fifo;
70734+int grsec_enable_execlog;
70735+int grsec_enable_signal;
70736+int grsec_enable_forkfail;
70737+int grsec_enable_audit_ptrace;
70738+int grsec_enable_time;
70739+int grsec_enable_group;
70740+kgid_t grsec_audit_gid;
70741+int grsec_enable_chdir;
70742+int grsec_enable_mount;
70743+int grsec_enable_rofs;
70744+int grsec_deny_new_usb;
70745+int grsec_enable_chroot_findtask;
70746+int grsec_enable_chroot_mount;
70747+int grsec_enable_chroot_shmat;
70748+int grsec_enable_chroot_fchdir;
70749+int grsec_enable_chroot_double;
70750+int grsec_enable_chroot_pivot;
70751+int grsec_enable_chroot_chdir;
70752+int grsec_enable_chroot_chmod;
70753+int grsec_enable_chroot_mknod;
70754+int grsec_enable_chroot_nice;
70755+int grsec_enable_chroot_execlog;
70756+int grsec_enable_chroot_caps;
70757+int grsec_enable_chroot_sysctl;
70758+int grsec_enable_chroot_unix;
70759+int grsec_enable_tpe;
70760+kgid_t grsec_tpe_gid;
70761+int grsec_enable_blackhole;
70762+#ifdef CONFIG_IPV6_MODULE
70763+EXPORT_SYMBOL(grsec_enable_blackhole);
70764+#endif
70765+int grsec_lastack_retries;
70766+int grsec_enable_tpe_all;
70767+int grsec_enable_tpe_invert;
70768+int grsec_enable_socket_all;
70769+kgid_t grsec_socket_all_gid;
70770+int grsec_enable_socket_client;
70771+kgid_t grsec_socket_client_gid;
70772+int grsec_enable_socket_server;
70773+kgid_t grsec_socket_server_gid;
70774+int grsec_resource_logging;
70775+int grsec_disable_privio;
70776+int grsec_enable_log_rwxmaps;
70777+int grsec_lock;
70778+
70779+DEFINE_SPINLOCK(grsec_alert_lock);
70780+unsigned long grsec_alert_wtime = 0;
70781+unsigned long grsec_alert_fyet = 0;
70782+
70783+DEFINE_SPINLOCK(grsec_audit_lock);
70784+
70785+DEFINE_RWLOCK(grsec_exec_file_lock);
70786+
70787+char *gr_shared_page[4];
70788+
70789+char *gr_alert_log_fmt;
70790+char *gr_audit_log_fmt;
70791+char *gr_alert_log_buf;
70792+char *gr_audit_log_buf;
70793+
70794+extern struct gr_arg *gr_usermode;
70795+extern unsigned char *gr_system_salt;
70796+extern unsigned char *gr_system_sum;
70797+
70798+void __init
70799+grsecurity_init(void)
70800+{
70801+ int j;
70802+ /* create the per-cpu shared pages */
70803+
70804+#ifdef CONFIG_X86
70805+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
70806+#endif
70807+
70808+ for (j = 0; j < 4; j++) {
70809+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
70810+ if (gr_shared_page[j] == NULL) {
70811+ panic("Unable to allocate grsecurity shared page");
70812+ return;
70813+ }
70814+ }
70815+
70816+ /* allocate log buffers */
70817+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
70818+ if (!gr_alert_log_fmt) {
70819+ panic("Unable to allocate grsecurity alert log format buffer");
70820+ return;
70821+ }
70822+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
70823+ if (!gr_audit_log_fmt) {
70824+ panic("Unable to allocate grsecurity audit log format buffer");
70825+ return;
70826+ }
70827+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
70828+ if (!gr_alert_log_buf) {
70829+ panic("Unable to allocate grsecurity alert log buffer");
70830+ return;
70831+ }
70832+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
70833+ if (!gr_audit_log_buf) {
70834+ panic("Unable to allocate grsecurity audit log buffer");
70835+ return;
70836+ }
70837+
70838+ /* allocate memory for authentication structure */
70839+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
70840+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
70841+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
70842+
70843+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
70844+ panic("Unable to allocate grsecurity authentication structure");
70845+ return;
70846+ }
70847+
70848+
70849+#ifdef CONFIG_GRKERNSEC_IO
70850+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
70851+ grsec_disable_privio = 1;
70852+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
70853+ grsec_disable_privio = 1;
70854+#else
70855+ grsec_disable_privio = 0;
70856+#endif
70857+#endif
70858+
70859+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
70860+ /* for backward compatibility, tpe_invert always defaults to on if
70861+ enabled in the kernel
70862+ */
70863+ grsec_enable_tpe_invert = 1;
70864+#endif
70865+
70866+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
70867+#ifndef CONFIG_GRKERNSEC_SYSCTL
70868+ grsec_lock = 1;
70869+#endif
70870+
70871+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70872+ grsec_enable_log_rwxmaps = 1;
70873+#endif
70874+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
70875+ grsec_enable_group = 1;
70876+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
70877+#endif
70878+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70879+ grsec_enable_ptrace_readexec = 1;
70880+#endif
70881+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
70882+ grsec_enable_chdir = 1;
70883+#endif
70884+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
70885+ grsec_enable_harden_ptrace = 1;
70886+#endif
70887+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70888+ grsec_enable_mount = 1;
70889+#endif
70890+#ifdef CONFIG_GRKERNSEC_LINK
70891+ grsec_enable_link = 1;
70892+#endif
70893+#ifdef CONFIG_GRKERNSEC_BRUTE
70894+ grsec_enable_brute = 1;
70895+#endif
70896+#ifdef CONFIG_GRKERNSEC_DMESG
70897+ grsec_enable_dmesg = 1;
70898+#endif
70899+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70900+ grsec_enable_blackhole = 1;
70901+ grsec_lastack_retries = 4;
70902+#endif
70903+#ifdef CONFIG_GRKERNSEC_FIFO
70904+ grsec_enable_fifo = 1;
70905+#endif
70906+#ifdef CONFIG_GRKERNSEC_EXECLOG
70907+ grsec_enable_execlog = 1;
70908+#endif
70909+#ifdef CONFIG_GRKERNSEC_SETXID
70910+ grsec_enable_setxid = 1;
70911+#endif
70912+#ifdef CONFIG_GRKERNSEC_SIGNAL
70913+ grsec_enable_signal = 1;
70914+#endif
70915+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70916+ grsec_enable_forkfail = 1;
70917+#endif
70918+#ifdef CONFIG_GRKERNSEC_TIME
70919+ grsec_enable_time = 1;
70920+#endif
70921+#ifdef CONFIG_GRKERNSEC_RESLOG
70922+ grsec_resource_logging = 1;
70923+#endif
70924+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70925+ grsec_enable_chroot_findtask = 1;
70926+#endif
70927+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70928+ grsec_enable_chroot_unix = 1;
70929+#endif
70930+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70931+ grsec_enable_chroot_mount = 1;
70932+#endif
70933+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70934+ grsec_enable_chroot_fchdir = 1;
70935+#endif
70936+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70937+ grsec_enable_chroot_shmat = 1;
70938+#endif
70939+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70940+ grsec_enable_audit_ptrace = 1;
70941+#endif
70942+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
70943+ grsec_enable_chroot_double = 1;
70944+#endif
70945+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
70946+ grsec_enable_chroot_pivot = 1;
70947+#endif
70948+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
70949+ grsec_enable_chroot_chdir = 1;
70950+#endif
70951+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
70952+ grsec_enable_chroot_chmod = 1;
70953+#endif
70954+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
70955+ grsec_enable_chroot_mknod = 1;
70956+#endif
70957+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
70958+ grsec_enable_chroot_nice = 1;
70959+#endif
70960+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
70961+ grsec_enable_chroot_execlog = 1;
70962+#endif
70963+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70964+ grsec_enable_chroot_caps = 1;
70965+#endif
70966+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
70967+ grsec_enable_chroot_sysctl = 1;
70968+#endif
70969+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70970+ grsec_enable_symlinkown = 1;
70971+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
70972+#endif
70973+#ifdef CONFIG_GRKERNSEC_TPE
70974+ grsec_enable_tpe = 1;
70975+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
70976+#ifdef CONFIG_GRKERNSEC_TPE_ALL
70977+ grsec_enable_tpe_all = 1;
70978+#endif
70979+#endif
70980+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70981+ grsec_enable_socket_all = 1;
70982+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
70983+#endif
70984+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70985+ grsec_enable_socket_client = 1;
70986+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
70987+#endif
70988+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70989+ grsec_enable_socket_server = 1;
70990+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
70991+#endif
70992+#endif
70993+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
70994+ grsec_deny_new_usb = 1;
70995+#endif
70996+
70997+ return;
70998+}
70999diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
71000new file mode 100644
71001index 0000000..5e05e20
71002--- /dev/null
71003+++ b/grsecurity/grsec_link.c
71004@@ -0,0 +1,58 @@
71005+#include <linux/kernel.h>
71006+#include <linux/sched.h>
71007+#include <linux/fs.h>
71008+#include <linux/file.h>
71009+#include <linux/grinternal.h>
71010+
71011+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
71012+{
71013+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
71014+ const struct inode *link_inode = link->dentry->d_inode;
71015+
71016+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
71017+ /* ignore root-owned links, e.g. /proc/self */
71018+ gr_is_global_nonroot(link_inode->i_uid) && target &&
71019+ !uid_eq(link_inode->i_uid, target->i_uid)) {
71020+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
71021+ return 1;
71022+ }
71023+#endif
71024+ return 0;
71025+}
71026+
71027+int
71028+gr_handle_follow_link(const struct inode *parent,
71029+ const struct inode *inode,
71030+ const struct dentry *dentry, const struct vfsmount *mnt)
71031+{
71032+#ifdef CONFIG_GRKERNSEC_LINK
71033+ const struct cred *cred = current_cred();
71034+
71035+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
71036+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
71037+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
71038+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
71039+ return -EACCES;
71040+ }
71041+#endif
71042+ return 0;
71043+}
71044+
71045+int
71046+gr_handle_hardlink(const struct dentry *dentry,
71047+ const struct vfsmount *mnt,
71048+ struct inode *inode, const int mode, const struct filename *to)
71049+{
71050+#ifdef CONFIG_GRKERNSEC_LINK
71051+ const struct cred *cred = current_cred();
71052+
71053+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
71054+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
71055+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
71056+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
71057+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
71058+ return -EPERM;
71059+ }
71060+#endif
71061+ return 0;
71062+}
71063diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
71064new file mode 100644
71065index 0000000..dbe0a6b
71066--- /dev/null
71067+++ b/grsecurity/grsec_log.c
71068@@ -0,0 +1,341 @@
71069+#include <linux/kernel.h>
71070+#include <linux/sched.h>
71071+#include <linux/file.h>
71072+#include <linux/tty.h>
71073+#include <linux/fs.h>
71074+#include <linux/mm.h>
71075+#include <linux/grinternal.h>
71076+
71077+#ifdef CONFIG_TREE_PREEMPT_RCU
71078+#define DISABLE_PREEMPT() preempt_disable()
71079+#define ENABLE_PREEMPT() preempt_enable()
71080+#else
71081+#define DISABLE_PREEMPT()
71082+#define ENABLE_PREEMPT()
71083+#endif
71084+
71085+#define BEGIN_LOCKS(x) \
71086+ DISABLE_PREEMPT(); \
71087+ rcu_read_lock(); \
71088+ read_lock(&tasklist_lock); \
71089+ read_lock(&grsec_exec_file_lock); \
71090+ if (x != GR_DO_AUDIT) \
71091+ spin_lock(&grsec_alert_lock); \
71092+ else \
71093+ spin_lock(&grsec_audit_lock)
71094+
71095+#define END_LOCKS(x) \
71096+ if (x != GR_DO_AUDIT) \
71097+ spin_unlock(&grsec_alert_lock); \
71098+ else \
71099+ spin_unlock(&grsec_audit_lock); \
71100+ read_unlock(&grsec_exec_file_lock); \
71101+ read_unlock(&tasklist_lock); \
71102+ rcu_read_unlock(); \
71103+ ENABLE_PREEMPT(); \
71104+ if (x == GR_DONT_AUDIT) \
71105+ gr_handle_alertkill(current)
71106+
71107+enum {
71108+ FLOODING,
71109+ NO_FLOODING
71110+};
71111+
71112+extern char *gr_alert_log_fmt;
71113+extern char *gr_audit_log_fmt;
71114+extern char *gr_alert_log_buf;
71115+extern char *gr_audit_log_buf;
71116+
71117+static int gr_log_start(int audit)
71118+{
71119+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
71120+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
71121+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71122+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
71123+ unsigned long curr_secs = get_seconds();
71124+
71125+ if (audit == GR_DO_AUDIT)
71126+ goto set_fmt;
71127+
71128+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
71129+ grsec_alert_wtime = curr_secs;
71130+ grsec_alert_fyet = 0;
71131+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
71132+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
71133+ grsec_alert_fyet++;
71134+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
71135+ grsec_alert_wtime = curr_secs;
71136+ grsec_alert_fyet++;
71137+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
71138+ return FLOODING;
71139+ }
71140+ else return FLOODING;
71141+
71142+set_fmt:
71143+#endif
71144+ memset(buf, 0, PAGE_SIZE);
71145+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
71146+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
71147+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
71148+ } else if (current->signal->curr_ip) {
71149+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
71150+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
71151+ } else if (gr_acl_is_enabled()) {
71152+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
71153+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
71154+ } else {
71155+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
71156+ strcpy(buf, fmt);
71157+ }
71158+
71159+ return NO_FLOODING;
71160+}
71161+
71162+static void gr_log_middle(int audit, const char *msg, va_list ap)
71163+ __attribute__ ((format (printf, 2, 0)));
71164+
71165+static void gr_log_middle(int audit, const char *msg, va_list ap)
71166+{
71167+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71168+ unsigned int len = strlen(buf);
71169+
71170+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
71171+
71172+ return;
71173+}
71174+
71175+static void gr_log_middle_varargs(int audit, const char *msg, ...)
71176+ __attribute__ ((format (printf, 2, 3)));
71177+
71178+static void gr_log_middle_varargs(int audit, const char *msg, ...)
71179+{
71180+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71181+ unsigned int len = strlen(buf);
71182+ va_list ap;
71183+
71184+ va_start(ap, msg);
71185+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
71186+ va_end(ap);
71187+
71188+ return;
71189+}
71190+
71191+static void gr_log_end(int audit, int append_default)
71192+{
71193+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71194+ if (append_default) {
71195+ struct task_struct *task = current;
71196+ struct task_struct *parent = task->real_parent;
71197+ const struct cred *cred = __task_cred(task);
71198+ const struct cred *pcred = __task_cred(parent);
71199+ unsigned int len = strlen(buf);
71200+
71201+ 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));
71202+ }
71203+
71204+ printk("%s\n", buf);
71205+
71206+ return;
71207+}
71208+
71209+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
71210+{
71211+ int logtype;
71212+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
71213+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
71214+ void *voidptr = NULL;
71215+ int num1 = 0, num2 = 0;
71216+ unsigned long ulong1 = 0, ulong2 = 0;
71217+ struct dentry *dentry = NULL;
71218+ struct vfsmount *mnt = NULL;
71219+ struct file *file = NULL;
71220+ struct task_struct *task = NULL;
71221+ struct vm_area_struct *vma = NULL;
71222+ const struct cred *cred, *pcred;
71223+ va_list ap;
71224+
71225+ BEGIN_LOCKS(audit);
71226+ logtype = gr_log_start(audit);
71227+ if (logtype == FLOODING) {
71228+ END_LOCKS(audit);
71229+ return;
71230+ }
71231+ va_start(ap, argtypes);
71232+ switch (argtypes) {
71233+ case GR_TTYSNIFF:
71234+ task = va_arg(ap, struct task_struct *);
71235+ 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));
71236+ break;
71237+ case GR_SYSCTL_HIDDEN:
71238+ str1 = va_arg(ap, char *);
71239+ gr_log_middle_varargs(audit, msg, result, str1);
71240+ break;
71241+ case GR_RBAC:
71242+ dentry = va_arg(ap, struct dentry *);
71243+ mnt = va_arg(ap, struct vfsmount *);
71244+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
71245+ break;
71246+ case GR_RBAC_STR:
71247+ dentry = va_arg(ap, struct dentry *);
71248+ mnt = va_arg(ap, struct vfsmount *);
71249+ str1 = va_arg(ap, char *);
71250+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
71251+ break;
71252+ case GR_STR_RBAC:
71253+ str1 = va_arg(ap, char *);
71254+ dentry = va_arg(ap, struct dentry *);
71255+ mnt = va_arg(ap, struct vfsmount *);
71256+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
71257+ break;
71258+ case GR_RBAC_MODE2:
71259+ dentry = va_arg(ap, struct dentry *);
71260+ mnt = va_arg(ap, struct vfsmount *);
71261+ str1 = va_arg(ap, char *);
71262+ str2 = va_arg(ap, char *);
71263+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
71264+ break;
71265+ case GR_RBAC_MODE3:
71266+ dentry = va_arg(ap, struct dentry *);
71267+ mnt = va_arg(ap, struct vfsmount *);
71268+ str1 = va_arg(ap, char *);
71269+ str2 = va_arg(ap, char *);
71270+ str3 = va_arg(ap, char *);
71271+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
71272+ break;
71273+ case GR_FILENAME:
71274+ dentry = va_arg(ap, struct dentry *);
71275+ mnt = va_arg(ap, struct vfsmount *);
71276+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
71277+ break;
71278+ case GR_STR_FILENAME:
71279+ str1 = va_arg(ap, char *);
71280+ dentry = va_arg(ap, struct dentry *);
71281+ mnt = va_arg(ap, struct vfsmount *);
71282+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
71283+ break;
71284+ case GR_FILENAME_STR:
71285+ dentry = va_arg(ap, struct dentry *);
71286+ mnt = va_arg(ap, struct vfsmount *);
71287+ str1 = va_arg(ap, char *);
71288+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
71289+ break;
71290+ case GR_FILENAME_TWO_INT:
71291+ dentry = va_arg(ap, struct dentry *);
71292+ mnt = va_arg(ap, struct vfsmount *);
71293+ num1 = va_arg(ap, int);
71294+ num2 = va_arg(ap, int);
71295+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
71296+ break;
71297+ case GR_FILENAME_TWO_INT_STR:
71298+ dentry = va_arg(ap, struct dentry *);
71299+ mnt = va_arg(ap, struct vfsmount *);
71300+ num1 = va_arg(ap, int);
71301+ num2 = va_arg(ap, int);
71302+ str1 = va_arg(ap, char *);
71303+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
71304+ break;
71305+ case GR_TEXTREL:
71306+ file = va_arg(ap, struct file *);
71307+ ulong1 = va_arg(ap, unsigned long);
71308+ ulong2 = va_arg(ap, unsigned long);
71309+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
71310+ break;
71311+ case GR_PTRACE:
71312+ task = va_arg(ap, struct task_struct *);
71313+ 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));
71314+ break;
71315+ case GR_RESOURCE:
71316+ task = va_arg(ap, struct task_struct *);
71317+ cred = __task_cred(task);
71318+ pcred = __task_cred(task->real_parent);
71319+ ulong1 = va_arg(ap, unsigned long);
71320+ str1 = va_arg(ap, char *);
71321+ ulong2 = va_arg(ap, unsigned long);
71322+ 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));
71323+ break;
71324+ case GR_CAP:
71325+ task = va_arg(ap, struct task_struct *);
71326+ cred = __task_cred(task);
71327+ pcred = __task_cred(task->real_parent);
71328+ str1 = va_arg(ap, char *);
71329+ 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));
71330+ break;
71331+ case GR_SIG:
71332+ str1 = va_arg(ap, char *);
71333+ voidptr = va_arg(ap, void *);
71334+ gr_log_middle_varargs(audit, msg, str1, voidptr);
71335+ break;
71336+ case GR_SIG2:
71337+ task = va_arg(ap, struct task_struct *);
71338+ cred = __task_cred(task);
71339+ pcred = __task_cred(task->real_parent);
71340+ num1 = va_arg(ap, int);
71341+ 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));
71342+ break;
71343+ case GR_CRASH1:
71344+ task = va_arg(ap, struct task_struct *);
71345+ cred = __task_cred(task);
71346+ pcred = __task_cred(task->real_parent);
71347+ ulong1 = va_arg(ap, unsigned long);
71348+ 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);
71349+ break;
71350+ case GR_CRASH2:
71351+ task = va_arg(ap, struct task_struct *);
71352+ cred = __task_cred(task);
71353+ pcred = __task_cred(task->real_parent);
71354+ ulong1 = va_arg(ap, unsigned long);
71355+ 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);
71356+ break;
71357+ case GR_RWXMAP:
71358+ file = va_arg(ap, struct file *);
71359+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
71360+ break;
71361+ case GR_RWXMAPVMA:
71362+ vma = va_arg(ap, struct vm_area_struct *);
71363+ if (vma->vm_file)
71364+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
71365+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
71366+ str1 = "<stack>";
71367+ else if (vma->vm_start <= current->mm->brk &&
71368+ vma->vm_end >= current->mm->start_brk)
71369+ str1 = "<heap>";
71370+ else
71371+ str1 = "<anonymous mapping>";
71372+ gr_log_middle_varargs(audit, msg, str1);
71373+ break;
71374+ case GR_PSACCT:
71375+ {
71376+ unsigned int wday, cday;
71377+ __u8 whr, chr;
71378+ __u8 wmin, cmin;
71379+ __u8 wsec, csec;
71380+ char cur_tty[64] = { 0 };
71381+ char parent_tty[64] = { 0 };
71382+
71383+ task = va_arg(ap, struct task_struct *);
71384+ wday = va_arg(ap, unsigned int);
71385+ cday = va_arg(ap, unsigned int);
71386+ whr = va_arg(ap, int);
71387+ chr = va_arg(ap, int);
71388+ wmin = va_arg(ap, int);
71389+ cmin = va_arg(ap, int);
71390+ wsec = va_arg(ap, int);
71391+ csec = va_arg(ap, int);
71392+ ulong1 = va_arg(ap, unsigned long);
71393+ cred = __task_cred(task);
71394+ pcred = __task_cred(task->real_parent);
71395+
71396+ 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));
71397+ }
71398+ break;
71399+ default:
71400+ gr_log_middle(audit, msg, ap);
71401+ }
71402+ va_end(ap);
71403+ // these don't need DEFAULTSECARGS printed on the end
71404+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
71405+ gr_log_end(audit, 0);
71406+ else
71407+ gr_log_end(audit, 1);
71408+ END_LOCKS(audit);
71409+}
71410diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
71411new file mode 100644
71412index 0000000..f536303
71413--- /dev/null
71414+++ b/grsecurity/grsec_mem.c
71415@@ -0,0 +1,40 @@
71416+#include <linux/kernel.h>
71417+#include <linux/sched.h>
71418+#include <linux/mm.h>
71419+#include <linux/mman.h>
71420+#include <linux/grinternal.h>
71421+
71422+void
71423+gr_handle_ioperm(void)
71424+{
71425+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
71426+ return;
71427+}
71428+
71429+void
71430+gr_handle_iopl(void)
71431+{
71432+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
71433+ return;
71434+}
71435+
71436+void
71437+gr_handle_mem_readwrite(u64 from, u64 to)
71438+{
71439+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
71440+ return;
71441+}
71442+
71443+void
71444+gr_handle_vm86(void)
71445+{
71446+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
71447+ return;
71448+}
71449+
71450+void
71451+gr_log_badprocpid(const char *entry)
71452+{
71453+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
71454+ return;
71455+}
71456diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
71457new file mode 100644
71458index 0000000..2131422
71459--- /dev/null
71460+++ b/grsecurity/grsec_mount.c
71461@@ -0,0 +1,62 @@
71462+#include <linux/kernel.h>
71463+#include <linux/sched.h>
71464+#include <linux/mount.h>
71465+#include <linux/grsecurity.h>
71466+#include <linux/grinternal.h>
71467+
71468+void
71469+gr_log_remount(const char *devname, const int retval)
71470+{
71471+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71472+ if (grsec_enable_mount && (retval >= 0))
71473+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
71474+#endif
71475+ return;
71476+}
71477+
71478+void
71479+gr_log_unmount(const char *devname, const int retval)
71480+{
71481+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71482+ if (grsec_enable_mount && (retval >= 0))
71483+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
71484+#endif
71485+ return;
71486+}
71487+
71488+void
71489+gr_log_mount(const char *from, const char *to, const int retval)
71490+{
71491+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71492+ if (grsec_enable_mount && (retval >= 0))
71493+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
71494+#endif
71495+ return;
71496+}
71497+
71498+int
71499+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
71500+{
71501+#ifdef CONFIG_GRKERNSEC_ROFS
71502+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
71503+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
71504+ return -EPERM;
71505+ } else
71506+ return 0;
71507+#endif
71508+ return 0;
71509+}
71510+
71511+int
71512+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
71513+{
71514+#ifdef CONFIG_GRKERNSEC_ROFS
71515+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
71516+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
71517+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
71518+ return -EPERM;
71519+ } else
71520+ return 0;
71521+#endif
71522+ return 0;
71523+}
71524diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
71525new file mode 100644
71526index 0000000..6ee9d50
71527--- /dev/null
71528+++ b/grsecurity/grsec_pax.c
71529@@ -0,0 +1,45 @@
71530+#include <linux/kernel.h>
71531+#include <linux/sched.h>
71532+#include <linux/mm.h>
71533+#include <linux/file.h>
71534+#include <linux/grinternal.h>
71535+#include <linux/grsecurity.h>
71536+
71537+void
71538+gr_log_textrel(struct vm_area_struct * vma)
71539+{
71540+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71541+ if (grsec_enable_log_rwxmaps)
71542+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
71543+#endif
71544+ return;
71545+}
71546+
71547+void gr_log_ptgnustack(struct file *file)
71548+{
71549+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71550+ if (grsec_enable_log_rwxmaps)
71551+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
71552+#endif
71553+ return;
71554+}
71555+
71556+void
71557+gr_log_rwxmmap(struct file *file)
71558+{
71559+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71560+ if (grsec_enable_log_rwxmaps)
71561+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
71562+#endif
71563+ return;
71564+}
71565+
71566+void
71567+gr_log_rwxmprotect(struct vm_area_struct *vma)
71568+{
71569+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71570+ if (grsec_enable_log_rwxmaps)
71571+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
71572+#endif
71573+ return;
71574+}
71575diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
71576new file mode 100644
71577index 0000000..f7f29aa
71578--- /dev/null
71579+++ b/grsecurity/grsec_ptrace.c
71580@@ -0,0 +1,30 @@
71581+#include <linux/kernel.h>
71582+#include <linux/sched.h>
71583+#include <linux/grinternal.h>
71584+#include <linux/security.h>
71585+
71586+void
71587+gr_audit_ptrace(struct task_struct *task)
71588+{
71589+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71590+ if (grsec_enable_audit_ptrace)
71591+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
71592+#endif
71593+ return;
71594+}
71595+
71596+int
71597+gr_ptrace_readexec(struct file *file, int unsafe_flags)
71598+{
71599+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
71600+ const struct dentry *dentry = file->f_path.dentry;
71601+ const struct vfsmount *mnt = file->f_path.mnt;
71602+
71603+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
71604+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
71605+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
71606+ return -EACCES;
71607+ }
71608+#endif
71609+ return 0;
71610+}
71611diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
71612new file mode 100644
71613index 0000000..4e29cc7
71614--- /dev/null
71615+++ b/grsecurity/grsec_sig.c
71616@@ -0,0 +1,246 @@
71617+#include <linux/kernel.h>
71618+#include <linux/sched.h>
71619+#include <linux/fs.h>
71620+#include <linux/delay.h>
71621+#include <linux/grsecurity.h>
71622+#include <linux/grinternal.h>
71623+#include <linux/hardirq.h>
71624+
71625+char *signames[] = {
71626+ [SIGSEGV] = "Segmentation fault",
71627+ [SIGILL] = "Illegal instruction",
71628+ [SIGABRT] = "Abort",
71629+ [SIGBUS] = "Invalid alignment/Bus error"
71630+};
71631+
71632+void
71633+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
71634+{
71635+#ifdef CONFIG_GRKERNSEC_SIGNAL
71636+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
71637+ (sig == SIGABRT) || (sig == SIGBUS))) {
71638+ if (task_pid_nr(t) == task_pid_nr(current)) {
71639+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
71640+ } else {
71641+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
71642+ }
71643+ }
71644+#endif
71645+ return;
71646+}
71647+
71648+int
71649+gr_handle_signal(const struct task_struct *p, const int sig)
71650+{
71651+#ifdef CONFIG_GRKERNSEC
71652+ /* ignore the 0 signal for protected task checks */
71653+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
71654+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
71655+ return -EPERM;
71656+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
71657+ return -EPERM;
71658+ }
71659+#endif
71660+ return 0;
71661+}
71662+
71663+#ifdef CONFIG_GRKERNSEC
71664+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
71665+
71666+int gr_fake_force_sig(int sig, struct task_struct *t)
71667+{
71668+ unsigned long int flags;
71669+ int ret, blocked, ignored;
71670+ struct k_sigaction *action;
71671+
71672+ spin_lock_irqsave(&t->sighand->siglock, flags);
71673+ action = &t->sighand->action[sig-1];
71674+ ignored = action->sa.sa_handler == SIG_IGN;
71675+ blocked = sigismember(&t->blocked, sig);
71676+ if (blocked || ignored) {
71677+ action->sa.sa_handler = SIG_DFL;
71678+ if (blocked) {
71679+ sigdelset(&t->blocked, sig);
71680+ recalc_sigpending_and_wake(t);
71681+ }
71682+ }
71683+ if (action->sa.sa_handler == SIG_DFL)
71684+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
71685+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
71686+
71687+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
71688+
71689+ return ret;
71690+}
71691+#endif
71692+
71693+#ifdef CONFIG_GRKERNSEC_BRUTE
71694+#define GR_USER_BAN_TIME (15 * 60)
71695+#define GR_DAEMON_BRUTE_TIME (30 * 60)
71696+
71697+static int __get_dumpable(unsigned long mm_flags)
71698+{
71699+ int ret;
71700+
71701+ ret = mm_flags & MMF_DUMPABLE_MASK;
71702+ return (ret >= 2) ? 2 : ret;
71703+}
71704+#endif
71705+
71706+void gr_handle_brute_attach(unsigned long mm_flags)
71707+{
71708+#ifdef CONFIG_GRKERNSEC_BRUTE
71709+ struct task_struct *p = current;
71710+ kuid_t uid = GLOBAL_ROOT_UID;
71711+ int daemon = 0;
71712+
71713+ if (!grsec_enable_brute)
71714+ return;
71715+
71716+ rcu_read_lock();
71717+ read_lock(&tasklist_lock);
71718+ read_lock(&grsec_exec_file_lock);
71719+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
71720+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
71721+ p->real_parent->brute = 1;
71722+ daemon = 1;
71723+ } else {
71724+ const struct cred *cred = __task_cred(p), *cred2;
71725+ struct task_struct *tsk, *tsk2;
71726+
71727+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
71728+ struct user_struct *user;
71729+
71730+ uid = cred->uid;
71731+
71732+ /* this is put upon execution past expiration */
71733+ user = find_user(uid);
71734+ if (user == NULL)
71735+ goto unlock;
71736+ user->suid_banned = 1;
71737+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
71738+ if (user->suid_ban_expires == ~0UL)
71739+ user->suid_ban_expires--;
71740+
71741+ /* only kill other threads of the same binary, from the same user */
71742+ do_each_thread(tsk2, tsk) {
71743+ cred2 = __task_cred(tsk);
71744+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
71745+ gr_fake_force_sig(SIGKILL, tsk);
71746+ } while_each_thread(tsk2, tsk);
71747+ }
71748+ }
71749+unlock:
71750+ read_unlock(&grsec_exec_file_lock);
71751+ read_unlock(&tasklist_lock);
71752+ rcu_read_unlock();
71753+
71754+ if (gr_is_global_nonroot(uid))
71755+ 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);
71756+ else if (daemon)
71757+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
71758+
71759+#endif
71760+ return;
71761+}
71762+
71763+void gr_handle_brute_check(void)
71764+{
71765+#ifdef CONFIG_GRKERNSEC_BRUTE
71766+ struct task_struct *p = current;
71767+
71768+ if (unlikely(p->brute)) {
71769+ if (!grsec_enable_brute)
71770+ p->brute = 0;
71771+ else if (time_before(get_seconds(), p->brute_expires))
71772+ msleep(30 * 1000);
71773+ }
71774+#endif
71775+ return;
71776+}
71777+
71778+void gr_handle_kernel_exploit(void)
71779+{
71780+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71781+ const struct cred *cred;
71782+ struct task_struct *tsk, *tsk2;
71783+ struct user_struct *user;
71784+ kuid_t uid;
71785+
71786+ if (in_irq() || in_serving_softirq() || in_nmi())
71787+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
71788+
71789+ uid = current_uid();
71790+
71791+ if (gr_is_global_root(uid))
71792+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
71793+ else {
71794+ /* kill all the processes of this user, hold a reference
71795+ to their creds struct, and prevent them from creating
71796+ another process until system reset
71797+ */
71798+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
71799+ GR_GLOBAL_UID(uid));
71800+ /* we intentionally leak this ref */
71801+ user = get_uid(current->cred->user);
71802+ if (user)
71803+ user->kernel_banned = 1;
71804+
71805+ /* kill all processes of this user */
71806+ read_lock(&tasklist_lock);
71807+ do_each_thread(tsk2, tsk) {
71808+ cred = __task_cred(tsk);
71809+ if (uid_eq(cred->uid, uid))
71810+ gr_fake_force_sig(SIGKILL, tsk);
71811+ } while_each_thread(tsk2, tsk);
71812+ read_unlock(&tasklist_lock);
71813+ }
71814+#endif
71815+}
71816+
71817+#ifdef CONFIG_GRKERNSEC_BRUTE
71818+static bool suid_ban_expired(struct user_struct *user)
71819+{
71820+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
71821+ user->suid_banned = 0;
71822+ user->suid_ban_expires = 0;
71823+ free_uid(user);
71824+ return true;
71825+ }
71826+
71827+ return false;
71828+}
71829+#endif
71830+
71831+int gr_process_kernel_exec_ban(void)
71832+{
71833+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71834+ if (unlikely(current->cred->user->kernel_banned))
71835+ return -EPERM;
71836+#endif
71837+ return 0;
71838+}
71839+
71840+int gr_process_kernel_setuid_ban(struct user_struct *user)
71841+{
71842+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71843+ if (unlikely(user->kernel_banned))
71844+ gr_fake_force_sig(SIGKILL, current);
71845+#endif
71846+ return 0;
71847+}
71848+
71849+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
71850+{
71851+#ifdef CONFIG_GRKERNSEC_BRUTE
71852+ struct user_struct *user = current->cred->user;
71853+ if (unlikely(user->suid_banned)) {
71854+ if (suid_ban_expired(user))
71855+ return 0;
71856+ /* disallow execution of suid binaries only */
71857+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
71858+ return -EPERM;
71859+ }
71860+#endif
71861+ return 0;
71862+}
71863diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
71864new file mode 100644
71865index 0000000..4030d57
71866--- /dev/null
71867+++ b/grsecurity/grsec_sock.c
71868@@ -0,0 +1,244 @@
71869+#include <linux/kernel.h>
71870+#include <linux/module.h>
71871+#include <linux/sched.h>
71872+#include <linux/file.h>
71873+#include <linux/net.h>
71874+#include <linux/in.h>
71875+#include <linux/ip.h>
71876+#include <net/sock.h>
71877+#include <net/inet_sock.h>
71878+#include <linux/grsecurity.h>
71879+#include <linux/grinternal.h>
71880+#include <linux/gracl.h>
71881+
71882+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
71883+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
71884+
71885+EXPORT_SYMBOL(gr_search_udp_recvmsg);
71886+EXPORT_SYMBOL(gr_search_udp_sendmsg);
71887+
71888+#ifdef CONFIG_UNIX_MODULE
71889+EXPORT_SYMBOL(gr_acl_handle_unix);
71890+EXPORT_SYMBOL(gr_acl_handle_mknod);
71891+EXPORT_SYMBOL(gr_handle_chroot_unix);
71892+EXPORT_SYMBOL(gr_handle_create);
71893+#endif
71894+
71895+#ifdef CONFIG_GRKERNSEC
71896+#define gr_conn_table_size 32749
71897+struct conn_table_entry {
71898+ struct conn_table_entry *next;
71899+ struct signal_struct *sig;
71900+};
71901+
71902+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
71903+DEFINE_SPINLOCK(gr_conn_table_lock);
71904+
71905+extern const char * gr_socktype_to_name(unsigned char type);
71906+extern const char * gr_proto_to_name(unsigned char proto);
71907+extern const char * gr_sockfamily_to_name(unsigned char family);
71908+
71909+static __inline__ int
71910+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
71911+{
71912+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
71913+}
71914+
71915+static __inline__ int
71916+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
71917+ __u16 sport, __u16 dport)
71918+{
71919+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
71920+ sig->gr_sport == sport && sig->gr_dport == dport))
71921+ return 1;
71922+ else
71923+ return 0;
71924+}
71925+
71926+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
71927+{
71928+ struct conn_table_entry **match;
71929+ unsigned int index;
71930+
71931+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
71932+ sig->gr_sport, sig->gr_dport,
71933+ gr_conn_table_size);
71934+
71935+ newent->sig = sig;
71936+
71937+ match = &gr_conn_table[index];
71938+ newent->next = *match;
71939+ *match = newent;
71940+
71941+ return;
71942+}
71943+
71944+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
71945+{
71946+ struct conn_table_entry *match, *last = NULL;
71947+ unsigned int index;
71948+
71949+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
71950+ sig->gr_sport, sig->gr_dport,
71951+ gr_conn_table_size);
71952+
71953+ match = gr_conn_table[index];
71954+ while (match && !conn_match(match->sig,
71955+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
71956+ sig->gr_dport)) {
71957+ last = match;
71958+ match = match->next;
71959+ }
71960+
71961+ if (match) {
71962+ if (last)
71963+ last->next = match->next;
71964+ else
71965+ gr_conn_table[index] = NULL;
71966+ kfree(match);
71967+ }
71968+
71969+ return;
71970+}
71971+
71972+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
71973+ __u16 sport, __u16 dport)
71974+{
71975+ struct conn_table_entry *match;
71976+ unsigned int index;
71977+
71978+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
71979+
71980+ match = gr_conn_table[index];
71981+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
71982+ match = match->next;
71983+
71984+ if (match)
71985+ return match->sig;
71986+ else
71987+ return NULL;
71988+}
71989+
71990+#endif
71991+
71992+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
71993+{
71994+#ifdef CONFIG_GRKERNSEC
71995+ struct signal_struct *sig = task->signal;
71996+ struct conn_table_entry *newent;
71997+
71998+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
71999+ if (newent == NULL)
72000+ return;
72001+ /* no bh lock needed since we are called with bh disabled */
72002+ spin_lock(&gr_conn_table_lock);
72003+ gr_del_task_from_ip_table_nolock(sig);
72004+ sig->gr_saddr = inet->inet_rcv_saddr;
72005+ sig->gr_daddr = inet->inet_daddr;
72006+ sig->gr_sport = inet->inet_sport;
72007+ sig->gr_dport = inet->inet_dport;
72008+ gr_add_to_task_ip_table_nolock(sig, newent);
72009+ spin_unlock(&gr_conn_table_lock);
72010+#endif
72011+ return;
72012+}
72013+
72014+void gr_del_task_from_ip_table(struct task_struct *task)
72015+{
72016+#ifdef CONFIG_GRKERNSEC
72017+ spin_lock_bh(&gr_conn_table_lock);
72018+ gr_del_task_from_ip_table_nolock(task->signal);
72019+ spin_unlock_bh(&gr_conn_table_lock);
72020+#endif
72021+ return;
72022+}
72023+
72024+void
72025+gr_attach_curr_ip(const struct sock *sk)
72026+{
72027+#ifdef CONFIG_GRKERNSEC
72028+ struct signal_struct *p, *set;
72029+ const struct inet_sock *inet = inet_sk(sk);
72030+
72031+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
72032+ return;
72033+
72034+ set = current->signal;
72035+
72036+ spin_lock_bh(&gr_conn_table_lock);
72037+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
72038+ inet->inet_dport, inet->inet_sport);
72039+ if (unlikely(p != NULL)) {
72040+ set->curr_ip = p->curr_ip;
72041+ set->used_accept = 1;
72042+ gr_del_task_from_ip_table_nolock(p);
72043+ spin_unlock_bh(&gr_conn_table_lock);
72044+ return;
72045+ }
72046+ spin_unlock_bh(&gr_conn_table_lock);
72047+
72048+ set->curr_ip = inet->inet_daddr;
72049+ set->used_accept = 1;
72050+#endif
72051+ return;
72052+}
72053+
72054+int
72055+gr_handle_sock_all(const int family, const int type, const int protocol)
72056+{
72057+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
72058+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
72059+ (family != AF_UNIX)) {
72060+ if (family == AF_INET)
72061+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
72062+ else
72063+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
72064+ return -EACCES;
72065+ }
72066+#endif
72067+ return 0;
72068+}
72069+
72070+int
72071+gr_handle_sock_server(const struct sockaddr *sck)
72072+{
72073+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72074+ if (grsec_enable_socket_server &&
72075+ in_group_p(grsec_socket_server_gid) &&
72076+ sck && (sck->sa_family != AF_UNIX) &&
72077+ (sck->sa_family != AF_LOCAL)) {
72078+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
72079+ return -EACCES;
72080+ }
72081+#endif
72082+ return 0;
72083+}
72084+
72085+int
72086+gr_handle_sock_server_other(const struct sock *sck)
72087+{
72088+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72089+ if (grsec_enable_socket_server &&
72090+ in_group_p(grsec_socket_server_gid) &&
72091+ sck && (sck->sk_family != AF_UNIX) &&
72092+ (sck->sk_family != AF_LOCAL)) {
72093+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
72094+ return -EACCES;
72095+ }
72096+#endif
72097+ return 0;
72098+}
72099+
72100+int
72101+gr_handle_sock_client(const struct sockaddr *sck)
72102+{
72103+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
72104+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
72105+ sck && (sck->sa_family != AF_UNIX) &&
72106+ (sck->sa_family != AF_LOCAL)) {
72107+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
72108+ return -EACCES;
72109+ }
72110+#endif
72111+ return 0;
72112+}
72113diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
72114new file mode 100644
72115index 0000000..a147ae7
72116--- /dev/null
72117+++ b/grsecurity/grsec_sysctl.c
72118@@ -0,0 +1,470 @@
72119+#include <linux/kernel.h>
72120+#include <linux/sched.h>
72121+#include <linux/sysctl.h>
72122+#include <linux/grsecurity.h>
72123+#include <linux/grinternal.h>
72124+
72125+int
72126+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
72127+{
72128+#ifdef CONFIG_GRKERNSEC_SYSCTL
72129+ if (dirname == NULL || name == NULL)
72130+ return 0;
72131+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
72132+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
72133+ return -EACCES;
72134+ }
72135+#endif
72136+ return 0;
72137+}
72138+
72139+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
72140+static int __maybe_unused __read_only one = 1;
72141+#endif
72142+
72143+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
72144+ defined(CONFIG_GRKERNSEC_DENYUSB)
72145+struct ctl_table grsecurity_table[] = {
72146+#ifdef CONFIG_GRKERNSEC_SYSCTL
72147+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
72148+#ifdef CONFIG_GRKERNSEC_IO
72149+ {
72150+ .procname = "disable_priv_io",
72151+ .data = &grsec_disable_privio,
72152+ .maxlen = sizeof(int),
72153+ .mode = 0600,
72154+ .proc_handler = &proc_dointvec,
72155+ },
72156+#endif
72157+#endif
72158+#ifdef CONFIG_GRKERNSEC_LINK
72159+ {
72160+ .procname = "linking_restrictions",
72161+ .data = &grsec_enable_link,
72162+ .maxlen = sizeof(int),
72163+ .mode = 0600,
72164+ .proc_handler = &proc_dointvec,
72165+ },
72166+#endif
72167+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
72168+ {
72169+ .procname = "enforce_symlinksifowner",
72170+ .data = &grsec_enable_symlinkown,
72171+ .maxlen = sizeof(int),
72172+ .mode = 0600,
72173+ .proc_handler = &proc_dointvec,
72174+ },
72175+ {
72176+ .procname = "symlinkown_gid",
72177+ .data = &grsec_symlinkown_gid,
72178+ .maxlen = sizeof(int),
72179+ .mode = 0600,
72180+ .proc_handler = &proc_dointvec,
72181+ },
72182+#endif
72183+#ifdef CONFIG_GRKERNSEC_BRUTE
72184+ {
72185+ .procname = "deter_bruteforce",
72186+ .data = &grsec_enable_brute,
72187+ .maxlen = sizeof(int),
72188+ .mode = 0600,
72189+ .proc_handler = &proc_dointvec,
72190+ },
72191+#endif
72192+#ifdef CONFIG_GRKERNSEC_FIFO
72193+ {
72194+ .procname = "fifo_restrictions",
72195+ .data = &grsec_enable_fifo,
72196+ .maxlen = sizeof(int),
72197+ .mode = 0600,
72198+ .proc_handler = &proc_dointvec,
72199+ },
72200+#endif
72201+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
72202+ {
72203+ .procname = "ptrace_readexec",
72204+ .data = &grsec_enable_ptrace_readexec,
72205+ .maxlen = sizeof(int),
72206+ .mode = 0600,
72207+ .proc_handler = &proc_dointvec,
72208+ },
72209+#endif
72210+#ifdef CONFIG_GRKERNSEC_SETXID
72211+ {
72212+ .procname = "consistent_setxid",
72213+ .data = &grsec_enable_setxid,
72214+ .maxlen = sizeof(int),
72215+ .mode = 0600,
72216+ .proc_handler = &proc_dointvec,
72217+ },
72218+#endif
72219+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72220+ {
72221+ .procname = "ip_blackhole",
72222+ .data = &grsec_enable_blackhole,
72223+ .maxlen = sizeof(int),
72224+ .mode = 0600,
72225+ .proc_handler = &proc_dointvec,
72226+ },
72227+ {
72228+ .procname = "lastack_retries",
72229+ .data = &grsec_lastack_retries,
72230+ .maxlen = sizeof(int),
72231+ .mode = 0600,
72232+ .proc_handler = &proc_dointvec,
72233+ },
72234+#endif
72235+#ifdef CONFIG_GRKERNSEC_EXECLOG
72236+ {
72237+ .procname = "exec_logging",
72238+ .data = &grsec_enable_execlog,
72239+ .maxlen = sizeof(int),
72240+ .mode = 0600,
72241+ .proc_handler = &proc_dointvec,
72242+ },
72243+#endif
72244+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72245+ {
72246+ .procname = "rwxmap_logging",
72247+ .data = &grsec_enable_log_rwxmaps,
72248+ .maxlen = sizeof(int),
72249+ .mode = 0600,
72250+ .proc_handler = &proc_dointvec,
72251+ },
72252+#endif
72253+#ifdef CONFIG_GRKERNSEC_SIGNAL
72254+ {
72255+ .procname = "signal_logging",
72256+ .data = &grsec_enable_signal,
72257+ .maxlen = sizeof(int),
72258+ .mode = 0600,
72259+ .proc_handler = &proc_dointvec,
72260+ },
72261+#endif
72262+#ifdef CONFIG_GRKERNSEC_FORKFAIL
72263+ {
72264+ .procname = "forkfail_logging",
72265+ .data = &grsec_enable_forkfail,
72266+ .maxlen = sizeof(int),
72267+ .mode = 0600,
72268+ .proc_handler = &proc_dointvec,
72269+ },
72270+#endif
72271+#ifdef CONFIG_GRKERNSEC_TIME
72272+ {
72273+ .procname = "timechange_logging",
72274+ .data = &grsec_enable_time,
72275+ .maxlen = sizeof(int),
72276+ .mode = 0600,
72277+ .proc_handler = &proc_dointvec,
72278+ },
72279+#endif
72280+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72281+ {
72282+ .procname = "chroot_deny_shmat",
72283+ .data = &grsec_enable_chroot_shmat,
72284+ .maxlen = sizeof(int),
72285+ .mode = 0600,
72286+ .proc_handler = &proc_dointvec,
72287+ },
72288+#endif
72289+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72290+ {
72291+ .procname = "chroot_deny_unix",
72292+ .data = &grsec_enable_chroot_unix,
72293+ .maxlen = sizeof(int),
72294+ .mode = 0600,
72295+ .proc_handler = &proc_dointvec,
72296+ },
72297+#endif
72298+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72299+ {
72300+ .procname = "chroot_deny_mount",
72301+ .data = &grsec_enable_chroot_mount,
72302+ .maxlen = sizeof(int),
72303+ .mode = 0600,
72304+ .proc_handler = &proc_dointvec,
72305+ },
72306+#endif
72307+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72308+ {
72309+ .procname = "chroot_deny_fchdir",
72310+ .data = &grsec_enable_chroot_fchdir,
72311+ .maxlen = sizeof(int),
72312+ .mode = 0600,
72313+ .proc_handler = &proc_dointvec,
72314+ },
72315+#endif
72316+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72317+ {
72318+ .procname = "chroot_deny_chroot",
72319+ .data = &grsec_enable_chroot_double,
72320+ .maxlen = sizeof(int),
72321+ .mode = 0600,
72322+ .proc_handler = &proc_dointvec,
72323+ },
72324+#endif
72325+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72326+ {
72327+ .procname = "chroot_deny_pivot",
72328+ .data = &grsec_enable_chroot_pivot,
72329+ .maxlen = sizeof(int),
72330+ .mode = 0600,
72331+ .proc_handler = &proc_dointvec,
72332+ },
72333+#endif
72334+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
72335+ {
72336+ .procname = "chroot_enforce_chdir",
72337+ .data = &grsec_enable_chroot_chdir,
72338+ .maxlen = sizeof(int),
72339+ .mode = 0600,
72340+ .proc_handler = &proc_dointvec,
72341+ },
72342+#endif
72343+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
72344+ {
72345+ .procname = "chroot_deny_chmod",
72346+ .data = &grsec_enable_chroot_chmod,
72347+ .maxlen = sizeof(int),
72348+ .mode = 0600,
72349+ .proc_handler = &proc_dointvec,
72350+ },
72351+#endif
72352+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72353+ {
72354+ .procname = "chroot_deny_mknod",
72355+ .data = &grsec_enable_chroot_mknod,
72356+ .maxlen = sizeof(int),
72357+ .mode = 0600,
72358+ .proc_handler = &proc_dointvec,
72359+ },
72360+#endif
72361+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72362+ {
72363+ .procname = "chroot_restrict_nice",
72364+ .data = &grsec_enable_chroot_nice,
72365+ .maxlen = sizeof(int),
72366+ .mode = 0600,
72367+ .proc_handler = &proc_dointvec,
72368+ },
72369+#endif
72370+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72371+ {
72372+ .procname = "chroot_execlog",
72373+ .data = &grsec_enable_chroot_execlog,
72374+ .maxlen = sizeof(int),
72375+ .mode = 0600,
72376+ .proc_handler = &proc_dointvec,
72377+ },
72378+#endif
72379+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72380+ {
72381+ .procname = "chroot_caps",
72382+ .data = &grsec_enable_chroot_caps,
72383+ .maxlen = sizeof(int),
72384+ .mode = 0600,
72385+ .proc_handler = &proc_dointvec,
72386+ },
72387+#endif
72388+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
72389+ {
72390+ .procname = "chroot_deny_sysctl",
72391+ .data = &grsec_enable_chroot_sysctl,
72392+ .maxlen = sizeof(int),
72393+ .mode = 0600,
72394+ .proc_handler = &proc_dointvec,
72395+ },
72396+#endif
72397+#ifdef CONFIG_GRKERNSEC_TPE
72398+ {
72399+ .procname = "tpe",
72400+ .data = &grsec_enable_tpe,
72401+ .maxlen = sizeof(int),
72402+ .mode = 0600,
72403+ .proc_handler = &proc_dointvec,
72404+ },
72405+ {
72406+ .procname = "tpe_gid",
72407+ .data = &grsec_tpe_gid,
72408+ .maxlen = sizeof(int),
72409+ .mode = 0600,
72410+ .proc_handler = &proc_dointvec,
72411+ },
72412+#endif
72413+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
72414+ {
72415+ .procname = "tpe_invert",
72416+ .data = &grsec_enable_tpe_invert,
72417+ .maxlen = sizeof(int),
72418+ .mode = 0600,
72419+ .proc_handler = &proc_dointvec,
72420+ },
72421+#endif
72422+#ifdef CONFIG_GRKERNSEC_TPE_ALL
72423+ {
72424+ .procname = "tpe_restrict_all",
72425+ .data = &grsec_enable_tpe_all,
72426+ .maxlen = sizeof(int),
72427+ .mode = 0600,
72428+ .proc_handler = &proc_dointvec,
72429+ },
72430+#endif
72431+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
72432+ {
72433+ .procname = "socket_all",
72434+ .data = &grsec_enable_socket_all,
72435+ .maxlen = sizeof(int),
72436+ .mode = 0600,
72437+ .proc_handler = &proc_dointvec,
72438+ },
72439+ {
72440+ .procname = "socket_all_gid",
72441+ .data = &grsec_socket_all_gid,
72442+ .maxlen = sizeof(int),
72443+ .mode = 0600,
72444+ .proc_handler = &proc_dointvec,
72445+ },
72446+#endif
72447+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
72448+ {
72449+ .procname = "socket_client",
72450+ .data = &grsec_enable_socket_client,
72451+ .maxlen = sizeof(int),
72452+ .mode = 0600,
72453+ .proc_handler = &proc_dointvec,
72454+ },
72455+ {
72456+ .procname = "socket_client_gid",
72457+ .data = &grsec_socket_client_gid,
72458+ .maxlen = sizeof(int),
72459+ .mode = 0600,
72460+ .proc_handler = &proc_dointvec,
72461+ },
72462+#endif
72463+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72464+ {
72465+ .procname = "socket_server",
72466+ .data = &grsec_enable_socket_server,
72467+ .maxlen = sizeof(int),
72468+ .mode = 0600,
72469+ .proc_handler = &proc_dointvec,
72470+ },
72471+ {
72472+ .procname = "socket_server_gid",
72473+ .data = &grsec_socket_server_gid,
72474+ .maxlen = sizeof(int),
72475+ .mode = 0600,
72476+ .proc_handler = &proc_dointvec,
72477+ },
72478+#endif
72479+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
72480+ {
72481+ .procname = "audit_group",
72482+ .data = &grsec_enable_group,
72483+ .maxlen = sizeof(int),
72484+ .mode = 0600,
72485+ .proc_handler = &proc_dointvec,
72486+ },
72487+ {
72488+ .procname = "audit_gid",
72489+ .data = &grsec_audit_gid,
72490+ .maxlen = sizeof(int),
72491+ .mode = 0600,
72492+ .proc_handler = &proc_dointvec,
72493+ },
72494+#endif
72495+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72496+ {
72497+ .procname = "audit_chdir",
72498+ .data = &grsec_enable_chdir,
72499+ .maxlen = sizeof(int),
72500+ .mode = 0600,
72501+ .proc_handler = &proc_dointvec,
72502+ },
72503+#endif
72504+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
72505+ {
72506+ .procname = "audit_mount",
72507+ .data = &grsec_enable_mount,
72508+ .maxlen = sizeof(int),
72509+ .mode = 0600,
72510+ .proc_handler = &proc_dointvec,
72511+ },
72512+#endif
72513+#ifdef CONFIG_GRKERNSEC_DMESG
72514+ {
72515+ .procname = "dmesg",
72516+ .data = &grsec_enable_dmesg,
72517+ .maxlen = sizeof(int),
72518+ .mode = 0600,
72519+ .proc_handler = &proc_dointvec,
72520+ },
72521+#endif
72522+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72523+ {
72524+ .procname = "chroot_findtask",
72525+ .data = &grsec_enable_chroot_findtask,
72526+ .maxlen = sizeof(int),
72527+ .mode = 0600,
72528+ .proc_handler = &proc_dointvec,
72529+ },
72530+#endif
72531+#ifdef CONFIG_GRKERNSEC_RESLOG
72532+ {
72533+ .procname = "resource_logging",
72534+ .data = &grsec_resource_logging,
72535+ .maxlen = sizeof(int),
72536+ .mode = 0600,
72537+ .proc_handler = &proc_dointvec,
72538+ },
72539+#endif
72540+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
72541+ {
72542+ .procname = "audit_ptrace",
72543+ .data = &grsec_enable_audit_ptrace,
72544+ .maxlen = sizeof(int),
72545+ .mode = 0600,
72546+ .proc_handler = &proc_dointvec,
72547+ },
72548+#endif
72549+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72550+ {
72551+ .procname = "harden_ptrace",
72552+ .data = &grsec_enable_harden_ptrace,
72553+ .maxlen = sizeof(int),
72554+ .mode = 0600,
72555+ .proc_handler = &proc_dointvec,
72556+ },
72557+#endif
72558+ {
72559+ .procname = "grsec_lock",
72560+ .data = &grsec_lock,
72561+ .maxlen = sizeof(int),
72562+ .mode = 0600,
72563+ .proc_handler = &proc_dointvec,
72564+ },
72565+#endif
72566+#ifdef CONFIG_GRKERNSEC_ROFS
72567+ {
72568+ .procname = "romount_protect",
72569+ .data = &grsec_enable_rofs,
72570+ .maxlen = sizeof(int),
72571+ .mode = 0600,
72572+ .proc_handler = &proc_dointvec_minmax,
72573+ .extra1 = &one,
72574+ .extra2 = &one,
72575+ },
72576+#endif
72577+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
72578+ {
72579+ .procname = "deny_new_usb",
72580+ .data = &grsec_deny_new_usb,
72581+ .maxlen = sizeof(int),
72582+ .mode = 0600,
72583+ .proc_handler = &proc_dointvec,
72584+ },
72585+#endif
72586+ { }
72587+};
72588+#endif
72589diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
72590new file mode 100644
72591index 0000000..0dc13c3
72592--- /dev/null
72593+++ b/grsecurity/grsec_time.c
72594@@ -0,0 +1,16 @@
72595+#include <linux/kernel.h>
72596+#include <linux/sched.h>
72597+#include <linux/grinternal.h>
72598+#include <linux/module.h>
72599+
72600+void
72601+gr_log_timechange(void)
72602+{
72603+#ifdef CONFIG_GRKERNSEC_TIME
72604+ if (grsec_enable_time)
72605+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
72606+#endif
72607+ return;
72608+}
72609+
72610+EXPORT_SYMBOL(gr_log_timechange);
72611diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
72612new file mode 100644
72613index 0000000..ee57dcf
72614--- /dev/null
72615+++ b/grsecurity/grsec_tpe.c
72616@@ -0,0 +1,73 @@
72617+#include <linux/kernel.h>
72618+#include <linux/sched.h>
72619+#include <linux/file.h>
72620+#include <linux/fs.h>
72621+#include <linux/grinternal.h>
72622+
72623+extern int gr_acl_tpe_check(void);
72624+
72625+int
72626+gr_tpe_allow(const struct file *file)
72627+{
72628+#ifdef CONFIG_GRKERNSEC
72629+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
72630+ const struct cred *cred = current_cred();
72631+ char *msg = NULL;
72632+ char *msg2 = NULL;
72633+
72634+ // never restrict root
72635+ if (gr_is_global_root(cred->uid))
72636+ return 1;
72637+
72638+ if (grsec_enable_tpe) {
72639+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
72640+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
72641+ msg = "not being in trusted group";
72642+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
72643+ msg = "being in untrusted group";
72644+#else
72645+ if (in_group_p(grsec_tpe_gid))
72646+ msg = "being in untrusted group";
72647+#endif
72648+ }
72649+ if (!msg && gr_acl_tpe_check())
72650+ msg = "being in untrusted role";
72651+
72652+ // not in any affected group/role
72653+ if (!msg)
72654+ goto next_check;
72655+
72656+ if (gr_is_global_nonroot(inode->i_uid))
72657+ msg2 = "file in non-root-owned directory";
72658+ else if (inode->i_mode & S_IWOTH)
72659+ msg2 = "file in world-writable directory";
72660+ else if (inode->i_mode & S_IWGRP)
72661+ msg2 = "file in group-writable directory";
72662+
72663+ if (msg && msg2) {
72664+ char fullmsg[70] = {0};
72665+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
72666+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
72667+ return 0;
72668+ }
72669+ msg = NULL;
72670+next_check:
72671+#ifdef CONFIG_GRKERNSEC_TPE_ALL
72672+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
72673+ return 1;
72674+
72675+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
72676+ msg = "directory not owned by user";
72677+ else if (inode->i_mode & S_IWOTH)
72678+ msg = "file in world-writable directory";
72679+ else if (inode->i_mode & S_IWGRP)
72680+ msg = "file in group-writable directory";
72681+
72682+ if (msg) {
72683+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
72684+ return 0;
72685+ }
72686+#endif
72687+#endif
72688+ return 1;
72689+}
72690diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
72691new file mode 100644
72692index 0000000..ae02d8e
72693--- /dev/null
72694+++ b/grsecurity/grsec_usb.c
72695@@ -0,0 +1,15 @@
72696+#include <linux/kernel.h>
72697+#include <linux/grinternal.h>
72698+#include <linux/module.h>
72699+
72700+int gr_handle_new_usb(void)
72701+{
72702+#ifdef CONFIG_GRKERNSEC_DENYUSB
72703+ if (grsec_deny_new_usb) {
72704+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
72705+ return 1;
72706+ }
72707+#endif
72708+ return 0;
72709+}
72710+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
72711diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
72712new file mode 100644
72713index 0000000..9f7b1ac
72714--- /dev/null
72715+++ b/grsecurity/grsum.c
72716@@ -0,0 +1,61 @@
72717+#include <linux/err.h>
72718+#include <linux/kernel.h>
72719+#include <linux/sched.h>
72720+#include <linux/mm.h>
72721+#include <linux/scatterlist.h>
72722+#include <linux/crypto.h>
72723+#include <linux/gracl.h>
72724+
72725+
72726+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
72727+#error "crypto and sha256 must be built into the kernel"
72728+#endif
72729+
72730+int
72731+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
72732+{
72733+ char *p;
72734+ struct crypto_hash *tfm;
72735+ struct hash_desc desc;
72736+ struct scatterlist sg;
72737+ unsigned char temp_sum[GR_SHA_LEN];
72738+ volatile int retval = 0;
72739+ volatile int dummy = 0;
72740+ unsigned int i;
72741+
72742+ sg_init_table(&sg, 1);
72743+
72744+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
72745+ if (IS_ERR(tfm)) {
72746+ /* should never happen, since sha256 should be built in */
72747+ return 1;
72748+ }
72749+
72750+ desc.tfm = tfm;
72751+ desc.flags = 0;
72752+
72753+ crypto_hash_init(&desc);
72754+
72755+ p = salt;
72756+ sg_set_buf(&sg, p, GR_SALT_LEN);
72757+ crypto_hash_update(&desc, &sg, sg.length);
72758+
72759+ p = entry->pw;
72760+ sg_set_buf(&sg, p, strlen(p));
72761+
72762+ crypto_hash_update(&desc, &sg, sg.length);
72763+
72764+ crypto_hash_final(&desc, temp_sum);
72765+
72766+ memset(entry->pw, 0, GR_PW_LEN);
72767+
72768+ for (i = 0; i < GR_SHA_LEN; i++)
72769+ if (sum[i] != temp_sum[i])
72770+ retval = 1;
72771+ else
72772+ dummy = 1; // waste a cycle
72773+
72774+ crypto_free_hash(tfm);
72775+
72776+ return retval;
72777+}
72778diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
72779index 77ff547..181834f 100644
72780--- a/include/asm-generic/4level-fixup.h
72781+++ b/include/asm-generic/4level-fixup.h
72782@@ -13,8 +13,10 @@
72783 #define pmd_alloc(mm, pud, address) \
72784 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
72785 NULL: pmd_offset(pud, address))
72786+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
72787
72788 #define pud_alloc(mm, pgd, address) (pgd)
72789+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
72790 #define pud_offset(pgd, start) (pgd)
72791 #define pud_none(pud) 0
72792 #define pud_bad(pud) 0
72793diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
72794index b7babf0..04ad282 100644
72795--- a/include/asm-generic/atomic-long.h
72796+++ b/include/asm-generic/atomic-long.h
72797@@ -22,6 +22,12 @@
72798
72799 typedef atomic64_t atomic_long_t;
72800
72801+#ifdef CONFIG_PAX_REFCOUNT
72802+typedef atomic64_unchecked_t atomic_long_unchecked_t;
72803+#else
72804+typedef atomic64_t atomic_long_unchecked_t;
72805+#endif
72806+
72807 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
72808
72809 static inline long atomic_long_read(atomic_long_t *l)
72810@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
72811 return (long)atomic64_read(v);
72812 }
72813
72814+#ifdef CONFIG_PAX_REFCOUNT
72815+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
72816+{
72817+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72818+
72819+ return (long)atomic64_read_unchecked(v);
72820+}
72821+#endif
72822+
72823 static inline void atomic_long_set(atomic_long_t *l, long i)
72824 {
72825 atomic64_t *v = (atomic64_t *)l;
72826@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
72827 atomic64_set(v, i);
72828 }
72829
72830+#ifdef CONFIG_PAX_REFCOUNT
72831+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
72832+{
72833+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72834+
72835+ atomic64_set_unchecked(v, i);
72836+}
72837+#endif
72838+
72839 static inline void atomic_long_inc(atomic_long_t *l)
72840 {
72841 atomic64_t *v = (atomic64_t *)l;
72842@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
72843 atomic64_inc(v);
72844 }
72845
72846+#ifdef CONFIG_PAX_REFCOUNT
72847+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
72848+{
72849+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72850+
72851+ atomic64_inc_unchecked(v);
72852+}
72853+#endif
72854+
72855 static inline void atomic_long_dec(atomic_long_t *l)
72856 {
72857 atomic64_t *v = (atomic64_t *)l;
72858@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
72859 atomic64_dec(v);
72860 }
72861
72862+#ifdef CONFIG_PAX_REFCOUNT
72863+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
72864+{
72865+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72866+
72867+ atomic64_dec_unchecked(v);
72868+}
72869+#endif
72870+
72871 static inline void atomic_long_add(long i, atomic_long_t *l)
72872 {
72873 atomic64_t *v = (atomic64_t *)l;
72874@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
72875 atomic64_add(i, v);
72876 }
72877
72878+#ifdef CONFIG_PAX_REFCOUNT
72879+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
72880+{
72881+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72882+
72883+ atomic64_add_unchecked(i, v);
72884+}
72885+#endif
72886+
72887 static inline void atomic_long_sub(long i, atomic_long_t *l)
72888 {
72889 atomic64_t *v = (atomic64_t *)l;
72890@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
72891 atomic64_sub(i, v);
72892 }
72893
72894+#ifdef CONFIG_PAX_REFCOUNT
72895+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
72896+{
72897+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72898+
72899+ atomic64_sub_unchecked(i, v);
72900+}
72901+#endif
72902+
72903 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
72904 {
72905 atomic64_t *v = (atomic64_t *)l;
72906@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
72907 return (long)atomic64_add_return(i, v);
72908 }
72909
72910+#ifdef CONFIG_PAX_REFCOUNT
72911+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
72912+{
72913+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72914+
72915+ return (long)atomic64_add_return_unchecked(i, v);
72916+}
72917+#endif
72918+
72919 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
72920 {
72921 atomic64_t *v = (atomic64_t *)l;
72922@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
72923 return (long)atomic64_inc_return(v);
72924 }
72925
72926+#ifdef CONFIG_PAX_REFCOUNT
72927+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
72928+{
72929+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72930+
72931+ return (long)atomic64_inc_return_unchecked(v);
72932+}
72933+#endif
72934+
72935 static inline long atomic_long_dec_return(atomic_long_t *l)
72936 {
72937 atomic64_t *v = (atomic64_t *)l;
72938@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
72939
72940 typedef atomic_t atomic_long_t;
72941
72942+#ifdef CONFIG_PAX_REFCOUNT
72943+typedef atomic_unchecked_t atomic_long_unchecked_t;
72944+#else
72945+typedef atomic_t atomic_long_unchecked_t;
72946+#endif
72947+
72948 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
72949 static inline long atomic_long_read(atomic_long_t *l)
72950 {
72951@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
72952 return (long)atomic_read(v);
72953 }
72954
72955+#ifdef CONFIG_PAX_REFCOUNT
72956+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
72957+{
72958+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72959+
72960+ return (long)atomic_read_unchecked(v);
72961+}
72962+#endif
72963+
72964 static inline void atomic_long_set(atomic_long_t *l, long i)
72965 {
72966 atomic_t *v = (atomic_t *)l;
72967@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
72968 atomic_set(v, i);
72969 }
72970
72971+#ifdef CONFIG_PAX_REFCOUNT
72972+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
72973+{
72974+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72975+
72976+ atomic_set_unchecked(v, i);
72977+}
72978+#endif
72979+
72980 static inline void atomic_long_inc(atomic_long_t *l)
72981 {
72982 atomic_t *v = (atomic_t *)l;
72983@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
72984 atomic_inc(v);
72985 }
72986
72987+#ifdef CONFIG_PAX_REFCOUNT
72988+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
72989+{
72990+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72991+
72992+ atomic_inc_unchecked(v);
72993+}
72994+#endif
72995+
72996 static inline void atomic_long_dec(atomic_long_t *l)
72997 {
72998 atomic_t *v = (atomic_t *)l;
72999@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
73000 atomic_dec(v);
73001 }
73002
73003+#ifdef CONFIG_PAX_REFCOUNT
73004+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
73005+{
73006+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73007+
73008+ atomic_dec_unchecked(v);
73009+}
73010+#endif
73011+
73012 static inline void atomic_long_add(long i, atomic_long_t *l)
73013 {
73014 atomic_t *v = (atomic_t *)l;
73015@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
73016 atomic_add(i, v);
73017 }
73018
73019+#ifdef CONFIG_PAX_REFCOUNT
73020+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
73021+{
73022+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73023+
73024+ atomic_add_unchecked(i, v);
73025+}
73026+#endif
73027+
73028 static inline void atomic_long_sub(long i, atomic_long_t *l)
73029 {
73030 atomic_t *v = (atomic_t *)l;
73031@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
73032 atomic_sub(i, v);
73033 }
73034
73035+#ifdef CONFIG_PAX_REFCOUNT
73036+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
73037+{
73038+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73039+
73040+ atomic_sub_unchecked(i, v);
73041+}
73042+#endif
73043+
73044 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
73045 {
73046 atomic_t *v = (atomic_t *)l;
73047@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
73048 return (long)atomic_add_return(i, v);
73049 }
73050
73051+#ifdef CONFIG_PAX_REFCOUNT
73052+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
73053+{
73054+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73055+
73056+ return (long)atomic_add_return_unchecked(i, v);
73057+}
73058+
73059+#endif
73060+
73061 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
73062 {
73063 atomic_t *v = (atomic_t *)l;
73064@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
73065 return (long)atomic_inc_return(v);
73066 }
73067
73068+#ifdef CONFIG_PAX_REFCOUNT
73069+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
73070+{
73071+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73072+
73073+ return (long)atomic_inc_return_unchecked(v);
73074+}
73075+#endif
73076+
73077 static inline long atomic_long_dec_return(atomic_long_t *l)
73078 {
73079 atomic_t *v = (atomic_t *)l;
73080@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
73081
73082 #endif /* BITS_PER_LONG == 64 */
73083
73084+#ifdef CONFIG_PAX_REFCOUNT
73085+static inline void pax_refcount_needs_these_functions(void)
73086+{
73087+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
73088+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
73089+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
73090+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
73091+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
73092+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
73093+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
73094+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
73095+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
73096+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
73097+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
73098+#ifdef CONFIG_X86
73099+ atomic_clear_mask_unchecked(0, NULL);
73100+ atomic_set_mask_unchecked(0, NULL);
73101+#endif
73102+
73103+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
73104+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
73105+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
73106+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
73107+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
73108+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
73109+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
73110+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
73111+}
73112+#else
73113+#define atomic_read_unchecked(v) atomic_read(v)
73114+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
73115+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
73116+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
73117+#define atomic_inc_unchecked(v) atomic_inc(v)
73118+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
73119+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
73120+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
73121+#define atomic_dec_unchecked(v) atomic_dec(v)
73122+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
73123+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
73124+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
73125+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
73126+
73127+#define atomic_long_read_unchecked(v) atomic_long_read(v)
73128+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
73129+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
73130+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
73131+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
73132+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
73133+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
73134+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
73135+#endif
73136+
73137 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
73138diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
73139index 33bd2de..f31bff97 100644
73140--- a/include/asm-generic/atomic.h
73141+++ b/include/asm-generic/atomic.h
73142@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
73143 * Atomically clears the bits set in @mask from @v
73144 */
73145 #ifndef atomic_clear_mask
73146-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
73147+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
73148 {
73149 unsigned long flags;
73150
73151diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
73152index b18ce4f..2ee2843 100644
73153--- a/include/asm-generic/atomic64.h
73154+++ b/include/asm-generic/atomic64.h
73155@@ -16,6 +16,8 @@ typedef struct {
73156 long long counter;
73157 } atomic64_t;
73158
73159+typedef atomic64_t atomic64_unchecked_t;
73160+
73161 #define ATOMIC64_INIT(i) { (i) }
73162
73163 extern long long atomic64_read(const atomic64_t *v);
73164@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
73165 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
73166 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
73167
73168+#define atomic64_read_unchecked(v) atomic64_read(v)
73169+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
73170+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
73171+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
73172+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
73173+#define atomic64_inc_unchecked(v) atomic64_inc(v)
73174+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
73175+#define atomic64_dec_unchecked(v) atomic64_dec(v)
73176+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
73177+
73178 #endif /* _ASM_GENERIC_ATOMIC64_H */
73179diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
73180index 1bfcfe5..e04c5c9 100644
73181--- a/include/asm-generic/cache.h
73182+++ b/include/asm-generic/cache.h
73183@@ -6,7 +6,7 @@
73184 * cache lines need to provide their own cache.h.
73185 */
73186
73187-#define L1_CACHE_SHIFT 5
73188-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
73189+#define L1_CACHE_SHIFT 5UL
73190+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
73191
73192 #endif /* __ASM_GENERIC_CACHE_H */
73193diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
73194index 0d68a1e..b74a761 100644
73195--- a/include/asm-generic/emergency-restart.h
73196+++ b/include/asm-generic/emergency-restart.h
73197@@ -1,7 +1,7 @@
73198 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
73199 #define _ASM_GENERIC_EMERGENCY_RESTART_H
73200
73201-static inline void machine_emergency_restart(void)
73202+static inline __noreturn void machine_emergency_restart(void)
73203 {
73204 machine_restart(NULL);
73205 }
73206diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
73207index 90f99c7..00ce236 100644
73208--- a/include/asm-generic/kmap_types.h
73209+++ b/include/asm-generic/kmap_types.h
73210@@ -2,9 +2,9 @@
73211 #define _ASM_GENERIC_KMAP_TYPES_H
73212
73213 #ifdef __WITH_KM_FENCE
73214-# define KM_TYPE_NR 41
73215+# define KM_TYPE_NR 42
73216 #else
73217-# define KM_TYPE_NR 20
73218+# define KM_TYPE_NR 21
73219 #endif
73220
73221 #endif
73222diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
73223index 9ceb03b..62b0b8f 100644
73224--- a/include/asm-generic/local.h
73225+++ b/include/asm-generic/local.h
73226@@ -23,24 +23,37 @@ typedef struct
73227 atomic_long_t a;
73228 } local_t;
73229
73230+typedef struct {
73231+ atomic_long_unchecked_t a;
73232+} local_unchecked_t;
73233+
73234 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
73235
73236 #define local_read(l) atomic_long_read(&(l)->a)
73237+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
73238 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
73239+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
73240 #define local_inc(l) atomic_long_inc(&(l)->a)
73241+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
73242 #define local_dec(l) atomic_long_dec(&(l)->a)
73243+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
73244 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
73245+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
73246 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
73247+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
73248
73249 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
73250 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
73251 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
73252 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
73253 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
73254+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
73255 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
73256 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
73257+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
73258
73259 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
73260+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
73261 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
73262 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
73263 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
73264diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
73265index 725612b..9cc513a 100644
73266--- a/include/asm-generic/pgtable-nopmd.h
73267+++ b/include/asm-generic/pgtable-nopmd.h
73268@@ -1,14 +1,19 @@
73269 #ifndef _PGTABLE_NOPMD_H
73270 #define _PGTABLE_NOPMD_H
73271
73272-#ifndef __ASSEMBLY__
73273-
73274 #include <asm-generic/pgtable-nopud.h>
73275
73276-struct mm_struct;
73277-
73278 #define __PAGETABLE_PMD_FOLDED
73279
73280+#define PMD_SHIFT PUD_SHIFT
73281+#define PTRS_PER_PMD 1
73282+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
73283+#define PMD_MASK (~(PMD_SIZE-1))
73284+
73285+#ifndef __ASSEMBLY__
73286+
73287+struct mm_struct;
73288+
73289 /*
73290 * Having the pmd type consist of a pud gets the size right, and allows
73291 * us to conceptually access the pud entry that this pmd is folded into
73292@@ -16,11 +21,6 @@ struct mm_struct;
73293 */
73294 typedef struct { pud_t pud; } pmd_t;
73295
73296-#define PMD_SHIFT PUD_SHIFT
73297-#define PTRS_PER_PMD 1
73298-#define PMD_SIZE (1UL << PMD_SHIFT)
73299-#define PMD_MASK (~(PMD_SIZE-1))
73300-
73301 /*
73302 * The "pud_xxx()" functions here are trivial for a folded two-level
73303 * setup: the pmd is never bad, and a pmd always exists (as it's folded
73304diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
73305index 810431d..0ec4804f 100644
73306--- a/include/asm-generic/pgtable-nopud.h
73307+++ b/include/asm-generic/pgtable-nopud.h
73308@@ -1,10 +1,15 @@
73309 #ifndef _PGTABLE_NOPUD_H
73310 #define _PGTABLE_NOPUD_H
73311
73312-#ifndef __ASSEMBLY__
73313-
73314 #define __PAGETABLE_PUD_FOLDED
73315
73316+#define PUD_SHIFT PGDIR_SHIFT
73317+#define PTRS_PER_PUD 1
73318+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
73319+#define PUD_MASK (~(PUD_SIZE-1))
73320+
73321+#ifndef __ASSEMBLY__
73322+
73323 /*
73324 * Having the pud type consist of a pgd gets the size right, and allows
73325 * us to conceptually access the pgd entry that this pud is folded into
73326@@ -12,11 +17,6 @@
73327 */
73328 typedef struct { pgd_t pgd; } pud_t;
73329
73330-#define PUD_SHIFT PGDIR_SHIFT
73331-#define PTRS_PER_PUD 1
73332-#define PUD_SIZE (1UL << PUD_SHIFT)
73333-#define PUD_MASK (~(PUD_SIZE-1))
73334-
73335 /*
73336 * The "pgd_xxx()" functions here are trivial for a folded two-level
73337 * setup: the pud is never bad, and a pud always exists (as it's folded
73338@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
73339 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
73340
73341 #define pgd_populate(mm, pgd, pud) do { } while (0)
73342+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
73343 /*
73344 * (puds are folded into pgds so this doesn't get actually called,
73345 * but the define is needed for a generic inline function.)
73346diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
73347index a59ff51..2594a70 100644
73348--- a/include/asm-generic/pgtable.h
73349+++ b/include/asm-generic/pgtable.h
73350@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
73351 }
73352 #endif /* CONFIG_NUMA_BALANCING */
73353
73354+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
73355+static inline unsigned long pax_open_kernel(void) { return 0; }
73356+#endif
73357+
73358+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
73359+static inline unsigned long pax_close_kernel(void) { return 0; }
73360+#endif
73361+
73362 #endif /* CONFIG_MMU */
73363
73364 #endif /* !__ASSEMBLY__ */
73365diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
73366index c184aa8..d049942 100644
73367--- a/include/asm-generic/uaccess.h
73368+++ b/include/asm-generic/uaccess.h
73369@@ -343,4 +343,12 @@ clear_user(void __user *to, unsigned long n)
73370 return __clear_user(to, n);
73371 }
73372
73373+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
73374+//static inline unsigned long pax_open_userland(void) { return 0; }
73375+#endif
73376+
73377+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
73378+//static inline unsigned long pax_close_userland(void) { return 0; }
73379+#endif
73380+
73381 #endif /* __ASM_GENERIC_UACCESS_H */
73382diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
73383index eb58d2d..df131bf 100644
73384--- a/include/asm-generic/vmlinux.lds.h
73385+++ b/include/asm-generic/vmlinux.lds.h
73386@@ -239,6 +239,7 @@
73387 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
73388 VMLINUX_SYMBOL(__start_rodata) = .; \
73389 *(.rodata) *(.rodata.*) \
73390+ *(.data..read_only) \
73391 *(__vermagic) /* Kernel version magic */ \
73392 . = ALIGN(8); \
73393 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
73394@@ -749,17 +750,18 @@
73395 * section in the linker script will go there too. @phdr should have
73396 * a leading colon.
73397 *
73398- * Note that this macros defines __per_cpu_load as an absolute symbol.
73399+ * Note that this macros defines per_cpu_load as an absolute symbol.
73400 * If there is no need to put the percpu section at a predetermined
73401 * address, use PERCPU_SECTION.
73402 */
73403 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
73404- VMLINUX_SYMBOL(__per_cpu_load) = .; \
73405- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
73406+ per_cpu_load = .; \
73407+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
73408 - LOAD_OFFSET) { \
73409+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
73410 PERCPU_INPUT(cacheline) \
73411 } phdr \
73412- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
73413+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
73414
73415 /**
73416 * PERCPU_SECTION - define output section for percpu area, simple version
73417diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
73418index 418d270..bfd2794 100644
73419--- a/include/crypto/algapi.h
73420+++ b/include/crypto/algapi.h
73421@@ -34,7 +34,7 @@ struct crypto_type {
73422 unsigned int maskclear;
73423 unsigned int maskset;
73424 unsigned int tfmsize;
73425-};
73426+} __do_const;
73427
73428 struct crypto_instance {
73429 struct crypto_alg alg;
73430diff --git a/include/drm/drmP.h b/include/drm/drmP.h
73431index 63d17ee..716de2b 100644
73432--- a/include/drm/drmP.h
73433+++ b/include/drm/drmP.h
73434@@ -72,6 +72,7 @@
73435 #include <linux/workqueue.h>
73436 #include <linux/poll.h>
73437 #include <asm/pgalloc.h>
73438+#include <asm/local.h>
73439 #include <drm/drm.h>
73440 #include <drm/drm_sarea.h>
73441
73442@@ -296,10 +297,12 @@ do { \
73443 * \param cmd command.
73444 * \param arg argument.
73445 */
73446-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
73447+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
73448+ struct drm_file *file_priv);
73449+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
73450 struct drm_file *file_priv);
73451
73452-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
73453+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
73454 unsigned long arg);
73455
73456 #define DRM_IOCTL_NR(n) _IOC_NR(n)
73457@@ -314,10 +317,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
73458 struct drm_ioctl_desc {
73459 unsigned int cmd;
73460 int flags;
73461- drm_ioctl_t *func;
73462+ drm_ioctl_t func;
73463 unsigned int cmd_drv;
73464 const char *name;
73465-};
73466+} __do_const;
73467
73468 /**
73469 * Creates a driver or general drm_ioctl_desc array entry for the given
73470@@ -1015,7 +1018,7 @@ struct drm_info_list {
73471 int (*show)(struct seq_file*, void*); /** show callback */
73472 u32 driver_features; /**< Required driver features for this entry */
73473 void *data;
73474-};
73475+} __do_const;
73476
73477 /**
73478 * debugfs node structure. This structure represents a debugfs file.
73479@@ -1088,7 +1091,7 @@ struct drm_device {
73480
73481 /** \name Usage Counters */
73482 /*@{ */
73483- int open_count; /**< Outstanding files open */
73484+ local_t open_count; /**< Outstanding files open */
73485 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
73486 atomic_t vma_count; /**< Outstanding vma areas open */
73487 int buf_use; /**< Buffers in use -- cannot alloc */
73488@@ -1099,7 +1102,7 @@ struct drm_device {
73489 /*@{ */
73490 unsigned long counters;
73491 enum drm_stat_type types[15];
73492- atomic_t counts[15];
73493+ atomic_unchecked_t counts[15];
73494 /*@} */
73495
73496 struct list_head filelist;
73497diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
73498index f43d556..94d9343 100644
73499--- a/include/drm/drm_crtc_helper.h
73500+++ b/include/drm/drm_crtc_helper.h
73501@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
73502 struct drm_connector *connector);
73503 /* disable encoder when not in use - more explicit than dpms off */
73504 void (*disable)(struct drm_encoder *encoder);
73505-};
73506+} __no_const;
73507
73508 /**
73509 * drm_connector_helper_funcs - helper operations for connectors
73510diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
73511index 72dcbe8..8db58d7 100644
73512--- a/include/drm/ttm/ttm_memory.h
73513+++ b/include/drm/ttm/ttm_memory.h
73514@@ -48,7 +48,7 @@
73515
73516 struct ttm_mem_shrink {
73517 int (*do_shrink) (struct ttm_mem_shrink *);
73518-};
73519+} __no_const;
73520
73521 /**
73522 * struct ttm_mem_global - Global memory accounting structure.
73523diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
73524index 4b840e8..155d235 100644
73525--- a/include/keys/asymmetric-subtype.h
73526+++ b/include/keys/asymmetric-subtype.h
73527@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
73528 /* Verify the signature on a key of this subtype (optional) */
73529 int (*verify_signature)(const struct key *key,
73530 const struct public_key_signature *sig);
73531-};
73532+} __do_const;
73533
73534 /**
73535 * asymmetric_key_subtype - Get the subtype from an asymmetric key
73536diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
73537index c1da539..1dcec55 100644
73538--- a/include/linux/atmdev.h
73539+++ b/include/linux/atmdev.h
73540@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
73541 #endif
73542
73543 struct k_atm_aal_stats {
73544-#define __HANDLE_ITEM(i) atomic_t i
73545+#define __HANDLE_ITEM(i) atomic_unchecked_t i
73546 __AAL_STAT_ITEMS
73547 #undef __HANDLE_ITEM
73548 };
73549@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
73550 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
73551 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
73552 struct module *owner;
73553-};
73554+} __do_const ;
73555
73556 struct atmphy_ops {
73557 int (*start)(struct atm_dev *dev);
73558diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
73559index 70cf138..0418ee2 100644
73560--- a/include/linux/binfmts.h
73561+++ b/include/linux/binfmts.h
73562@@ -73,8 +73,10 @@ struct linux_binfmt {
73563 int (*load_binary)(struct linux_binprm *);
73564 int (*load_shlib)(struct file *);
73565 int (*core_dump)(struct coredump_params *cprm);
73566+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
73567+ void (*handle_mmap)(struct file *);
73568 unsigned long min_coredump; /* minimal dump size */
73569-};
73570+} __do_const;
73571
73572 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
73573
73574diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
73575index 2fdb4a4..54aad7e 100644
73576--- a/include/linux/blkdev.h
73577+++ b/include/linux/blkdev.h
73578@@ -1526,7 +1526,7 @@ struct block_device_operations {
73579 /* this callback is with swap_lock and sometimes page table lock held */
73580 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
73581 struct module *owner;
73582-};
73583+} __do_const;
73584
73585 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
73586 unsigned long);
73587diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
73588index 7c2e030..b72475d 100644
73589--- a/include/linux/blktrace_api.h
73590+++ b/include/linux/blktrace_api.h
73591@@ -23,7 +23,7 @@ struct blk_trace {
73592 struct dentry *dir;
73593 struct dentry *dropped_file;
73594 struct dentry *msg_file;
73595- atomic_t dropped;
73596+ atomic_unchecked_t dropped;
73597 };
73598
73599 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
73600diff --git a/include/linux/cache.h b/include/linux/cache.h
73601index 4c57065..4307975 100644
73602--- a/include/linux/cache.h
73603+++ b/include/linux/cache.h
73604@@ -16,6 +16,10 @@
73605 #define __read_mostly
73606 #endif
73607
73608+#ifndef __read_only
73609+#define __read_only __read_mostly
73610+#endif
73611+
73612 #ifndef ____cacheline_aligned
73613 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
73614 #endif
73615diff --git a/include/linux/capability.h b/include/linux/capability.h
73616index d9a4f7f4..19f77d6 100644
73617--- a/include/linux/capability.h
73618+++ b/include/linux/capability.h
73619@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
73620 extern bool nsown_capable(int cap);
73621 extern bool inode_capable(const struct inode *inode, int cap);
73622 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
73623+extern bool capable_nolog(int cap);
73624+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
73625+extern bool inode_capable_nolog(const struct inode *inode, int cap);
73626
73627 /* audit system wants to get cap info from files as well */
73628 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
73629
73630+extern int is_privileged_binary(const struct dentry *dentry);
73631+
73632 #endif /* !_LINUX_CAPABILITY_H */
73633diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
73634index 8609d57..86e4d79 100644
73635--- a/include/linux/cdrom.h
73636+++ b/include/linux/cdrom.h
73637@@ -87,7 +87,6 @@ struct cdrom_device_ops {
73638
73639 /* driver specifications */
73640 const int capability; /* capability flags */
73641- int n_minors; /* number of active minor devices */
73642 /* handle uniform packets for scsi type devices (scsi,atapi) */
73643 int (*generic_packet) (struct cdrom_device_info *,
73644 struct packet_command *);
73645diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
73646index 4ce9056..86caac6 100644
73647--- a/include/linux/cleancache.h
73648+++ b/include/linux/cleancache.h
73649@@ -31,7 +31,7 @@ struct cleancache_ops {
73650 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
73651 void (*invalidate_inode)(int, struct cleancache_filekey);
73652 void (*invalidate_fs)(int);
73653-};
73654+} __no_const;
73655
73656 extern struct cleancache_ops *
73657 cleancache_register_ops(struct cleancache_ops *ops);
73658diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
73659index 1186098..f87e53d 100644
73660--- a/include/linux/clk-provider.h
73661+++ b/include/linux/clk-provider.h
73662@@ -132,6 +132,7 @@ struct clk_ops {
73663 unsigned long);
73664 void (*init)(struct clk_hw *hw);
73665 };
73666+typedef struct clk_ops __no_const clk_ops_no_const;
73667
73668 /**
73669 * struct clk_init_data - holds init data that's common to all clocks and is
73670diff --git a/include/linux/compat.h b/include/linux/compat.h
73671index 7f0c1dd..206ac34 100644
73672--- a/include/linux/compat.h
73673+++ b/include/linux/compat.h
73674@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
73675 compat_size_t __user *len_ptr);
73676
73677 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
73678-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
73679+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
73680 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
73681 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
73682 compat_ssize_t msgsz, int msgflg);
73683@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
73684 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
73685 compat_ulong_t addr, compat_ulong_t data);
73686 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
73687- compat_long_t addr, compat_long_t data);
73688+ compat_ulong_t addr, compat_ulong_t data);
73689
73690 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
73691 /*
73692@@ -669,6 +669,7 @@ asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
73693
73694 int compat_restore_altstack(const compat_stack_t __user *uss);
73695 int __compat_save_altstack(compat_stack_t __user *, unsigned long);
73696+void __compat_save_altstack_ex(compat_stack_t __user *, unsigned long);
73697
73698 asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
73699 struct compat_timespec __user *interval);
73700diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
73701index 842de22..7f3a41f 100644
73702--- a/include/linux/compiler-gcc4.h
73703+++ b/include/linux/compiler-gcc4.h
73704@@ -39,9 +39,29 @@
73705 # define __compiletime_warning(message) __attribute__((warning(message)))
73706 # define __compiletime_error(message) __attribute__((error(message)))
73707 #endif /* __CHECKER__ */
73708+
73709+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
73710+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
73711+#define __bos0(ptr) __bos((ptr), 0)
73712+#define __bos1(ptr) __bos((ptr), 1)
73713 #endif /* GCC_VERSION >= 40300 */
73714
73715 #if GCC_VERSION >= 40500
73716+
73717+#ifdef CONSTIFY_PLUGIN
73718+#define __no_const __attribute__((no_const))
73719+#define __do_const __attribute__((do_const))
73720+#endif
73721+
73722+#ifdef SIZE_OVERFLOW_PLUGIN
73723+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
73724+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
73725+#endif
73726+
73727+#ifdef LATENT_ENTROPY_PLUGIN
73728+#define __latent_entropy __attribute__((latent_entropy))
73729+#endif
73730+
73731 /*
73732 * Mark a position in code as unreachable. This can be used to
73733 * suppress control flow warnings after asm blocks that transfer
73734diff --git a/include/linux/compiler.h b/include/linux/compiler.h
73735index 92669cd..1771a15 100644
73736--- a/include/linux/compiler.h
73737+++ b/include/linux/compiler.h
73738@@ -5,11 +5,14 @@
73739
73740 #ifdef __CHECKER__
73741 # define __user __attribute__((noderef, address_space(1)))
73742+# define __force_user __force __user
73743 # define __kernel __attribute__((address_space(0)))
73744+# define __force_kernel __force __kernel
73745 # define __safe __attribute__((safe))
73746 # define __force __attribute__((force))
73747 # define __nocast __attribute__((nocast))
73748 # define __iomem __attribute__((noderef, address_space(2)))
73749+# define __force_iomem __force __iomem
73750 # define __must_hold(x) __attribute__((context(x,1,1)))
73751 # define __acquires(x) __attribute__((context(x,0,1)))
73752 # define __releases(x) __attribute__((context(x,1,0)))
73753@@ -17,20 +20,37 @@
73754 # define __release(x) __context__(x,-1)
73755 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
73756 # define __percpu __attribute__((noderef, address_space(3)))
73757+# define __force_percpu __force __percpu
73758 #ifdef CONFIG_SPARSE_RCU_POINTER
73759 # define __rcu __attribute__((noderef, address_space(4)))
73760+# define __force_rcu __force __rcu
73761 #else
73762 # define __rcu
73763+# define __force_rcu
73764 #endif
73765 extern void __chk_user_ptr(const volatile void __user *);
73766 extern void __chk_io_ptr(const volatile void __iomem *);
73767 #else
73768-# define __user
73769-# define __kernel
73770+# ifdef CHECKER_PLUGIN
73771+//# define __user
73772+//# define __force_user
73773+//# define __kernel
73774+//# define __force_kernel
73775+# else
73776+# ifdef STRUCTLEAK_PLUGIN
73777+# define __user __attribute__((user))
73778+# else
73779+# define __user
73780+# endif
73781+# define __force_user
73782+# define __kernel
73783+# define __force_kernel
73784+# endif
73785 # define __safe
73786 # define __force
73787 # define __nocast
73788 # define __iomem
73789+# define __force_iomem
73790 # define __chk_user_ptr(x) (void)0
73791 # define __chk_io_ptr(x) (void)0
73792 # define __builtin_warning(x, y...) (1)
73793@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
73794 # define __release(x) (void)0
73795 # define __cond_lock(x,c) (c)
73796 # define __percpu
73797+# define __force_percpu
73798 # define __rcu
73799+# define __force_rcu
73800 #endif
73801
73802 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
73803@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
73804 # define __attribute_const__ /* unimplemented */
73805 #endif
73806
73807+#ifndef __no_const
73808+# define __no_const
73809+#endif
73810+
73811+#ifndef __do_const
73812+# define __do_const
73813+#endif
73814+
73815+#ifndef __size_overflow
73816+# define __size_overflow(...)
73817+#endif
73818+
73819+#ifndef __intentional_overflow
73820+# define __intentional_overflow(...)
73821+#endif
73822+
73823+#ifndef __latent_entropy
73824+# define __latent_entropy
73825+#endif
73826+
73827 /*
73828 * Tell gcc if a function is cold. The compiler will assume any path
73829 * directly leading to the call is unlikely.
73830@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
73831 #define __cold
73832 #endif
73833
73834+#ifndef __alloc_size
73835+#define __alloc_size(...)
73836+#endif
73837+
73838+#ifndef __bos
73839+#define __bos(ptr, arg)
73840+#endif
73841+
73842+#ifndef __bos0
73843+#define __bos0(ptr)
73844+#endif
73845+
73846+#ifndef __bos1
73847+#define __bos1(ptr)
73848+#endif
73849+
73850 /* Simple shorthand for a section definition */
73851 #ifndef __section
73852 # define __section(S) __attribute__ ((__section__(#S)))
73853@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
73854 * use is to mediate communication between process-level code and irq/NMI
73855 * handlers, all running on the same CPU.
73856 */
73857-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
73858+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
73859+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
73860
73861 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
73862 #ifdef CONFIG_KPROBES
73863diff --git a/include/linux/completion.h b/include/linux/completion.h
73864index 33f0280..35c6568 100644
73865--- a/include/linux/completion.h
73866+++ b/include/linux/completion.h
73867@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
73868 extern void wait_for_completion(struct completion *);
73869 extern void wait_for_completion_io(struct completion *);
73870 extern int wait_for_completion_interruptible(struct completion *x);
73871-extern int wait_for_completion_killable(struct completion *x);
73872+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
73873 extern unsigned long wait_for_completion_timeout(struct completion *x,
73874 unsigned long timeout);
73875 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
73876 unsigned long timeout);
73877 extern long wait_for_completion_interruptible_timeout(
73878- struct completion *x, unsigned long timeout);
73879+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
73880 extern long wait_for_completion_killable_timeout(
73881- struct completion *x, unsigned long timeout);
73882+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
73883 extern bool try_wait_for_completion(struct completion *x);
73884 extern bool completion_done(struct completion *x);
73885
73886diff --git a/include/linux/configfs.h b/include/linux/configfs.h
73887index 34025df..d94bbbc 100644
73888--- a/include/linux/configfs.h
73889+++ b/include/linux/configfs.h
73890@@ -125,7 +125,7 @@ struct configfs_attribute {
73891 const char *ca_name;
73892 struct module *ca_owner;
73893 umode_t ca_mode;
73894-};
73895+} __do_const;
73896
73897 /*
73898 * Users often need to create attribute structures for their configurable
73899diff --git a/include/linux/cpu.h b/include/linux/cpu.h
73900index 9f3c7e8..a18c7b6 100644
73901--- a/include/linux/cpu.h
73902+++ b/include/linux/cpu.h
73903@@ -115,7 +115,7 @@ enum {
73904 /* Need to know about CPUs going up/down? */
73905 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
73906 #define cpu_notifier(fn, pri) { \
73907- static struct notifier_block fn##_nb __cpuinitdata = \
73908+ static struct notifier_block fn##_nb = \
73909 { .notifier_call = fn, .priority = pri }; \
73910 register_cpu_notifier(&fn##_nb); \
73911 }
73912diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
73913index 037d36a..ca5fe6e 100644
73914--- a/include/linux/cpufreq.h
73915+++ b/include/linux/cpufreq.h
73916@@ -262,7 +262,7 @@ struct cpufreq_driver {
73917 int (*suspend) (struct cpufreq_policy *policy);
73918 int (*resume) (struct cpufreq_policy *policy);
73919 struct freq_attr **attr;
73920-};
73921+} __do_const;
73922
73923 /* flags */
73924
73925@@ -321,6 +321,7 @@ struct global_attr {
73926 ssize_t (*store)(struct kobject *a, struct attribute *b,
73927 const char *c, size_t count);
73928 };
73929+typedef struct global_attr __no_const global_attr_no_const;
73930
73931 #define define_one_global_ro(_name) \
73932 static struct global_attr _name = \
73933diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
73934index 8f04062..900239a 100644
73935--- a/include/linux/cpuidle.h
73936+++ b/include/linux/cpuidle.h
73937@@ -52,7 +52,8 @@ struct cpuidle_state {
73938 int index);
73939
73940 int (*enter_dead) (struct cpuidle_device *dev, int index);
73941-};
73942+} __do_const;
73943+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
73944
73945 /* Idle State Flags */
73946 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
73947@@ -191,7 +192,7 @@ struct cpuidle_governor {
73948 void (*reflect) (struct cpuidle_device *dev, int index);
73949
73950 struct module *owner;
73951-};
73952+} __do_const;
73953
73954 #ifdef CONFIG_CPU_IDLE
73955
73956diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
73957index d08e4d2..95fad61 100644
73958--- a/include/linux/cpumask.h
73959+++ b/include/linux/cpumask.h
73960@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
73961 }
73962
73963 /* Valid inputs for n are -1 and 0. */
73964-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
73965+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
73966 {
73967 return n+1;
73968 }
73969
73970-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
73971+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
73972 {
73973 return n+1;
73974 }
73975
73976-static inline unsigned int cpumask_next_and(int n,
73977+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
73978 const struct cpumask *srcp,
73979 const struct cpumask *andp)
73980 {
73981@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
73982 *
73983 * Returns >= nr_cpu_ids if no further cpus set.
73984 */
73985-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
73986+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
73987 {
73988 /* -1 is a legal arg here. */
73989 if (n != -1)
73990@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
73991 *
73992 * Returns >= nr_cpu_ids if no further cpus unset.
73993 */
73994-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
73995+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
73996 {
73997 /* -1 is a legal arg here. */
73998 if (n != -1)
73999@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
74000 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
74001 }
74002
74003-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
74004+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
74005 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
74006
74007 /**
74008diff --git a/include/linux/cred.h b/include/linux/cred.h
74009index 04421e8..6bce4ef 100644
74010--- a/include/linux/cred.h
74011+++ b/include/linux/cred.h
74012@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
74013 static inline void validate_process_creds(void)
74014 {
74015 }
74016+static inline void validate_task_creds(struct task_struct *task)
74017+{
74018+}
74019 #endif
74020
74021 /**
74022diff --git a/include/linux/crypto.h b/include/linux/crypto.h
74023index b92eadf..b4ecdc1 100644
74024--- a/include/linux/crypto.h
74025+++ b/include/linux/crypto.h
74026@@ -373,7 +373,7 @@ struct cipher_tfm {
74027 const u8 *key, unsigned int keylen);
74028 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
74029 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
74030-};
74031+} __no_const;
74032
74033 struct hash_tfm {
74034 int (*init)(struct hash_desc *desc);
74035@@ -394,13 +394,13 @@ struct compress_tfm {
74036 int (*cot_decompress)(struct crypto_tfm *tfm,
74037 const u8 *src, unsigned int slen,
74038 u8 *dst, unsigned int *dlen);
74039-};
74040+} __no_const;
74041
74042 struct rng_tfm {
74043 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
74044 unsigned int dlen);
74045 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
74046-};
74047+} __no_const;
74048
74049 #define crt_ablkcipher crt_u.ablkcipher
74050 #define crt_aead crt_u.aead
74051diff --git a/include/linux/ctype.h b/include/linux/ctype.h
74052index 653589e..4ef254a 100644
74053--- a/include/linux/ctype.h
74054+++ b/include/linux/ctype.h
74055@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
74056 * Fast implementation of tolower() for internal usage. Do not use in your
74057 * code.
74058 */
74059-static inline char _tolower(const char c)
74060+static inline unsigned char _tolower(const unsigned char c)
74061 {
74062 return c | 0x20;
74063 }
74064diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
74065index 7925bf0..d5143d2 100644
74066--- a/include/linux/decompress/mm.h
74067+++ b/include/linux/decompress/mm.h
74068@@ -77,7 +77,7 @@ static void free(void *where)
74069 * warnings when not needed (indeed large_malloc / large_free are not
74070 * needed by inflate */
74071
74072-#define malloc(a) kmalloc(a, GFP_KERNEL)
74073+#define malloc(a) kmalloc((a), GFP_KERNEL)
74074 #define free(a) kfree(a)
74075
74076 #define large_malloc(a) vmalloc(a)
74077diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
74078index fe8c447..bdc1f33 100644
74079--- a/include/linux/devfreq.h
74080+++ b/include/linux/devfreq.h
74081@@ -114,7 +114,7 @@ struct devfreq_governor {
74082 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
74083 int (*event_handler)(struct devfreq *devfreq,
74084 unsigned int event, void *data);
74085-};
74086+} __do_const;
74087
74088 /**
74089 * struct devfreq - Device devfreq structure
74090diff --git a/include/linux/device.h b/include/linux/device.h
74091index c0a1261..dba7569 100644
74092--- a/include/linux/device.h
74093+++ b/include/linux/device.h
74094@@ -290,7 +290,7 @@ struct subsys_interface {
74095 struct list_head node;
74096 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
74097 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
74098-};
74099+} __do_const;
74100
74101 int subsys_interface_register(struct subsys_interface *sif);
74102 void subsys_interface_unregister(struct subsys_interface *sif);
74103@@ -473,7 +473,7 @@ struct device_type {
74104 void (*release)(struct device *dev);
74105
74106 const struct dev_pm_ops *pm;
74107-};
74108+} __do_const;
74109
74110 /* interface for exporting device attributes */
74111 struct device_attribute {
74112@@ -483,11 +483,12 @@ struct device_attribute {
74113 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
74114 const char *buf, size_t count);
74115 };
74116+typedef struct device_attribute __no_const device_attribute_no_const;
74117
74118 struct dev_ext_attribute {
74119 struct device_attribute attr;
74120 void *var;
74121-};
74122+} __do_const;
74123
74124 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
74125 char *buf);
74126diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
74127index 94af418..b1ca7a2 100644
74128--- a/include/linux/dma-mapping.h
74129+++ b/include/linux/dma-mapping.h
74130@@ -54,7 +54,7 @@ struct dma_map_ops {
74131 u64 (*get_required_mask)(struct device *dev);
74132 #endif
74133 int is_phys;
74134-};
74135+} __do_const;
74136
74137 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
74138
74139diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
74140index 96d3e4a..dc36433 100644
74141--- a/include/linux/dmaengine.h
74142+++ b/include/linux/dmaengine.h
74143@@ -1035,9 +1035,9 @@ struct dma_pinned_list {
74144 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
74145 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
74146
74147-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
74148+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
74149 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
74150-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
74151+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
74152 struct dma_pinned_list *pinned_list, struct page *page,
74153 unsigned int offset, size_t len);
74154
74155diff --git a/include/linux/efi.h b/include/linux/efi.h
74156index 2bc0ad7..3f7b006 100644
74157--- a/include/linux/efi.h
74158+++ b/include/linux/efi.h
74159@@ -745,6 +745,7 @@ struct efivar_operations {
74160 efi_set_variable_t *set_variable;
74161 efi_query_variable_store_t *query_variable_store;
74162 };
74163+typedef struct efivar_operations __no_const efivar_operations_no_const;
74164
74165 struct efivars {
74166 /*
74167diff --git a/include/linux/elf.h b/include/linux/elf.h
74168index 40a3c0e..4c45a38 100644
74169--- a/include/linux/elf.h
74170+++ b/include/linux/elf.h
74171@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
74172 #define elf_note elf32_note
74173 #define elf_addr_t Elf32_Off
74174 #define Elf_Half Elf32_Half
74175+#define elf_dyn Elf32_Dyn
74176
74177 #else
74178
74179@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
74180 #define elf_note elf64_note
74181 #define elf_addr_t Elf64_Off
74182 #define Elf_Half Elf64_Half
74183+#define elf_dyn Elf64_Dyn
74184
74185 #endif
74186
74187diff --git a/include/linux/err.h b/include/linux/err.h
74188index f2edce2..cc2082c 100644
74189--- a/include/linux/err.h
74190+++ b/include/linux/err.h
74191@@ -19,12 +19,12 @@
74192
74193 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
74194
74195-static inline void * __must_check ERR_PTR(long error)
74196+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
74197 {
74198 return (void *) error;
74199 }
74200
74201-static inline long __must_check PTR_ERR(const void *ptr)
74202+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
74203 {
74204 return (long) ptr;
74205 }
74206diff --git a/include/linux/extcon.h b/include/linux/extcon.h
74207index fcb51c8..bdafcf6 100644
74208--- a/include/linux/extcon.h
74209+++ b/include/linux/extcon.h
74210@@ -134,7 +134,7 @@ struct extcon_dev {
74211 /* /sys/class/extcon/.../mutually_exclusive/... */
74212 struct attribute_group attr_g_muex;
74213 struct attribute **attrs_muex;
74214- struct device_attribute *d_attrs_muex;
74215+ device_attribute_no_const *d_attrs_muex;
74216 };
74217
74218 /**
74219diff --git a/include/linux/fb.h b/include/linux/fb.h
74220index d49c60f..2834fbe 100644
74221--- a/include/linux/fb.h
74222+++ b/include/linux/fb.h
74223@@ -304,7 +304,7 @@ struct fb_ops {
74224 /* called at KDB enter and leave time to prepare the console */
74225 int (*fb_debug_enter)(struct fb_info *info);
74226 int (*fb_debug_leave)(struct fb_info *info);
74227-};
74228+} __do_const;
74229
74230 #ifdef CONFIG_FB_TILEBLITTING
74231 #define FB_TILE_CURSOR_NONE 0
74232diff --git a/include/linux/filter.h b/include/linux/filter.h
74233index f65f5a6..2f4f93a 100644
74234--- a/include/linux/filter.h
74235+++ b/include/linux/filter.h
74236@@ -20,6 +20,7 @@ struct compat_sock_fprog {
74237
74238 struct sk_buff;
74239 struct sock;
74240+struct bpf_jit_work;
74241
74242 struct sk_filter
74243 {
74244@@ -27,6 +28,9 @@ struct sk_filter
74245 unsigned int len; /* Number of filter blocks */
74246 unsigned int (*bpf_func)(const struct sk_buff *skb,
74247 const struct sock_filter *filter);
74248+#ifdef CONFIG_BPF_JIT
74249+ struct bpf_jit_work *work;
74250+#endif
74251 struct rcu_head rcu;
74252 struct sock_filter insns[0];
74253 };
74254diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
74255index 8293262..2b3b8bd 100644
74256--- a/include/linux/frontswap.h
74257+++ b/include/linux/frontswap.h
74258@@ -11,7 +11,7 @@ struct frontswap_ops {
74259 int (*load)(unsigned, pgoff_t, struct page *);
74260 void (*invalidate_page)(unsigned, pgoff_t);
74261 void (*invalidate_area)(unsigned);
74262-};
74263+} __no_const;
74264
74265 extern bool frontswap_enabled;
74266 extern struct frontswap_ops *
74267diff --git a/include/linux/fs.h b/include/linux/fs.h
74268index 65c2be2..4c53f6e 100644
74269--- a/include/linux/fs.h
74270+++ b/include/linux/fs.h
74271@@ -1543,7 +1543,8 @@ struct file_operations {
74272 long (*fallocate)(struct file *file, int mode, loff_t offset,
74273 loff_t len);
74274 int (*show_fdinfo)(struct seq_file *m, struct file *f);
74275-};
74276+} __do_const;
74277+typedef struct file_operations __no_const file_operations_no_const;
74278
74279 struct inode_operations {
74280 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
74281@@ -2688,4 +2689,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
74282 inode->i_flags |= S_NOSEC;
74283 }
74284
74285+static inline bool is_sidechannel_device(const struct inode *inode)
74286+{
74287+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
74288+ umode_t mode = inode->i_mode;
74289+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
74290+#else
74291+ return false;
74292+#endif
74293+}
74294+
74295 #endif /* _LINUX_FS_H */
74296diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
74297index 2b93a9a..855d94a 100644
74298--- a/include/linux/fs_struct.h
74299+++ b/include/linux/fs_struct.h
74300@@ -6,7 +6,7 @@
74301 #include <linux/seqlock.h>
74302
74303 struct fs_struct {
74304- int users;
74305+ atomic_t users;
74306 spinlock_t lock;
74307 seqcount_t seq;
74308 int umask;
74309diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
74310index 5dfa0aa..6acf322 100644
74311--- a/include/linux/fscache-cache.h
74312+++ b/include/linux/fscache-cache.h
74313@@ -112,7 +112,7 @@ struct fscache_operation {
74314 fscache_operation_release_t release;
74315 };
74316
74317-extern atomic_t fscache_op_debug_id;
74318+extern atomic_unchecked_t fscache_op_debug_id;
74319 extern void fscache_op_work_func(struct work_struct *work);
74320
74321 extern void fscache_enqueue_operation(struct fscache_operation *);
74322@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
74323 INIT_WORK(&op->work, fscache_op_work_func);
74324 atomic_set(&op->usage, 1);
74325 op->state = FSCACHE_OP_ST_INITIALISED;
74326- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
74327+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
74328 op->processor = processor;
74329 op->release = release;
74330 INIT_LIST_HEAD(&op->pend_link);
74331diff --git a/include/linux/fscache.h b/include/linux/fscache.h
74332index 7a08623..4c07b0f 100644
74333--- a/include/linux/fscache.h
74334+++ b/include/linux/fscache.h
74335@@ -152,7 +152,7 @@ struct fscache_cookie_def {
74336 * - this is mandatory for any object that may have data
74337 */
74338 void (*now_uncached)(void *cookie_netfs_data);
74339-};
74340+} __do_const;
74341
74342 /*
74343 * fscache cached network filesystem type
74344diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
74345index a78680a..87bd73e 100644
74346--- a/include/linux/fsnotify.h
74347+++ b/include/linux/fsnotify.h
74348@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
74349 struct inode *inode = path->dentry->d_inode;
74350 __u32 mask = FS_ACCESS;
74351
74352+ if (is_sidechannel_device(inode))
74353+ return;
74354+
74355 if (S_ISDIR(inode->i_mode))
74356 mask |= FS_ISDIR;
74357
74358@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
74359 struct inode *inode = path->dentry->d_inode;
74360 __u32 mask = FS_MODIFY;
74361
74362+ if (is_sidechannel_device(inode))
74363+ return;
74364+
74365 if (S_ISDIR(inode->i_mode))
74366 mask |= FS_ISDIR;
74367
74368@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
74369 */
74370 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
74371 {
74372- return kstrdup(name, GFP_KERNEL);
74373+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
74374 }
74375
74376 /*
74377diff --git a/include/linux/genhd.h b/include/linux/genhd.h
74378index 9f3c275..911b591 100644
74379--- a/include/linux/genhd.h
74380+++ b/include/linux/genhd.h
74381@@ -194,7 +194,7 @@ struct gendisk {
74382 struct kobject *slave_dir;
74383
74384 struct timer_rand_state *random;
74385- atomic_t sync_io; /* RAID */
74386+ atomic_unchecked_t sync_io; /* RAID */
74387 struct disk_events *ev;
74388 #ifdef CONFIG_BLK_DEV_INTEGRITY
74389 struct blk_integrity *integrity;
74390diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
74391index 023bc34..b02b46a 100644
74392--- a/include/linux/genl_magic_func.h
74393+++ b/include/linux/genl_magic_func.h
74394@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
74395 },
74396
74397 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
74398-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
74399+static struct genl_ops ZZZ_genl_ops[] = {
74400 #include GENL_MAGIC_INCLUDE_FILE
74401 };
74402
74403diff --git a/include/linux/gfp.h b/include/linux/gfp.h
74404index 0f615eb..5c3832f 100644
74405--- a/include/linux/gfp.h
74406+++ b/include/linux/gfp.h
74407@@ -35,6 +35,13 @@ struct vm_area_struct;
74408 #define ___GFP_NO_KSWAPD 0x400000u
74409 #define ___GFP_OTHER_NODE 0x800000u
74410 #define ___GFP_WRITE 0x1000000u
74411+
74412+#ifdef CONFIG_PAX_USERCOPY_SLABS
74413+#define ___GFP_USERCOPY 0x2000000u
74414+#else
74415+#define ___GFP_USERCOPY 0
74416+#endif
74417+
74418 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
74419
74420 /*
74421@@ -92,6 +99,7 @@ struct vm_area_struct;
74422 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
74423 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
74424 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
74425+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
74426
74427 /*
74428 * This may seem redundant, but it's a way of annotating false positives vs.
74429@@ -99,7 +107,7 @@ struct vm_area_struct;
74430 */
74431 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
74432
74433-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
74434+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
74435 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
74436
74437 /* This equals 0, but use constants in case they ever change */
74438@@ -153,6 +161,8 @@ struct vm_area_struct;
74439 /* 4GB DMA on some platforms */
74440 #define GFP_DMA32 __GFP_DMA32
74441
74442+#define GFP_USERCOPY __GFP_USERCOPY
74443+
74444 /* Convert GFP flags to their corresponding migrate type */
74445 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
74446 {
74447diff --git a/include/linux/gracl.h b/include/linux/gracl.h
74448new file mode 100644
74449index 0000000..ebe6d72
74450--- /dev/null
74451+++ b/include/linux/gracl.h
74452@@ -0,0 +1,319 @@
74453+#ifndef GR_ACL_H
74454+#define GR_ACL_H
74455+
74456+#include <linux/grdefs.h>
74457+#include <linux/resource.h>
74458+#include <linux/capability.h>
74459+#include <linux/dcache.h>
74460+#include <asm/resource.h>
74461+
74462+/* Major status information */
74463+
74464+#define GR_VERSION "grsecurity 2.9.1"
74465+#define GRSECURITY_VERSION 0x2901
74466+
74467+enum {
74468+ GR_SHUTDOWN = 0,
74469+ GR_ENABLE = 1,
74470+ GR_SPROLE = 2,
74471+ GR_RELOAD = 3,
74472+ GR_SEGVMOD = 4,
74473+ GR_STATUS = 5,
74474+ GR_UNSPROLE = 6,
74475+ GR_PASSSET = 7,
74476+ GR_SPROLEPAM = 8,
74477+};
74478+
74479+/* Password setup definitions
74480+ * kernel/grhash.c */
74481+enum {
74482+ GR_PW_LEN = 128,
74483+ GR_SALT_LEN = 16,
74484+ GR_SHA_LEN = 32,
74485+};
74486+
74487+enum {
74488+ GR_SPROLE_LEN = 64,
74489+};
74490+
74491+enum {
74492+ GR_NO_GLOB = 0,
74493+ GR_REG_GLOB,
74494+ GR_CREATE_GLOB
74495+};
74496+
74497+#define GR_NLIMITS 32
74498+
74499+/* Begin Data Structures */
74500+
74501+struct sprole_pw {
74502+ unsigned char *rolename;
74503+ unsigned char salt[GR_SALT_LEN];
74504+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
74505+};
74506+
74507+struct name_entry {
74508+ __u32 key;
74509+ ino_t inode;
74510+ dev_t device;
74511+ char *name;
74512+ __u16 len;
74513+ __u8 deleted;
74514+ struct name_entry *prev;
74515+ struct name_entry *next;
74516+};
74517+
74518+struct inodev_entry {
74519+ struct name_entry *nentry;
74520+ struct inodev_entry *prev;
74521+ struct inodev_entry *next;
74522+};
74523+
74524+struct acl_role_db {
74525+ struct acl_role_label **r_hash;
74526+ __u32 r_size;
74527+};
74528+
74529+struct inodev_db {
74530+ struct inodev_entry **i_hash;
74531+ __u32 i_size;
74532+};
74533+
74534+struct name_db {
74535+ struct name_entry **n_hash;
74536+ __u32 n_size;
74537+};
74538+
74539+struct crash_uid {
74540+ uid_t uid;
74541+ unsigned long expires;
74542+};
74543+
74544+struct gr_hash_struct {
74545+ void **table;
74546+ void **nametable;
74547+ void *first;
74548+ __u32 table_size;
74549+ __u32 used_size;
74550+ int type;
74551+};
74552+
74553+/* Userspace Grsecurity ACL data structures */
74554+
74555+struct acl_subject_label {
74556+ char *filename;
74557+ ino_t inode;
74558+ dev_t device;
74559+ __u32 mode;
74560+ kernel_cap_t cap_mask;
74561+ kernel_cap_t cap_lower;
74562+ kernel_cap_t cap_invert_audit;
74563+
74564+ struct rlimit res[GR_NLIMITS];
74565+ __u32 resmask;
74566+
74567+ __u8 user_trans_type;
74568+ __u8 group_trans_type;
74569+ uid_t *user_transitions;
74570+ gid_t *group_transitions;
74571+ __u16 user_trans_num;
74572+ __u16 group_trans_num;
74573+
74574+ __u32 sock_families[2];
74575+ __u32 ip_proto[8];
74576+ __u32 ip_type;
74577+ struct acl_ip_label **ips;
74578+ __u32 ip_num;
74579+ __u32 inaddr_any_override;
74580+
74581+ __u32 crashes;
74582+ unsigned long expires;
74583+
74584+ struct acl_subject_label *parent_subject;
74585+ struct gr_hash_struct *hash;
74586+ struct acl_subject_label *prev;
74587+ struct acl_subject_label *next;
74588+
74589+ struct acl_object_label **obj_hash;
74590+ __u32 obj_hash_size;
74591+ __u16 pax_flags;
74592+};
74593+
74594+struct role_allowed_ip {
74595+ __u32 addr;
74596+ __u32 netmask;
74597+
74598+ struct role_allowed_ip *prev;
74599+ struct role_allowed_ip *next;
74600+};
74601+
74602+struct role_transition {
74603+ char *rolename;
74604+
74605+ struct role_transition *prev;
74606+ struct role_transition *next;
74607+};
74608+
74609+struct acl_role_label {
74610+ char *rolename;
74611+ uid_t uidgid;
74612+ __u16 roletype;
74613+
74614+ __u16 auth_attempts;
74615+ unsigned long expires;
74616+
74617+ struct acl_subject_label *root_label;
74618+ struct gr_hash_struct *hash;
74619+
74620+ struct acl_role_label *prev;
74621+ struct acl_role_label *next;
74622+
74623+ struct role_transition *transitions;
74624+ struct role_allowed_ip *allowed_ips;
74625+ uid_t *domain_children;
74626+ __u16 domain_child_num;
74627+
74628+ umode_t umask;
74629+
74630+ struct acl_subject_label **subj_hash;
74631+ __u32 subj_hash_size;
74632+};
74633+
74634+struct user_acl_role_db {
74635+ struct acl_role_label **r_table;
74636+ __u32 num_pointers; /* Number of allocations to track */
74637+ __u32 num_roles; /* Number of roles */
74638+ __u32 num_domain_children; /* Number of domain children */
74639+ __u32 num_subjects; /* Number of subjects */
74640+ __u32 num_objects; /* Number of objects */
74641+};
74642+
74643+struct acl_object_label {
74644+ char *filename;
74645+ ino_t inode;
74646+ dev_t device;
74647+ __u32 mode;
74648+
74649+ struct acl_subject_label *nested;
74650+ struct acl_object_label *globbed;
74651+
74652+ /* next two structures not used */
74653+
74654+ struct acl_object_label *prev;
74655+ struct acl_object_label *next;
74656+};
74657+
74658+struct acl_ip_label {
74659+ char *iface;
74660+ __u32 addr;
74661+ __u32 netmask;
74662+ __u16 low, high;
74663+ __u8 mode;
74664+ __u32 type;
74665+ __u32 proto[8];
74666+
74667+ /* next two structures not used */
74668+
74669+ struct acl_ip_label *prev;
74670+ struct acl_ip_label *next;
74671+};
74672+
74673+struct gr_arg {
74674+ struct user_acl_role_db role_db;
74675+ unsigned char pw[GR_PW_LEN];
74676+ unsigned char salt[GR_SALT_LEN];
74677+ unsigned char sum[GR_SHA_LEN];
74678+ unsigned char sp_role[GR_SPROLE_LEN];
74679+ struct sprole_pw *sprole_pws;
74680+ dev_t segv_device;
74681+ ino_t segv_inode;
74682+ uid_t segv_uid;
74683+ __u16 num_sprole_pws;
74684+ __u16 mode;
74685+};
74686+
74687+struct gr_arg_wrapper {
74688+ struct gr_arg *arg;
74689+ __u32 version;
74690+ __u32 size;
74691+};
74692+
74693+struct subject_map {
74694+ struct acl_subject_label *user;
74695+ struct acl_subject_label *kernel;
74696+ struct subject_map *prev;
74697+ struct subject_map *next;
74698+};
74699+
74700+struct acl_subj_map_db {
74701+ struct subject_map **s_hash;
74702+ __u32 s_size;
74703+};
74704+
74705+/* End Data Structures Section */
74706+
74707+/* Hash functions generated by empirical testing by Brad Spengler
74708+ Makes good use of the low bits of the inode. Generally 0-1 times
74709+ in loop for successful match. 0-3 for unsuccessful match.
74710+ Shift/add algorithm with modulus of table size and an XOR*/
74711+
74712+static __inline__ unsigned int
74713+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
74714+{
74715+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
74716+}
74717+
74718+ static __inline__ unsigned int
74719+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
74720+{
74721+ return ((const unsigned long)userp % sz);
74722+}
74723+
74724+static __inline__ unsigned int
74725+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
74726+{
74727+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
74728+}
74729+
74730+static __inline__ unsigned int
74731+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
74732+{
74733+ return full_name_hash((const unsigned char *)name, len) % sz;
74734+}
74735+
74736+#define FOR_EACH_ROLE_START(role) \
74737+ role = role_list; \
74738+ while (role) {
74739+
74740+#define FOR_EACH_ROLE_END(role) \
74741+ role = role->prev; \
74742+ }
74743+
74744+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
74745+ subj = NULL; \
74746+ iter = 0; \
74747+ while (iter < role->subj_hash_size) { \
74748+ if (subj == NULL) \
74749+ subj = role->subj_hash[iter]; \
74750+ if (subj == NULL) { \
74751+ iter++; \
74752+ continue; \
74753+ }
74754+
74755+#define FOR_EACH_SUBJECT_END(subj,iter) \
74756+ subj = subj->next; \
74757+ if (subj == NULL) \
74758+ iter++; \
74759+ }
74760+
74761+
74762+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
74763+ subj = role->hash->first; \
74764+ while (subj != NULL) {
74765+
74766+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
74767+ subj = subj->next; \
74768+ }
74769+
74770+#endif
74771+
74772diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
74773new file mode 100644
74774index 0000000..33ebd1f
74775--- /dev/null
74776+++ b/include/linux/gracl_compat.h
74777@@ -0,0 +1,156 @@
74778+#ifndef GR_ACL_COMPAT_H
74779+#define GR_ACL_COMPAT_H
74780+
74781+#include <linux/resource.h>
74782+#include <asm/resource.h>
74783+
74784+struct sprole_pw_compat {
74785+ compat_uptr_t rolename;
74786+ unsigned char salt[GR_SALT_LEN];
74787+ unsigned char sum[GR_SHA_LEN];
74788+};
74789+
74790+struct gr_hash_struct_compat {
74791+ compat_uptr_t table;
74792+ compat_uptr_t nametable;
74793+ compat_uptr_t first;
74794+ __u32 table_size;
74795+ __u32 used_size;
74796+ int type;
74797+};
74798+
74799+struct acl_subject_label_compat {
74800+ compat_uptr_t filename;
74801+ compat_ino_t inode;
74802+ __u32 device;
74803+ __u32 mode;
74804+ kernel_cap_t cap_mask;
74805+ kernel_cap_t cap_lower;
74806+ kernel_cap_t cap_invert_audit;
74807+
74808+ struct compat_rlimit res[GR_NLIMITS];
74809+ __u32 resmask;
74810+
74811+ __u8 user_trans_type;
74812+ __u8 group_trans_type;
74813+ compat_uptr_t user_transitions;
74814+ compat_uptr_t group_transitions;
74815+ __u16 user_trans_num;
74816+ __u16 group_trans_num;
74817+
74818+ __u32 sock_families[2];
74819+ __u32 ip_proto[8];
74820+ __u32 ip_type;
74821+ compat_uptr_t ips;
74822+ __u32 ip_num;
74823+ __u32 inaddr_any_override;
74824+
74825+ __u32 crashes;
74826+ compat_ulong_t expires;
74827+
74828+ compat_uptr_t parent_subject;
74829+ compat_uptr_t hash;
74830+ compat_uptr_t prev;
74831+ compat_uptr_t next;
74832+
74833+ compat_uptr_t obj_hash;
74834+ __u32 obj_hash_size;
74835+ __u16 pax_flags;
74836+};
74837+
74838+struct role_allowed_ip_compat {
74839+ __u32 addr;
74840+ __u32 netmask;
74841+
74842+ compat_uptr_t prev;
74843+ compat_uptr_t next;
74844+};
74845+
74846+struct role_transition_compat {
74847+ compat_uptr_t rolename;
74848+
74849+ compat_uptr_t prev;
74850+ compat_uptr_t next;
74851+};
74852+
74853+struct acl_role_label_compat {
74854+ compat_uptr_t rolename;
74855+ uid_t uidgid;
74856+ __u16 roletype;
74857+
74858+ __u16 auth_attempts;
74859+ compat_ulong_t expires;
74860+
74861+ compat_uptr_t root_label;
74862+ compat_uptr_t hash;
74863+
74864+ compat_uptr_t prev;
74865+ compat_uptr_t next;
74866+
74867+ compat_uptr_t transitions;
74868+ compat_uptr_t allowed_ips;
74869+ compat_uptr_t domain_children;
74870+ __u16 domain_child_num;
74871+
74872+ umode_t umask;
74873+
74874+ compat_uptr_t subj_hash;
74875+ __u32 subj_hash_size;
74876+};
74877+
74878+struct user_acl_role_db_compat {
74879+ compat_uptr_t r_table;
74880+ __u32 num_pointers;
74881+ __u32 num_roles;
74882+ __u32 num_domain_children;
74883+ __u32 num_subjects;
74884+ __u32 num_objects;
74885+};
74886+
74887+struct acl_object_label_compat {
74888+ compat_uptr_t filename;
74889+ compat_ino_t inode;
74890+ __u32 device;
74891+ __u32 mode;
74892+
74893+ compat_uptr_t nested;
74894+ compat_uptr_t globbed;
74895+
74896+ compat_uptr_t prev;
74897+ compat_uptr_t next;
74898+};
74899+
74900+struct acl_ip_label_compat {
74901+ compat_uptr_t iface;
74902+ __u32 addr;
74903+ __u32 netmask;
74904+ __u16 low, high;
74905+ __u8 mode;
74906+ __u32 type;
74907+ __u32 proto[8];
74908+
74909+ compat_uptr_t prev;
74910+ compat_uptr_t next;
74911+};
74912+
74913+struct gr_arg_compat {
74914+ struct user_acl_role_db_compat role_db;
74915+ unsigned char pw[GR_PW_LEN];
74916+ unsigned char salt[GR_SALT_LEN];
74917+ unsigned char sum[GR_SHA_LEN];
74918+ unsigned char sp_role[GR_SPROLE_LEN];
74919+ compat_uptr_t sprole_pws;
74920+ __u32 segv_device;
74921+ compat_ino_t segv_inode;
74922+ uid_t segv_uid;
74923+ __u16 num_sprole_pws;
74924+ __u16 mode;
74925+};
74926+
74927+struct gr_arg_wrapper_compat {
74928+ compat_uptr_t arg;
74929+ __u32 version;
74930+ __u32 size;
74931+};
74932+
74933+#endif
74934diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
74935new file mode 100644
74936index 0000000..323ecf2
74937--- /dev/null
74938+++ b/include/linux/gralloc.h
74939@@ -0,0 +1,9 @@
74940+#ifndef __GRALLOC_H
74941+#define __GRALLOC_H
74942+
74943+void acl_free_all(void);
74944+int acl_alloc_stack_init(unsigned long size);
74945+void *acl_alloc(unsigned long len);
74946+void *acl_alloc_num(unsigned long num, unsigned long len);
74947+
74948+#endif
74949diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
74950new file mode 100644
74951index 0000000..be66033
74952--- /dev/null
74953+++ b/include/linux/grdefs.h
74954@@ -0,0 +1,140 @@
74955+#ifndef GRDEFS_H
74956+#define GRDEFS_H
74957+
74958+/* Begin grsecurity status declarations */
74959+
74960+enum {
74961+ GR_READY = 0x01,
74962+ GR_STATUS_INIT = 0x00 // disabled state
74963+};
74964+
74965+/* Begin ACL declarations */
74966+
74967+/* Role flags */
74968+
74969+enum {
74970+ GR_ROLE_USER = 0x0001,
74971+ GR_ROLE_GROUP = 0x0002,
74972+ GR_ROLE_DEFAULT = 0x0004,
74973+ GR_ROLE_SPECIAL = 0x0008,
74974+ GR_ROLE_AUTH = 0x0010,
74975+ GR_ROLE_NOPW = 0x0020,
74976+ GR_ROLE_GOD = 0x0040,
74977+ GR_ROLE_LEARN = 0x0080,
74978+ GR_ROLE_TPE = 0x0100,
74979+ GR_ROLE_DOMAIN = 0x0200,
74980+ GR_ROLE_PAM = 0x0400,
74981+ GR_ROLE_PERSIST = 0x0800
74982+};
74983+
74984+/* ACL Subject and Object mode flags */
74985+enum {
74986+ GR_DELETED = 0x80000000
74987+};
74988+
74989+/* ACL Object-only mode flags */
74990+enum {
74991+ GR_READ = 0x00000001,
74992+ GR_APPEND = 0x00000002,
74993+ GR_WRITE = 0x00000004,
74994+ GR_EXEC = 0x00000008,
74995+ GR_FIND = 0x00000010,
74996+ GR_INHERIT = 0x00000020,
74997+ GR_SETID = 0x00000040,
74998+ GR_CREATE = 0x00000080,
74999+ GR_DELETE = 0x00000100,
75000+ GR_LINK = 0x00000200,
75001+ GR_AUDIT_READ = 0x00000400,
75002+ GR_AUDIT_APPEND = 0x00000800,
75003+ GR_AUDIT_WRITE = 0x00001000,
75004+ GR_AUDIT_EXEC = 0x00002000,
75005+ GR_AUDIT_FIND = 0x00004000,
75006+ GR_AUDIT_INHERIT= 0x00008000,
75007+ GR_AUDIT_SETID = 0x00010000,
75008+ GR_AUDIT_CREATE = 0x00020000,
75009+ GR_AUDIT_DELETE = 0x00040000,
75010+ GR_AUDIT_LINK = 0x00080000,
75011+ GR_PTRACERD = 0x00100000,
75012+ GR_NOPTRACE = 0x00200000,
75013+ GR_SUPPRESS = 0x00400000,
75014+ GR_NOLEARN = 0x00800000,
75015+ GR_INIT_TRANSFER= 0x01000000
75016+};
75017+
75018+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
75019+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
75020+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
75021+
75022+/* ACL subject-only mode flags */
75023+enum {
75024+ GR_KILL = 0x00000001,
75025+ GR_VIEW = 0x00000002,
75026+ GR_PROTECTED = 0x00000004,
75027+ GR_LEARN = 0x00000008,
75028+ GR_OVERRIDE = 0x00000010,
75029+ /* just a placeholder, this mode is only used in userspace */
75030+ GR_DUMMY = 0x00000020,
75031+ GR_PROTSHM = 0x00000040,
75032+ GR_KILLPROC = 0x00000080,
75033+ GR_KILLIPPROC = 0x00000100,
75034+ /* just a placeholder, this mode is only used in userspace */
75035+ GR_NOTROJAN = 0x00000200,
75036+ GR_PROTPROCFD = 0x00000400,
75037+ GR_PROCACCT = 0x00000800,
75038+ GR_RELAXPTRACE = 0x00001000,
75039+ //GR_NESTED = 0x00002000,
75040+ GR_INHERITLEARN = 0x00004000,
75041+ GR_PROCFIND = 0x00008000,
75042+ GR_POVERRIDE = 0x00010000,
75043+ GR_KERNELAUTH = 0x00020000,
75044+ GR_ATSECURE = 0x00040000,
75045+ GR_SHMEXEC = 0x00080000
75046+};
75047+
75048+enum {
75049+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
75050+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
75051+ GR_PAX_ENABLE_MPROTECT = 0x0004,
75052+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
75053+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
75054+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
75055+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
75056+ GR_PAX_DISABLE_MPROTECT = 0x0400,
75057+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
75058+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
75059+};
75060+
75061+enum {
75062+ GR_ID_USER = 0x01,
75063+ GR_ID_GROUP = 0x02,
75064+};
75065+
75066+enum {
75067+ GR_ID_ALLOW = 0x01,
75068+ GR_ID_DENY = 0x02,
75069+};
75070+
75071+#define GR_CRASH_RES 31
75072+#define GR_UIDTABLE_MAX 500
75073+
75074+/* begin resource learning section */
75075+enum {
75076+ GR_RLIM_CPU_BUMP = 60,
75077+ GR_RLIM_FSIZE_BUMP = 50000,
75078+ GR_RLIM_DATA_BUMP = 10000,
75079+ GR_RLIM_STACK_BUMP = 1000,
75080+ GR_RLIM_CORE_BUMP = 10000,
75081+ GR_RLIM_RSS_BUMP = 500000,
75082+ GR_RLIM_NPROC_BUMP = 1,
75083+ GR_RLIM_NOFILE_BUMP = 5,
75084+ GR_RLIM_MEMLOCK_BUMP = 50000,
75085+ GR_RLIM_AS_BUMP = 500000,
75086+ GR_RLIM_LOCKS_BUMP = 2,
75087+ GR_RLIM_SIGPENDING_BUMP = 5,
75088+ GR_RLIM_MSGQUEUE_BUMP = 10000,
75089+ GR_RLIM_NICE_BUMP = 1,
75090+ GR_RLIM_RTPRIO_BUMP = 1,
75091+ GR_RLIM_RTTIME_BUMP = 1000000
75092+};
75093+
75094+#endif
75095diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
75096new file mode 100644
75097index 0000000..e337683
75098--- /dev/null
75099+++ b/include/linux/grinternal.h
75100@@ -0,0 +1,229 @@
75101+#ifndef __GRINTERNAL_H
75102+#define __GRINTERNAL_H
75103+
75104+#ifdef CONFIG_GRKERNSEC
75105+
75106+#include <linux/fs.h>
75107+#include <linux/mnt_namespace.h>
75108+#include <linux/nsproxy.h>
75109+#include <linux/gracl.h>
75110+#include <linux/grdefs.h>
75111+#include <linux/grmsg.h>
75112+
75113+void gr_add_learn_entry(const char *fmt, ...)
75114+ __attribute__ ((format (printf, 1, 2)));
75115+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
75116+ const struct vfsmount *mnt);
75117+__u32 gr_check_create(const struct dentry *new_dentry,
75118+ const struct dentry *parent,
75119+ const struct vfsmount *mnt, const __u32 mode);
75120+int gr_check_protected_task(const struct task_struct *task);
75121+__u32 to_gr_audit(const __u32 reqmode);
75122+int gr_set_acls(const int type);
75123+int gr_apply_subject_to_task(struct task_struct *task);
75124+int gr_acl_is_enabled(void);
75125+char gr_roletype_to_char(void);
75126+
75127+void gr_handle_alertkill(struct task_struct *task);
75128+char *gr_to_filename(const struct dentry *dentry,
75129+ const struct vfsmount *mnt);
75130+char *gr_to_filename1(const struct dentry *dentry,
75131+ const struct vfsmount *mnt);
75132+char *gr_to_filename2(const struct dentry *dentry,
75133+ const struct vfsmount *mnt);
75134+char *gr_to_filename3(const struct dentry *dentry,
75135+ const struct vfsmount *mnt);
75136+
75137+extern int grsec_enable_ptrace_readexec;
75138+extern int grsec_enable_harden_ptrace;
75139+extern int grsec_enable_link;
75140+extern int grsec_enable_fifo;
75141+extern int grsec_enable_execve;
75142+extern int grsec_enable_shm;
75143+extern int grsec_enable_execlog;
75144+extern int grsec_enable_signal;
75145+extern int grsec_enable_audit_ptrace;
75146+extern int grsec_enable_forkfail;
75147+extern int grsec_enable_time;
75148+extern int grsec_enable_rofs;
75149+extern int grsec_deny_new_usb;
75150+extern int grsec_enable_chroot_shmat;
75151+extern int grsec_enable_chroot_mount;
75152+extern int grsec_enable_chroot_double;
75153+extern int grsec_enable_chroot_pivot;
75154+extern int grsec_enable_chroot_chdir;
75155+extern int grsec_enable_chroot_chmod;
75156+extern int grsec_enable_chroot_mknod;
75157+extern int grsec_enable_chroot_fchdir;
75158+extern int grsec_enable_chroot_nice;
75159+extern int grsec_enable_chroot_execlog;
75160+extern int grsec_enable_chroot_caps;
75161+extern int grsec_enable_chroot_sysctl;
75162+extern int grsec_enable_chroot_unix;
75163+extern int grsec_enable_symlinkown;
75164+extern kgid_t grsec_symlinkown_gid;
75165+extern int grsec_enable_tpe;
75166+extern kgid_t grsec_tpe_gid;
75167+extern int grsec_enable_tpe_all;
75168+extern int grsec_enable_tpe_invert;
75169+extern int grsec_enable_socket_all;
75170+extern kgid_t grsec_socket_all_gid;
75171+extern int grsec_enable_socket_client;
75172+extern kgid_t grsec_socket_client_gid;
75173+extern int grsec_enable_socket_server;
75174+extern kgid_t grsec_socket_server_gid;
75175+extern kgid_t grsec_audit_gid;
75176+extern int grsec_enable_group;
75177+extern int grsec_enable_log_rwxmaps;
75178+extern int grsec_enable_mount;
75179+extern int grsec_enable_chdir;
75180+extern int grsec_resource_logging;
75181+extern int grsec_enable_blackhole;
75182+extern int grsec_lastack_retries;
75183+extern int grsec_enable_brute;
75184+extern int grsec_lock;
75185+
75186+extern spinlock_t grsec_alert_lock;
75187+extern unsigned long grsec_alert_wtime;
75188+extern unsigned long grsec_alert_fyet;
75189+
75190+extern spinlock_t grsec_audit_lock;
75191+
75192+extern rwlock_t grsec_exec_file_lock;
75193+
75194+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
75195+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
75196+ (tsk)->exec_file->f_path.mnt) : "/")
75197+
75198+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
75199+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
75200+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
75201+
75202+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
75203+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
75204+ (tsk)->exec_file->f_path.mnt) : "/")
75205+
75206+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
75207+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
75208+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
75209+
75210+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
75211+
75212+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
75213+
75214+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
75215+{
75216+ if (file1 && file2) {
75217+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
75218+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
75219+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
75220+ return true;
75221+ }
75222+
75223+ return false;
75224+}
75225+
75226+#define GR_CHROOT_CAPS {{ \
75227+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
75228+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
75229+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
75230+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
75231+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
75232+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
75233+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
75234+
75235+#define security_learn(normal_msg,args...) \
75236+({ \
75237+ read_lock(&grsec_exec_file_lock); \
75238+ gr_add_learn_entry(normal_msg "\n", ## args); \
75239+ read_unlock(&grsec_exec_file_lock); \
75240+})
75241+
75242+enum {
75243+ GR_DO_AUDIT,
75244+ GR_DONT_AUDIT,
75245+ /* used for non-audit messages that we shouldn't kill the task on */
75246+ GR_DONT_AUDIT_GOOD
75247+};
75248+
75249+enum {
75250+ GR_TTYSNIFF,
75251+ GR_RBAC,
75252+ GR_RBAC_STR,
75253+ GR_STR_RBAC,
75254+ GR_RBAC_MODE2,
75255+ GR_RBAC_MODE3,
75256+ GR_FILENAME,
75257+ GR_SYSCTL_HIDDEN,
75258+ GR_NOARGS,
75259+ GR_ONE_INT,
75260+ GR_ONE_INT_TWO_STR,
75261+ GR_ONE_STR,
75262+ GR_STR_INT,
75263+ GR_TWO_STR_INT,
75264+ GR_TWO_INT,
75265+ GR_TWO_U64,
75266+ GR_THREE_INT,
75267+ GR_FIVE_INT_TWO_STR,
75268+ GR_TWO_STR,
75269+ GR_THREE_STR,
75270+ GR_FOUR_STR,
75271+ GR_STR_FILENAME,
75272+ GR_FILENAME_STR,
75273+ GR_FILENAME_TWO_INT,
75274+ GR_FILENAME_TWO_INT_STR,
75275+ GR_TEXTREL,
75276+ GR_PTRACE,
75277+ GR_RESOURCE,
75278+ GR_CAP,
75279+ GR_SIG,
75280+ GR_SIG2,
75281+ GR_CRASH1,
75282+ GR_CRASH2,
75283+ GR_PSACCT,
75284+ GR_RWXMAP,
75285+ GR_RWXMAPVMA
75286+};
75287+
75288+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
75289+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
75290+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
75291+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
75292+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
75293+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
75294+#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)
75295+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
75296+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
75297+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
75298+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
75299+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
75300+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
75301+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
75302+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
75303+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
75304+#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)
75305+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
75306+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
75307+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
75308+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
75309+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
75310+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
75311+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
75312+#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)
75313+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
75314+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
75315+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
75316+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
75317+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
75318+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
75319+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
75320+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
75321+#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)
75322+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
75323+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
75324+
75325+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
75326+
75327+#endif
75328+
75329+#endif
75330diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
75331new file mode 100644
75332index 0000000..a4396b5
75333--- /dev/null
75334+++ b/include/linux/grmsg.h
75335@@ -0,0 +1,113 @@
75336+#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"
75337+#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"
75338+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
75339+#define GR_STOPMOD_MSG "denied modification of module state by "
75340+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
75341+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
75342+#define GR_IOPERM_MSG "denied use of ioperm() by "
75343+#define GR_IOPL_MSG "denied use of iopl() by "
75344+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
75345+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
75346+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
75347+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
75348+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
75349+#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"
75350+#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"
75351+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
75352+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
75353+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
75354+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
75355+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
75356+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
75357+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
75358+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
75359+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
75360+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
75361+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
75362+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
75363+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
75364+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
75365+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
75366+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
75367+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
75368+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
75369+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
75370+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
75371+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
75372+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
75373+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
75374+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
75375+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
75376+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
75377+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
75378+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
75379+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
75380+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
75381+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
75382+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
75383+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
75384+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
75385+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
75386+#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"
75387+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
75388+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
75389+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
75390+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
75391+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
75392+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
75393+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
75394+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
75395+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
75396+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
75397+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
75398+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
75399+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
75400+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
75401+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
75402+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
75403+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
75404+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
75405+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
75406+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
75407+#define GR_FAILFORK_MSG "failed fork with errno %s by "
75408+#define GR_NICE_CHROOT_MSG "denied priority change by "
75409+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
75410+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
75411+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
75412+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
75413+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
75414+#define GR_TIME_MSG "time set by "
75415+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
75416+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
75417+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
75418+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
75419+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
75420+#define GR_BIND_MSG "denied bind() by "
75421+#define GR_CONNECT_MSG "denied connect() by "
75422+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
75423+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
75424+#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"
75425+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
75426+#define GR_CAP_ACL_MSG "use of %s denied for "
75427+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
75428+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
75429+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
75430+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
75431+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
75432+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
75433+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
75434+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
75435+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
75436+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
75437+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
75438+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
75439+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
75440+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
75441+#define GR_VM86_MSG "denied use of vm86 by "
75442+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
75443+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
75444+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
75445+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
75446+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
75447+#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 "
75448+#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 "
75449diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
75450new file mode 100644
75451index 0000000..d6f5a21
75452--- /dev/null
75453+++ b/include/linux/grsecurity.h
75454@@ -0,0 +1,244 @@
75455+#ifndef GR_SECURITY_H
75456+#define GR_SECURITY_H
75457+#include <linux/fs.h>
75458+#include <linux/fs_struct.h>
75459+#include <linux/binfmts.h>
75460+#include <linux/gracl.h>
75461+
75462+/* notify of brain-dead configs */
75463+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75464+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
75465+#endif
75466+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
75467+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
75468+#endif
75469+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
75470+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
75471+#endif
75472+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
75473+#error "CONFIG_PAX enabled, but no PaX options are enabled."
75474+#endif
75475+
75476+int gr_handle_new_usb(void);
75477+
75478+void gr_handle_brute_attach(unsigned long mm_flags);
75479+void gr_handle_brute_check(void);
75480+void gr_handle_kernel_exploit(void);
75481+
75482+char gr_roletype_to_char(void);
75483+
75484+int gr_acl_enable_at_secure(void);
75485+
75486+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
75487+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
75488+
75489+void gr_del_task_from_ip_table(struct task_struct *p);
75490+
75491+int gr_pid_is_chrooted(struct task_struct *p);
75492+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
75493+int gr_handle_chroot_nice(void);
75494+int gr_handle_chroot_sysctl(const int op);
75495+int gr_handle_chroot_setpriority(struct task_struct *p,
75496+ const int niceval);
75497+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
75498+int gr_handle_chroot_chroot(const struct dentry *dentry,
75499+ const struct vfsmount *mnt);
75500+void gr_handle_chroot_chdir(const struct path *path);
75501+int gr_handle_chroot_chmod(const struct dentry *dentry,
75502+ const struct vfsmount *mnt, const int mode);
75503+int gr_handle_chroot_mknod(const struct dentry *dentry,
75504+ const struct vfsmount *mnt, const int mode);
75505+int gr_handle_chroot_mount(const struct dentry *dentry,
75506+ const struct vfsmount *mnt,
75507+ const char *dev_name);
75508+int gr_handle_chroot_pivot(void);
75509+int gr_handle_chroot_unix(const pid_t pid);
75510+
75511+int gr_handle_rawio(const struct inode *inode);
75512+
75513+void gr_handle_ioperm(void);
75514+void gr_handle_iopl(void);
75515+
75516+umode_t gr_acl_umask(void);
75517+
75518+int gr_tpe_allow(const struct file *file);
75519+
75520+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
75521+void gr_clear_chroot_entries(struct task_struct *task);
75522+
75523+void gr_log_forkfail(const int retval);
75524+void gr_log_timechange(void);
75525+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
75526+void gr_log_chdir(const struct dentry *dentry,
75527+ const struct vfsmount *mnt);
75528+void gr_log_chroot_exec(const struct dentry *dentry,
75529+ const struct vfsmount *mnt);
75530+void gr_log_remount(const char *devname, const int retval);
75531+void gr_log_unmount(const char *devname, const int retval);
75532+void gr_log_mount(const char *from, const char *to, const int retval);
75533+void gr_log_textrel(struct vm_area_struct *vma);
75534+void gr_log_ptgnustack(struct file *file);
75535+void gr_log_rwxmmap(struct file *file);
75536+void gr_log_rwxmprotect(struct vm_area_struct *vma);
75537+
75538+int gr_handle_follow_link(const struct inode *parent,
75539+ const struct inode *inode,
75540+ const struct dentry *dentry,
75541+ const struct vfsmount *mnt);
75542+int gr_handle_fifo(const struct dentry *dentry,
75543+ const struct vfsmount *mnt,
75544+ const struct dentry *dir, const int flag,
75545+ const int acc_mode);
75546+int gr_handle_hardlink(const struct dentry *dentry,
75547+ const struct vfsmount *mnt,
75548+ struct inode *inode,
75549+ const int mode, const struct filename *to);
75550+
75551+int gr_is_capable(const int cap);
75552+int gr_is_capable_nolog(const int cap);
75553+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
75554+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
75555+
75556+void gr_copy_label(struct task_struct *tsk);
75557+void gr_handle_crash(struct task_struct *task, const int sig);
75558+int gr_handle_signal(const struct task_struct *p, const int sig);
75559+int gr_check_crash_uid(const kuid_t uid);
75560+int gr_check_protected_task(const struct task_struct *task);
75561+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
75562+int gr_acl_handle_mmap(const struct file *file,
75563+ const unsigned long prot);
75564+int gr_acl_handle_mprotect(const struct file *file,
75565+ const unsigned long prot);
75566+int gr_check_hidden_task(const struct task_struct *tsk);
75567+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
75568+ const struct vfsmount *mnt);
75569+__u32 gr_acl_handle_utime(const struct dentry *dentry,
75570+ const struct vfsmount *mnt);
75571+__u32 gr_acl_handle_access(const struct dentry *dentry,
75572+ const struct vfsmount *mnt, const int fmode);
75573+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
75574+ const struct vfsmount *mnt, umode_t *mode);
75575+__u32 gr_acl_handle_chown(const struct dentry *dentry,
75576+ const struct vfsmount *mnt);
75577+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
75578+ const struct vfsmount *mnt);
75579+int gr_handle_ptrace(struct task_struct *task, const long request);
75580+int gr_handle_proc_ptrace(struct task_struct *task);
75581+__u32 gr_acl_handle_execve(const struct dentry *dentry,
75582+ const struct vfsmount *mnt);
75583+int gr_check_crash_exec(const struct file *filp);
75584+int gr_acl_is_enabled(void);
75585+void gr_set_kernel_label(struct task_struct *task);
75586+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
75587+ const kgid_t gid);
75588+int gr_set_proc_label(const struct dentry *dentry,
75589+ const struct vfsmount *mnt,
75590+ const int unsafe_flags);
75591+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
75592+ const struct vfsmount *mnt);
75593+__u32 gr_acl_handle_open(const struct dentry *dentry,
75594+ const struct vfsmount *mnt, int acc_mode);
75595+__u32 gr_acl_handle_creat(const struct dentry *dentry,
75596+ const struct dentry *p_dentry,
75597+ const struct vfsmount *p_mnt,
75598+ int open_flags, int acc_mode, const int imode);
75599+void gr_handle_create(const struct dentry *dentry,
75600+ const struct vfsmount *mnt);
75601+void gr_handle_proc_create(const struct dentry *dentry,
75602+ const struct inode *inode);
75603+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
75604+ const struct dentry *parent_dentry,
75605+ const struct vfsmount *parent_mnt,
75606+ const int mode);
75607+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
75608+ const struct dentry *parent_dentry,
75609+ const struct vfsmount *parent_mnt);
75610+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
75611+ const struct vfsmount *mnt);
75612+void gr_handle_delete(const ino_t ino, const dev_t dev);
75613+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
75614+ const struct vfsmount *mnt);
75615+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
75616+ const struct dentry *parent_dentry,
75617+ const struct vfsmount *parent_mnt,
75618+ const struct filename *from);
75619+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
75620+ const struct dentry *parent_dentry,
75621+ const struct vfsmount *parent_mnt,
75622+ const struct dentry *old_dentry,
75623+ const struct vfsmount *old_mnt, const struct filename *to);
75624+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
75625+int gr_acl_handle_rename(struct dentry *new_dentry,
75626+ struct dentry *parent_dentry,
75627+ const struct vfsmount *parent_mnt,
75628+ struct dentry *old_dentry,
75629+ struct inode *old_parent_inode,
75630+ struct vfsmount *old_mnt, const struct filename *newname);
75631+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
75632+ struct dentry *old_dentry,
75633+ struct dentry *new_dentry,
75634+ struct vfsmount *mnt, const __u8 replace);
75635+__u32 gr_check_link(const struct dentry *new_dentry,
75636+ const struct dentry *parent_dentry,
75637+ const struct vfsmount *parent_mnt,
75638+ const struct dentry *old_dentry,
75639+ const struct vfsmount *old_mnt);
75640+int gr_acl_handle_filldir(const struct file *file, const char *name,
75641+ const unsigned int namelen, const ino_t ino);
75642+
75643+__u32 gr_acl_handle_unix(const struct dentry *dentry,
75644+ const struct vfsmount *mnt);
75645+void gr_acl_handle_exit(void);
75646+void gr_acl_handle_psacct(struct task_struct *task, const long code);
75647+int gr_acl_handle_procpidmem(const struct task_struct *task);
75648+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
75649+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
75650+void gr_audit_ptrace(struct task_struct *task);
75651+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
75652+void gr_put_exec_file(struct task_struct *task);
75653+
75654+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
75655+
75656+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
75657+extern void gr_learn_resource(const struct task_struct *task, const int res,
75658+ const unsigned long wanted, const int gt);
75659+#else
75660+static inline void gr_learn_resource(const struct task_struct *task, const int res,
75661+ const unsigned long wanted, const int gt)
75662+{
75663+}
75664+#endif
75665+
75666+#ifdef CONFIG_GRKERNSEC_RESLOG
75667+extern void gr_log_resource(const struct task_struct *task, const int res,
75668+ const unsigned long wanted, const int gt);
75669+#else
75670+static inline void gr_log_resource(const struct task_struct *task, const int res,
75671+ const unsigned long wanted, const int gt)
75672+{
75673+}
75674+#endif
75675+
75676+#ifdef CONFIG_GRKERNSEC
75677+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
75678+void gr_handle_vm86(void);
75679+void gr_handle_mem_readwrite(u64 from, u64 to);
75680+
75681+void gr_log_badprocpid(const char *entry);
75682+
75683+extern int grsec_enable_dmesg;
75684+extern int grsec_disable_privio;
75685+
75686+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75687+extern kgid_t grsec_proc_gid;
75688+#endif
75689+
75690+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75691+extern int grsec_enable_chroot_findtask;
75692+#endif
75693+#ifdef CONFIG_GRKERNSEC_SETXID
75694+extern int grsec_enable_setxid;
75695+#endif
75696+#endif
75697+
75698+#endif
75699diff --git a/include/linux/grsock.h b/include/linux/grsock.h
75700new file mode 100644
75701index 0000000..e7ffaaf
75702--- /dev/null
75703+++ b/include/linux/grsock.h
75704@@ -0,0 +1,19 @@
75705+#ifndef __GRSOCK_H
75706+#define __GRSOCK_H
75707+
75708+extern void gr_attach_curr_ip(const struct sock *sk);
75709+extern int gr_handle_sock_all(const int family, const int type,
75710+ const int protocol);
75711+extern int gr_handle_sock_server(const struct sockaddr *sck);
75712+extern int gr_handle_sock_server_other(const struct sock *sck);
75713+extern int gr_handle_sock_client(const struct sockaddr *sck);
75714+extern int gr_search_connect(struct socket * sock,
75715+ struct sockaddr_in * addr);
75716+extern int gr_search_bind(struct socket * sock,
75717+ struct sockaddr_in * addr);
75718+extern int gr_search_listen(struct socket * sock);
75719+extern int gr_search_accept(struct socket * sock);
75720+extern int gr_search_socket(const int domain, const int type,
75721+ const int protocol);
75722+
75723+#endif
75724diff --git a/include/linux/hid.h b/include/linux/hid.h
75725index 0c48991..76e41d8 100644
75726--- a/include/linux/hid.h
75727+++ b/include/linux/hid.h
75728@@ -393,10 +393,12 @@ struct hid_report {
75729 struct hid_device *device; /* associated device */
75730 };
75731
75732+#define HID_MAX_IDS 256
75733+
75734 struct hid_report_enum {
75735 unsigned numbered;
75736 struct list_head report_list;
75737- struct hid_report *report_id_hash[256];
75738+ struct hid_report *report_id_hash[HID_MAX_IDS];
75739 };
75740
75741 #define HID_REPORT_TYPES 3
75742@@ -747,6 +749,10 @@ void hid_output_report(struct hid_report *report, __u8 *data);
75743 struct hid_device *hid_allocate_device(void);
75744 struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id);
75745 int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size);
75746+struct hid_report *hid_validate_report(struct hid_device *hid,
75747+ unsigned int type, unsigned int id,
75748+ unsigned int fields,
75749+ unsigned int report_counts);
75750 int hid_open_report(struct hid_device *device);
75751 int hid_check_keys_pressed(struct hid_device *hid);
75752 int hid_connect(struct hid_device *hid, unsigned int connect_mask);
75753diff --git a/include/linux/highmem.h b/include/linux/highmem.h
75754index 7fb31da..08b5114 100644
75755--- a/include/linux/highmem.h
75756+++ b/include/linux/highmem.h
75757@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
75758 kunmap_atomic(kaddr);
75759 }
75760
75761+static inline void sanitize_highpage(struct page *page)
75762+{
75763+ void *kaddr;
75764+ unsigned long flags;
75765+
75766+ local_irq_save(flags);
75767+ kaddr = kmap_atomic(page);
75768+ clear_page(kaddr);
75769+ kunmap_atomic(kaddr);
75770+ local_irq_restore(flags);
75771+}
75772+
75773 static inline void zero_user_segments(struct page *page,
75774 unsigned start1, unsigned end1,
75775 unsigned start2, unsigned end2)
75776diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
75777index 1c7b89a..7f52502 100644
75778--- a/include/linux/hwmon-sysfs.h
75779+++ b/include/linux/hwmon-sysfs.h
75780@@ -25,7 +25,8 @@
75781 struct sensor_device_attribute{
75782 struct device_attribute dev_attr;
75783 int index;
75784-};
75785+} __do_const;
75786+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
75787 #define to_sensor_dev_attr(_dev_attr) \
75788 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
75789
75790@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
75791 struct device_attribute dev_attr;
75792 u8 index;
75793 u8 nr;
75794-};
75795+} __do_const;
75796 #define to_sensor_dev_attr_2(_dev_attr) \
75797 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
75798
75799diff --git a/include/linux/i2c.h b/include/linux/i2c.h
75800index e988fa9..ff9f17e 100644
75801--- a/include/linux/i2c.h
75802+++ b/include/linux/i2c.h
75803@@ -366,6 +366,7 @@ struct i2c_algorithm {
75804 /* To determine what the adapter supports */
75805 u32 (*functionality) (struct i2c_adapter *);
75806 };
75807+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
75808
75809 /**
75810 * struct i2c_bus_recovery_info - I2C bus recovery information
75811diff --git a/include/linux/i2o.h b/include/linux/i2o.h
75812index d23c3c2..eb63c81 100644
75813--- a/include/linux/i2o.h
75814+++ b/include/linux/i2o.h
75815@@ -565,7 +565,7 @@ struct i2o_controller {
75816 struct i2o_device *exec; /* Executive */
75817 #if BITS_PER_LONG == 64
75818 spinlock_t context_list_lock; /* lock for context_list */
75819- atomic_t context_list_counter; /* needed for unique contexts */
75820+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
75821 struct list_head context_list; /* list of context id's
75822 and pointers */
75823 #endif
75824diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
75825index aff7ad8..3942bbd 100644
75826--- a/include/linux/if_pppox.h
75827+++ b/include/linux/if_pppox.h
75828@@ -76,7 +76,7 @@ struct pppox_proto {
75829 int (*ioctl)(struct socket *sock, unsigned int cmd,
75830 unsigned long arg);
75831 struct module *owner;
75832-};
75833+} __do_const;
75834
75835 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
75836 extern void unregister_pppox_proto(int proto_num);
75837diff --git a/include/linux/init.h b/include/linux/init.h
75838index 8618147..0821126 100644
75839--- a/include/linux/init.h
75840+++ b/include/linux/init.h
75841@@ -39,9 +39,36 @@
75842 * Also note, that this data cannot be "const".
75843 */
75844
75845+#ifdef MODULE
75846+#define add_init_latent_entropy
75847+#define add_devinit_latent_entropy
75848+#define add_cpuinit_latent_entropy
75849+#define add_meminit_latent_entropy
75850+#else
75851+#define add_init_latent_entropy __latent_entropy
75852+
75853+#ifdef CONFIG_HOTPLUG
75854+#define add_devinit_latent_entropy
75855+#else
75856+#define add_devinit_latent_entropy __latent_entropy
75857+#endif
75858+
75859+#ifdef CONFIG_HOTPLUG_CPU
75860+#define add_cpuinit_latent_entropy
75861+#else
75862+#define add_cpuinit_latent_entropy __latent_entropy
75863+#endif
75864+
75865+#ifdef CONFIG_MEMORY_HOTPLUG
75866+#define add_meminit_latent_entropy
75867+#else
75868+#define add_meminit_latent_entropy __latent_entropy
75869+#endif
75870+#endif
75871+
75872 /* These are for everybody (although not all archs will actually
75873 discard it in modules) */
75874-#define __init __section(.init.text) __cold notrace
75875+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
75876 #define __initdata __section(.init.data)
75877 #define __initconst __constsection(.init.rodata)
75878 #define __exitdata __section(.exit.data)
75879@@ -94,7 +121,7 @@
75880 #define __exit __section(.exit.text) __exitused __cold notrace
75881
75882 /* Used for HOTPLUG_CPU */
75883-#define __cpuinit __section(.cpuinit.text) __cold notrace
75884+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
75885 #define __cpuinitdata __section(.cpuinit.data)
75886 #define __cpuinitconst __constsection(.cpuinit.rodata)
75887 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
75888@@ -102,7 +129,7 @@
75889 #define __cpuexitconst __constsection(.cpuexit.rodata)
75890
75891 /* Used for MEMORY_HOTPLUG */
75892-#define __meminit __section(.meminit.text) __cold notrace
75893+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
75894 #define __meminitdata __section(.meminit.data)
75895 #define __meminitconst __constsection(.meminit.rodata)
75896 #define __memexit __section(.memexit.text) __exitused __cold notrace
75897diff --git a/include/linux/init_task.h b/include/linux/init_task.h
75898index 5cd0f09..c9f67cc 100644
75899--- a/include/linux/init_task.h
75900+++ b/include/linux/init_task.h
75901@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
75902
75903 #define INIT_TASK_COMM "swapper"
75904
75905+#ifdef CONFIG_X86
75906+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
75907+#else
75908+#define INIT_TASK_THREAD_INFO
75909+#endif
75910+
75911 /*
75912 * INIT_TASK is used to set up the first task table, touch at
75913 * your own risk!. Base=0, limit=0x1fffff (=2MB)
75914@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
75915 RCU_POINTER_INITIALIZER(cred, &init_cred), \
75916 .comm = INIT_TASK_COMM, \
75917 .thread = INIT_THREAD, \
75918+ INIT_TASK_THREAD_INFO \
75919 .fs = &init_fs, \
75920 .files = &init_files, \
75921 .signal = &init_signals, \
75922diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
75923index 5fa5afe..ac55b25 100644
75924--- a/include/linux/interrupt.h
75925+++ b/include/linux/interrupt.h
75926@@ -430,7 +430,7 @@ enum
75927 /* map softirq index to softirq name. update 'softirq_to_name' in
75928 * kernel/softirq.c when adding a new softirq.
75929 */
75930-extern char *softirq_to_name[NR_SOFTIRQS];
75931+extern const char * const softirq_to_name[NR_SOFTIRQS];
75932
75933 /* softirq mask and active fields moved to irq_cpustat_t in
75934 * asm/hardirq.h to get better cache usage. KAO
75935@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
75936
75937 struct softirq_action
75938 {
75939- void (*action)(struct softirq_action *);
75940-};
75941+ void (*action)(void);
75942+} __no_const;
75943
75944 asmlinkage void do_softirq(void);
75945 asmlinkage void __do_softirq(void);
75946-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
75947+extern void open_softirq(int nr, void (*action)(void));
75948 extern void softirq_init(void);
75949 extern void __raise_softirq_irqoff(unsigned int nr);
75950
75951diff --git a/include/linux/iommu.h b/include/linux/iommu.h
75952index 3aeb730..2177f39 100644
75953--- a/include/linux/iommu.h
75954+++ b/include/linux/iommu.h
75955@@ -113,7 +113,7 @@ struct iommu_ops {
75956 u32 (*domain_get_windows)(struct iommu_domain *domain);
75957
75958 unsigned long pgsize_bitmap;
75959-};
75960+} __do_const;
75961
75962 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
75963 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
75964diff --git a/include/linux/ioport.h b/include/linux/ioport.h
75965index 89b7c24..382af74 100644
75966--- a/include/linux/ioport.h
75967+++ b/include/linux/ioport.h
75968@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
75969 int adjust_resource(struct resource *res, resource_size_t start,
75970 resource_size_t size);
75971 resource_size_t resource_alignment(struct resource *res);
75972-static inline resource_size_t resource_size(const struct resource *res)
75973+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
75974 {
75975 return res->end - res->start + 1;
75976 }
75977diff --git a/include/linux/irq.h b/include/linux/irq.h
75978index bc4e066..50468a9 100644
75979--- a/include/linux/irq.h
75980+++ b/include/linux/irq.h
75981@@ -328,7 +328,8 @@ struct irq_chip {
75982 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
75983
75984 unsigned long flags;
75985-};
75986+} __do_const;
75987+typedef struct irq_chip __no_const irq_chip_no_const;
75988
75989 /*
75990 * irq_chip specific flags
75991diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
75992index 3e203eb..3fe68d0 100644
75993--- a/include/linux/irqchip/arm-gic.h
75994+++ b/include/linux/irqchip/arm-gic.h
75995@@ -59,9 +59,11 @@
75996
75997 #ifndef __ASSEMBLY__
75998
75999+#include <linux/irq.h>
76000+
76001 struct device_node;
76002
76003-extern struct irq_chip gic_arch_extn;
76004+extern irq_chip_no_const gic_arch_extn;
76005
76006 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
76007 u32 offset, struct device_node *);
76008diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
76009index 6883e19..e854fcb 100644
76010--- a/include/linux/kallsyms.h
76011+++ b/include/linux/kallsyms.h
76012@@ -15,7 +15,8 @@
76013
76014 struct module;
76015
76016-#ifdef CONFIG_KALLSYMS
76017+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
76018+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76019 /* Lookup the address for a symbol. Returns 0 if not found. */
76020 unsigned long kallsyms_lookup_name(const char *name);
76021
76022@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
76023 /* Stupid that this does nothing, but I didn't create this mess. */
76024 #define __print_symbol(fmt, addr)
76025 #endif /*CONFIG_KALLSYMS*/
76026+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
76027+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
76028+extern unsigned long kallsyms_lookup_name(const char *name);
76029+extern void __print_symbol(const char *fmt, unsigned long address);
76030+extern int sprint_backtrace(char *buffer, unsigned long address);
76031+extern int sprint_symbol(char *buffer, unsigned long address);
76032+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
76033+const char *kallsyms_lookup(unsigned long addr,
76034+ unsigned long *symbolsize,
76035+ unsigned long *offset,
76036+ char **modname, char *namebuf);
76037+extern int kallsyms_lookup_size_offset(unsigned long addr,
76038+ unsigned long *symbolsize,
76039+ unsigned long *offset);
76040+#endif
76041
76042 /* This macro allows us to keep printk typechecking */
76043 static __printf(1, 2)
76044diff --git a/include/linux/key-type.h b/include/linux/key-type.h
76045index 518a53a..5e28358 100644
76046--- a/include/linux/key-type.h
76047+++ b/include/linux/key-type.h
76048@@ -125,7 +125,7 @@ struct key_type {
76049 /* internal fields */
76050 struct list_head link; /* link in types list */
76051 struct lock_class_key lock_class; /* key->sem lock class */
76052-};
76053+} __do_const;
76054
76055 extern struct key_type key_type_keyring;
76056
76057diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
76058index c6e091b..a940adf 100644
76059--- a/include/linux/kgdb.h
76060+++ b/include/linux/kgdb.h
76061@@ -52,7 +52,7 @@ extern int kgdb_connected;
76062 extern int kgdb_io_module_registered;
76063
76064 extern atomic_t kgdb_setting_breakpoint;
76065-extern atomic_t kgdb_cpu_doing_single_step;
76066+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
76067
76068 extern struct task_struct *kgdb_usethread;
76069 extern struct task_struct *kgdb_contthread;
76070@@ -254,7 +254,7 @@ struct kgdb_arch {
76071 void (*correct_hw_break)(void);
76072
76073 void (*enable_nmi)(bool on);
76074-};
76075+} __do_const;
76076
76077 /**
76078 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
76079@@ -279,7 +279,7 @@ struct kgdb_io {
76080 void (*pre_exception) (void);
76081 void (*post_exception) (void);
76082 int is_console;
76083-};
76084+} __do_const;
76085
76086 extern struct kgdb_arch arch_kgdb_ops;
76087
76088diff --git a/include/linux/kmod.h b/include/linux/kmod.h
76089index 0555cc6..b16a7a4 100644
76090--- a/include/linux/kmod.h
76091+++ b/include/linux/kmod.h
76092@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
76093 * usually useless though. */
76094 extern __printf(2, 3)
76095 int __request_module(bool wait, const char *name, ...);
76096+extern __printf(3, 4)
76097+int ___request_module(bool wait, char *param_name, const char *name, ...);
76098 #define request_module(mod...) __request_module(true, mod)
76099 #define request_module_nowait(mod...) __request_module(false, mod)
76100 #define try_then_request_module(x, mod...) \
76101diff --git a/include/linux/kobject.h b/include/linux/kobject.h
76102index 939b112..ed6ed51 100644
76103--- a/include/linux/kobject.h
76104+++ b/include/linux/kobject.h
76105@@ -111,7 +111,7 @@ struct kobj_type {
76106 struct attribute **default_attrs;
76107 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
76108 const void *(*namespace)(struct kobject *kobj);
76109-};
76110+} __do_const;
76111
76112 struct kobj_uevent_env {
76113 char *envp[UEVENT_NUM_ENVP];
76114@@ -134,6 +134,7 @@ struct kobj_attribute {
76115 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
76116 const char *buf, size_t count);
76117 };
76118+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
76119
76120 extern const struct sysfs_ops kobj_sysfs_ops;
76121
76122diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
76123index f66b065..c2c29b4 100644
76124--- a/include/linux/kobject_ns.h
76125+++ b/include/linux/kobject_ns.h
76126@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
76127 const void *(*netlink_ns)(struct sock *sk);
76128 const void *(*initial_ns)(void);
76129 void (*drop_ns)(void *);
76130-};
76131+} __do_const;
76132
76133 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
76134 int kobj_ns_type_registered(enum kobj_ns_type type);
76135diff --git a/include/linux/kref.h b/include/linux/kref.h
76136index 484604d..0f6c5b6 100644
76137--- a/include/linux/kref.h
76138+++ b/include/linux/kref.h
76139@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
76140 static inline int kref_sub(struct kref *kref, unsigned int count,
76141 void (*release)(struct kref *kref))
76142 {
76143- WARN_ON(release == NULL);
76144+ BUG_ON(release == NULL);
76145
76146 if (atomic_sub_and_test((int) count, &kref->refcount)) {
76147 release(kref);
76148diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
76149index 8db53cf..c21121d 100644
76150--- a/include/linux/kvm_host.h
76151+++ b/include/linux/kvm_host.h
76152@@ -444,7 +444,7 @@ static inline void kvm_irqfd_exit(void)
76153 {
76154 }
76155 #endif
76156-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
76157+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
76158 struct module *module);
76159 void kvm_exit(void);
76160
76161@@ -616,7 +616,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
76162 struct kvm_guest_debug *dbg);
76163 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
76164
76165-int kvm_arch_init(void *opaque);
76166+int kvm_arch_init(const void *opaque);
76167 void kvm_arch_exit(void);
76168
76169 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
76170diff --git a/include/linux/libata.h b/include/linux/libata.h
76171index eae7a05..2cdd875 100644
76172--- a/include/linux/libata.h
76173+++ b/include/linux/libata.h
76174@@ -919,7 +919,7 @@ struct ata_port_operations {
76175 * fields must be pointers.
76176 */
76177 const struct ata_port_operations *inherits;
76178-};
76179+} __do_const;
76180
76181 struct ata_port_info {
76182 unsigned long flags;
76183diff --git a/include/linux/list.h b/include/linux/list.h
76184index b83e565..baa6c1d 100644
76185--- a/include/linux/list.h
76186+++ b/include/linux/list.h
76187@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
76188 extern void list_del(struct list_head *entry);
76189 #endif
76190
76191+extern void __pax_list_add(struct list_head *new,
76192+ struct list_head *prev,
76193+ struct list_head *next);
76194+static inline void pax_list_add(struct list_head *new, struct list_head *head)
76195+{
76196+ __pax_list_add(new, head, head->next);
76197+}
76198+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
76199+{
76200+ __pax_list_add(new, head->prev, head);
76201+}
76202+extern void pax_list_del(struct list_head *entry);
76203+
76204 /**
76205 * list_replace - replace old entry by new one
76206 * @old : the element to be replaced
76207@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
76208 INIT_LIST_HEAD(entry);
76209 }
76210
76211+extern void pax_list_del_init(struct list_head *entry);
76212+
76213 /**
76214 * list_move - delete from one list and add as another's head
76215 * @list: the entry to move
76216diff --git a/include/linux/math64.h b/include/linux/math64.h
76217index 2913b86..8dcbb1e 100644
76218--- a/include/linux/math64.h
76219+++ b/include/linux/math64.h
76220@@ -15,7 +15,7 @@
76221 * This is commonly provided by 32bit archs to provide an optimized 64bit
76222 * divide.
76223 */
76224-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76225+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76226 {
76227 *remainder = dividend % divisor;
76228 return dividend / divisor;
76229@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
76230 /**
76231 * div64_u64 - unsigned 64bit divide with 64bit divisor
76232 */
76233-static inline u64 div64_u64(u64 dividend, u64 divisor)
76234+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
76235 {
76236 return dividend / divisor;
76237 }
76238@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
76239 #define div64_ul(x, y) div_u64((x), (y))
76240
76241 #ifndef div_u64_rem
76242-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76243+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76244 {
76245 *remainder = do_div(dividend, divisor);
76246 return dividend;
76247@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
76248 * divide.
76249 */
76250 #ifndef div_u64
76251-static inline u64 div_u64(u64 dividend, u32 divisor)
76252+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
76253 {
76254 u32 remainder;
76255 return div_u64_rem(dividend, divisor, &remainder);
76256diff --git a/include/linux/mm.h b/include/linux/mm.h
76257index e0c8528..bcf0c29 100644
76258--- a/include/linux/mm.h
76259+++ b/include/linux/mm.h
76260@@ -104,6 +104,11 @@ extern unsigned int kobjsize(const void *objp);
76261 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
76262 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
76263 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
76264+
76265+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76266+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
76267+#endif
76268+
76269 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
76270
76271 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
76272@@ -205,8 +210,8 @@ struct vm_operations_struct {
76273 /* called by access_process_vm when get_user_pages() fails, typically
76274 * for use by special VMAs that can switch between memory and hardware
76275 */
76276- int (*access)(struct vm_area_struct *vma, unsigned long addr,
76277- void *buf, int len, int write);
76278+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
76279+ void *buf, size_t len, int write);
76280 #ifdef CONFIG_NUMA
76281 /*
76282 * set_policy() op must add a reference to any non-NULL @new mempolicy
76283@@ -236,6 +241,7 @@ struct vm_operations_struct {
76284 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
76285 unsigned long size, pgoff_t pgoff);
76286 };
76287+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
76288
76289 struct mmu_gather;
76290 struct inode;
76291@@ -980,8 +986,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
76292 unsigned long *pfn);
76293 int follow_phys(struct vm_area_struct *vma, unsigned long address,
76294 unsigned int flags, unsigned long *prot, resource_size_t *phys);
76295-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
76296- void *buf, int len, int write);
76297+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
76298+ void *buf, size_t len, int write);
76299
76300 static inline void unmap_shared_mapping_range(struct address_space *mapping,
76301 loff_t const holebegin, loff_t const holelen)
76302@@ -1020,9 +1026,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
76303 }
76304 #endif
76305
76306-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
76307-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
76308- void *buf, int len, int write);
76309+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
76310+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
76311+ void *buf, size_t len, int write);
76312
76313 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
76314 unsigned long start, unsigned long nr_pages,
76315@@ -1053,34 +1059,6 @@ int set_page_dirty(struct page *page);
76316 int set_page_dirty_lock(struct page *page);
76317 int clear_page_dirty_for_io(struct page *page);
76318
76319-/* Is the vma a continuation of the stack vma above it? */
76320-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
76321-{
76322- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
76323-}
76324-
76325-static inline int stack_guard_page_start(struct vm_area_struct *vma,
76326- unsigned long addr)
76327-{
76328- return (vma->vm_flags & VM_GROWSDOWN) &&
76329- (vma->vm_start == addr) &&
76330- !vma_growsdown(vma->vm_prev, addr);
76331-}
76332-
76333-/* Is the vma a continuation of the stack vma below it? */
76334-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
76335-{
76336- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
76337-}
76338-
76339-static inline int stack_guard_page_end(struct vm_area_struct *vma,
76340- unsigned long addr)
76341-{
76342- return (vma->vm_flags & VM_GROWSUP) &&
76343- (vma->vm_end == addr) &&
76344- !vma_growsup(vma->vm_next, addr);
76345-}
76346-
76347 extern pid_t
76348 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
76349
76350@@ -1180,6 +1158,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
76351 }
76352 #endif
76353
76354+#ifdef CONFIG_MMU
76355+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
76356+#else
76357+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
76358+{
76359+ return __pgprot(0);
76360+}
76361+#endif
76362+
76363 int vma_wants_writenotify(struct vm_area_struct *vma);
76364
76365 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
76366@@ -1198,8 +1185,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
76367 {
76368 return 0;
76369 }
76370+
76371+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
76372+ unsigned long address)
76373+{
76374+ return 0;
76375+}
76376 #else
76377 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
76378+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
76379 #endif
76380
76381 #ifdef __PAGETABLE_PMD_FOLDED
76382@@ -1208,8 +1202,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
76383 {
76384 return 0;
76385 }
76386+
76387+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
76388+ unsigned long address)
76389+{
76390+ return 0;
76391+}
76392 #else
76393 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
76394+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
76395 #endif
76396
76397 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
76398@@ -1227,11 +1228,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
76399 NULL: pud_offset(pgd, address);
76400 }
76401
76402+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76403+{
76404+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
76405+ NULL: pud_offset(pgd, address);
76406+}
76407+
76408 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
76409 {
76410 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
76411 NULL: pmd_offset(pud, address);
76412 }
76413+
76414+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
76415+{
76416+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
76417+ NULL: pmd_offset(pud, address);
76418+}
76419 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
76420
76421 #if USE_SPLIT_PTLOCKS
76422@@ -1517,6 +1530,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76423 unsigned long len, unsigned long prot, unsigned long flags,
76424 unsigned long pgoff, unsigned long *populate);
76425 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
76426+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
76427
76428 #ifdef CONFIG_MMU
76429 extern int __mm_populate(unsigned long addr, unsigned long len,
76430@@ -1545,10 +1559,11 @@ struct vm_unmapped_area_info {
76431 unsigned long high_limit;
76432 unsigned long align_mask;
76433 unsigned long align_offset;
76434+ unsigned long threadstack_offset;
76435 };
76436
76437-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
76438-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
76439+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
76440+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
76441
76442 /*
76443 * Search for an unmapped address range.
76444@@ -1560,7 +1575,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
76445 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
76446 */
76447 static inline unsigned long
76448-vm_unmapped_area(struct vm_unmapped_area_info *info)
76449+vm_unmapped_area(const struct vm_unmapped_area_info *info)
76450 {
76451 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
76452 return unmapped_area(info);
76453@@ -1623,6 +1638,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
76454 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
76455 struct vm_area_struct **pprev);
76456
76457+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
76458+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
76459+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
76460+
76461 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
76462 NULL if none. Assume start_addr < end_addr. */
76463 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
76464@@ -1651,15 +1670,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
76465 return vma;
76466 }
76467
76468-#ifdef CONFIG_MMU
76469-pgprot_t vm_get_page_prot(unsigned long vm_flags);
76470-#else
76471-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
76472-{
76473- return __pgprot(0);
76474-}
76475-#endif
76476-
76477 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
76478 unsigned long change_prot_numa(struct vm_area_struct *vma,
76479 unsigned long start, unsigned long end);
76480@@ -1711,6 +1721,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
76481 static inline void vm_stat_account(struct mm_struct *mm,
76482 unsigned long flags, struct file *file, long pages)
76483 {
76484+
76485+#ifdef CONFIG_PAX_RANDMMAP
76486+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
76487+#endif
76488+
76489 mm->total_vm += pages;
76490 }
76491 #endif /* CONFIG_PROC_FS */
76492@@ -1791,7 +1806,7 @@ extern int unpoison_memory(unsigned long pfn);
76493 extern int sysctl_memory_failure_early_kill;
76494 extern int sysctl_memory_failure_recovery;
76495 extern void shake_page(struct page *p, int access);
76496-extern atomic_long_t num_poisoned_pages;
76497+extern atomic_long_unchecked_t num_poisoned_pages;
76498 extern int soft_offline_page(struct page *page, int flags);
76499
76500 extern void dump_page(struct page *page);
76501@@ -1828,5 +1843,11 @@ void __init setup_nr_node_ids(void);
76502 static inline void setup_nr_node_ids(void) {}
76503 #endif
76504
76505+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76506+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
76507+#else
76508+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
76509+#endif
76510+
76511 #endif /* __KERNEL__ */
76512 #endif /* _LINUX_MM_H */
76513diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
76514index 4a189ba..04101d6 100644
76515--- a/include/linux/mm_types.h
76516+++ b/include/linux/mm_types.h
76517@@ -289,6 +289,8 @@ struct vm_area_struct {
76518 #ifdef CONFIG_NUMA
76519 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
76520 #endif
76521+
76522+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
76523 };
76524
76525 struct core_thread {
76526@@ -438,6 +440,24 @@ struct mm_struct {
76527 int first_nid;
76528 #endif
76529 struct uprobes_state uprobes_state;
76530+
76531+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76532+ unsigned long pax_flags;
76533+#endif
76534+
76535+#ifdef CONFIG_PAX_DLRESOLVE
76536+ unsigned long call_dl_resolve;
76537+#endif
76538+
76539+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
76540+ unsigned long call_syscall;
76541+#endif
76542+
76543+#ifdef CONFIG_PAX_ASLR
76544+ unsigned long delta_mmap; /* randomized offset */
76545+ unsigned long delta_stack; /* randomized offset */
76546+#endif
76547+
76548 };
76549
76550 /* first nid will either be a valid NID or one of these values */
76551diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
76552index c5d5278..f0b68c8 100644
76553--- a/include/linux/mmiotrace.h
76554+++ b/include/linux/mmiotrace.h
76555@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
76556 /* Called from ioremap.c */
76557 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
76558 void __iomem *addr);
76559-extern void mmiotrace_iounmap(volatile void __iomem *addr);
76560+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
76561
76562 /* For anyone to insert markers. Remember trailing newline. */
76563 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
76564@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
76565 {
76566 }
76567
76568-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
76569+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
76570 {
76571 }
76572
76573diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
76574index 5c76737..61f518e 100644
76575--- a/include/linux/mmzone.h
76576+++ b/include/linux/mmzone.h
76577@@ -396,7 +396,7 @@ struct zone {
76578 unsigned long flags; /* zone flags, see below */
76579
76580 /* Zone statistics */
76581- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
76582+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
76583
76584 /*
76585 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
76586diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
76587index b508016..237cfe5 100644
76588--- a/include/linux/mod_devicetable.h
76589+++ b/include/linux/mod_devicetable.h
76590@@ -13,7 +13,7 @@
76591 typedef unsigned long kernel_ulong_t;
76592 #endif
76593
76594-#define PCI_ANY_ID (~0)
76595+#define PCI_ANY_ID ((__u16)~0)
76596
76597 struct pci_device_id {
76598 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
76599@@ -139,7 +139,7 @@ struct usb_device_id {
76600 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
76601 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
76602
76603-#define HID_ANY_ID (~0)
76604+#define HID_ANY_ID (~0U)
76605 #define HID_BUS_ANY 0xffff
76606 #define HID_GROUP_ANY 0x0000
76607
76608@@ -465,7 +465,7 @@ struct dmi_system_id {
76609 const char *ident;
76610 struct dmi_strmatch matches[4];
76611 void *driver_data;
76612-};
76613+} __do_const;
76614 /*
76615 * struct dmi_device_id appears during expansion of
76616 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
76617diff --git a/include/linux/module.h b/include/linux/module.h
76618index 46f1ea0..a34ca37 100644
76619--- a/include/linux/module.h
76620+++ b/include/linux/module.h
76621@@ -17,9 +17,11 @@
76622 #include <linux/moduleparam.h>
76623 #include <linux/tracepoint.h>
76624 #include <linux/export.h>
76625+#include <linux/fs.h>
76626
76627 #include <linux/percpu.h>
76628 #include <asm/module.h>
76629+#include <asm/pgtable.h>
76630
76631 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
76632 #define MODULE_SIG_STRING "~Module signature appended~\n"
76633@@ -54,12 +56,13 @@ struct module_attribute {
76634 int (*test)(struct module *);
76635 void (*free)(struct module *);
76636 };
76637+typedef struct module_attribute __no_const module_attribute_no_const;
76638
76639 struct module_version_attribute {
76640 struct module_attribute mattr;
76641 const char *module_name;
76642 const char *version;
76643-} __attribute__ ((__aligned__(sizeof(void *))));
76644+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
76645
76646 extern ssize_t __modver_version_show(struct module_attribute *,
76647 struct module_kobject *, char *);
76648@@ -232,7 +235,7 @@ struct module
76649
76650 /* Sysfs stuff. */
76651 struct module_kobject mkobj;
76652- struct module_attribute *modinfo_attrs;
76653+ module_attribute_no_const *modinfo_attrs;
76654 const char *version;
76655 const char *srcversion;
76656 struct kobject *holders_dir;
76657@@ -281,19 +284,16 @@ struct module
76658 int (*init)(void);
76659
76660 /* If this is non-NULL, vfree after init() returns */
76661- void *module_init;
76662+ void *module_init_rx, *module_init_rw;
76663
76664 /* Here is the actual code + data, vfree'd on unload. */
76665- void *module_core;
76666+ void *module_core_rx, *module_core_rw;
76667
76668 /* Here are the sizes of the init and core sections */
76669- unsigned int init_size, core_size;
76670+ unsigned int init_size_rw, core_size_rw;
76671
76672 /* The size of the executable code in each section. */
76673- unsigned int init_text_size, core_text_size;
76674-
76675- /* Size of RO sections of the module (text+rodata) */
76676- unsigned int init_ro_size, core_ro_size;
76677+ unsigned int init_size_rx, core_size_rx;
76678
76679 /* Arch-specific module values */
76680 struct mod_arch_specific arch;
76681@@ -349,6 +349,10 @@ struct module
76682 #ifdef CONFIG_EVENT_TRACING
76683 struct ftrace_event_call **trace_events;
76684 unsigned int num_trace_events;
76685+ struct file_operations trace_id;
76686+ struct file_operations trace_enable;
76687+ struct file_operations trace_format;
76688+ struct file_operations trace_filter;
76689 #endif
76690 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
76691 unsigned int num_ftrace_callsites;
76692@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
76693 bool is_module_percpu_address(unsigned long addr);
76694 bool is_module_text_address(unsigned long addr);
76695
76696+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
76697+{
76698+
76699+#ifdef CONFIG_PAX_KERNEXEC
76700+ if (ktla_ktva(addr) >= (unsigned long)start &&
76701+ ktla_ktva(addr) < (unsigned long)start + size)
76702+ return 1;
76703+#endif
76704+
76705+ return ((void *)addr >= start && (void *)addr < start + size);
76706+}
76707+
76708+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
76709+{
76710+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
76711+}
76712+
76713+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
76714+{
76715+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
76716+}
76717+
76718+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
76719+{
76720+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
76721+}
76722+
76723+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
76724+{
76725+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
76726+}
76727+
76728 static inline int within_module_core(unsigned long addr, const struct module *mod)
76729 {
76730- return (unsigned long)mod->module_core <= addr &&
76731- addr < (unsigned long)mod->module_core + mod->core_size;
76732+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
76733 }
76734
76735 static inline int within_module_init(unsigned long addr, const struct module *mod)
76736 {
76737- return (unsigned long)mod->module_init <= addr &&
76738- addr < (unsigned long)mod->module_init + mod->init_size;
76739+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
76740 }
76741
76742 /* Search for module by name: must hold module_mutex. */
76743diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
76744index 560ca53..ef621ef 100644
76745--- a/include/linux/moduleloader.h
76746+++ b/include/linux/moduleloader.h
76747@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
76748 sections. Returns NULL on failure. */
76749 void *module_alloc(unsigned long size);
76750
76751+#ifdef CONFIG_PAX_KERNEXEC
76752+void *module_alloc_exec(unsigned long size);
76753+#else
76754+#define module_alloc_exec(x) module_alloc(x)
76755+#endif
76756+
76757 /* Free memory returned from module_alloc. */
76758 void module_free(struct module *mod, void *module_region);
76759
76760+#ifdef CONFIG_PAX_KERNEXEC
76761+void module_free_exec(struct module *mod, void *module_region);
76762+#else
76763+#define module_free_exec(x, y) module_free((x), (y))
76764+#endif
76765+
76766 /*
76767 * Apply the given relocation to the (simplified) ELF. Return -error
76768 * or 0.
76769@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
76770 unsigned int relsec,
76771 struct module *me)
76772 {
76773+#ifdef CONFIG_MODULES
76774 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
76775+#endif
76776 return -ENOEXEC;
76777 }
76778 #endif
76779@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
76780 unsigned int relsec,
76781 struct module *me)
76782 {
76783+#ifdef CONFIG_MODULES
76784 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
76785+#endif
76786 return -ENOEXEC;
76787 }
76788 #endif
76789diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
76790index 137b419..fe663ec 100644
76791--- a/include/linux/moduleparam.h
76792+++ b/include/linux/moduleparam.h
76793@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
76794 * @len is usually just sizeof(string).
76795 */
76796 #define module_param_string(name, string, len, perm) \
76797- static const struct kparam_string __param_string_##name \
76798+ static const struct kparam_string __param_string_##name __used \
76799 = { len, string }; \
76800 __module_param_call(MODULE_PARAM_PREFIX, name, \
76801 &param_ops_string, \
76802@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
76803 */
76804 #define module_param_array_named(name, array, type, nump, perm) \
76805 param_check_##type(name, &(array)[0]); \
76806- static const struct kparam_array __param_arr_##name \
76807+ static const struct kparam_array __param_arr_##name __used \
76808 = { .max = ARRAY_SIZE(array), .num = nump, \
76809 .ops = &param_ops_##type, \
76810 .elemsize = sizeof(array[0]), .elem = array }; \
76811diff --git a/include/linux/namei.h b/include/linux/namei.h
76812index 5a5ff57..5ae5070 100644
76813--- a/include/linux/namei.h
76814+++ b/include/linux/namei.h
76815@@ -19,7 +19,7 @@ struct nameidata {
76816 unsigned seq;
76817 int last_type;
76818 unsigned depth;
76819- char *saved_names[MAX_NESTED_LINKS + 1];
76820+ const char *saved_names[MAX_NESTED_LINKS + 1];
76821 };
76822
76823 /*
76824@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
76825
76826 extern void nd_jump_link(struct nameidata *nd, struct path *path);
76827
76828-static inline void nd_set_link(struct nameidata *nd, char *path)
76829+static inline void nd_set_link(struct nameidata *nd, const char *path)
76830 {
76831 nd->saved_names[nd->depth] = path;
76832 }
76833
76834-static inline char *nd_get_link(struct nameidata *nd)
76835+static inline const char *nd_get_link(const struct nameidata *nd)
76836 {
76837 return nd->saved_names[nd->depth];
76838 }
76839diff --git a/include/linux/net.h b/include/linux/net.h
76840index 99c9f0c..e1cf296 100644
76841--- a/include/linux/net.h
76842+++ b/include/linux/net.h
76843@@ -183,7 +183,7 @@ struct net_proto_family {
76844 int (*create)(struct net *net, struct socket *sock,
76845 int protocol, int kern);
76846 struct module *owner;
76847-};
76848+} __do_const;
76849
76850 struct iovec;
76851 struct kvec;
76852diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
76853index 96e4c21..9cc8278 100644
76854--- a/include/linux/netdevice.h
76855+++ b/include/linux/netdevice.h
76856@@ -1026,6 +1026,7 @@ struct net_device_ops {
76857 int (*ndo_change_carrier)(struct net_device *dev,
76858 bool new_carrier);
76859 };
76860+typedef struct net_device_ops __no_const net_device_ops_no_const;
76861
76862 /*
76863 * The DEVICE structure.
76864@@ -1094,7 +1095,7 @@ struct net_device {
76865 int iflink;
76866
76867 struct net_device_stats stats;
76868- atomic_long_t rx_dropped; /* dropped packets by core network
76869+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
76870 * Do not use this in drivers.
76871 */
76872
76873diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
76874index 0060fde..481c6ae 100644
76875--- a/include/linux/netfilter.h
76876+++ b/include/linux/netfilter.h
76877@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
76878 #endif
76879 /* Use the module struct to lock set/get code in place */
76880 struct module *owner;
76881-};
76882+} __do_const;
76883
76884 /* Function to register/unregister hook points. */
76885 int nf_register_hook(struct nf_hook_ops *reg);
76886diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
76887index d80e275..c3510b8 100644
76888--- a/include/linux/netfilter/ipset/ip_set.h
76889+++ b/include/linux/netfilter/ipset/ip_set.h
76890@@ -124,7 +124,7 @@ struct ip_set_type_variant {
76891 /* Return true if "b" set is the same as "a"
76892 * according to the create set parameters */
76893 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
76894-};
76895+} __do_const;
76896
76897 /* The core set type structure */
76898 struct ip_set_type {
76899diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
76900index cadb740..d7c37c0 100644
76901--- a/include/linux/netfilter/nfnetlink.h
76902+++ b/include/linux/netfilter/nfnetlink.h
76903@@ -16,7 +16,7 @@ struct nfnl_callback {
76904 const struct nlattr * const cda[]);
76905 const struct nla_policy *policy; /* netlink attribute policy */
76906 const u_int16_t attr_count; /* number of nlattr's */
76907-};
76908+} __do_const;
76909
76910 struct nfnetlink_subsystem {
76911 const char *name;
76912diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
76913new file mode 100644
76914index 0000000..33f4af8
76915--- /dev/null
76916+++ b/include/linux/netfilter/xt_gradm.h
76917@@ -0,0 +1,9 @@
76918+#ifndef _LINUX_NETFILTER_XT_GRADM_H
76919+#define _LINUX_NETFILTER_XT_GRADM_H 1
76920+
76921+struct xt_gradm_mtinfo {
76922+ __u16 flags;
76923+ __u16 invflags;
76924+};
76925+
76926+#endif
76927diff --git a/include/linux/nls.h b/include/linux/nls.h
76928index 5dc635f..35f5e11 100644
76929--- a/include/linux/nls.h
76930+++ b/include/linux/nls.h
76931@@ -31,7 +31,7 @@ struct nls_table {
76932 const unsigned char *charset2upper;
76933 struct module *owner;
76934 struct nls_table *next;
76935-};
76936+} __do_const;
76937
76938 /* this value hold the maximum octet of charset */
76939 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
76940diff --git a/include/linux/notifier.h b/include/linux/notifier.h
76941index d14a4c3..a078786 100644
76942--- a/include/linux/notifier.h
76943+++ b/include/linux/notifier.h
76944@@ -54,7 +54,8 @@ struct notifier_block {
76945 notifier_fn_t notifier_call;
76946 struct notifier_block __rcu *next;
76947 int priority;
76948-};
76949+} __do_const;
76950+typedef struct notifier_block __no_const notifier_block_no_const;
76951
76952 struct atomic_notifier_head {
76953 spinlock_t lock;
76954diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
76955index a4c5624..79d6d88 100644
76956--- a/include/linux/oprofile.h
76957+++ b/include/linux/oprofile.h
76958@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
76959 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
76960 char const * name, ulong * val);
76961
76962-/** Create a file for read-only access to an atomic_t. */
76963+/** Create a file for read-only access to an atomic_unchecked_t. */
76964 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
76965- char const * name, atomic_t * val);
76966+ char const * name, atomic_unchecked_t * val);
76967
76968 /** create a directory */
76969 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
76970diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
76971index 8db71dc..a76bf2c 100644
76972--- a/include/linux/pci_hotplug.h
76973+++ b/include/linux/pci_hotplug.h
76974@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
76975 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
76976 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
76977 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
76978-};
76979+} __do_const;
76980+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
76981
76982 /**
76983 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
76984diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
76985index c5b6dbf..b124155 100644
76986--- a/include/linux/perf_event.h
76987+++ b/include/linux/perf_event.h
76988@@ -318,8 +318,8 @@ struct perf_event {
76989
76990 enum perf_event_active_state state;
76991 unsigned int attach_state;
76992- local64_t count;
76993- atomic64_t child_count;
76994+ local64_t count; /* PaX: fix it one day */
76995+ atomic64_unchecked_t child_count;
76996
76997 /*
76998 * These are the total time in nanoseconds that the event
76999@@ -370,8 +370,8 @@ struct perf_event {
77000 * These accumulate total time (in nanoseconds) that children
77001 * events have been enabled and running, respectively.
77002 */
77003- atomic64_t child_total_time_enabled;
77004- atomic64_t child_total_time_running;
77005+ atomic64_unchecked_t child_total_time_enabled;
77006+ atomic64_unchecked_t child_total_time_running;
77007
77008 /*
77009 * Protect attach/detach and child_list:
77010@@ -692,7 +692,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
77011 entry->ip[entry->nr++] = ip;
77012 }
77013
77014-extern int sysctl_perf_event_paranoid;
77015+extern int sysctl_perf_event_legitimately_concerned;
77016 extern int sysctl_perf_event_mlock;
77017 extern int sysctl_perf_event_sample_rate;
77018
77019@@ -700,19 +700,24 @@ extern int perf_proc_update_handler(struct ctl_table *table, int write,
77020 void __user *buffer, size_t *lenp,
77021 loff_t *ppos);
77022
77023+static inline bool perf_paranoid_any(void)
77024+{
77025+ return sysctl_perf_event_legitimately_concerned > 2;
77026+}
77027+
77028 static inline bool perf_paranoid_tracepoint_raw(void)
77029 {
77030- return sysctl_perf_event_paranoid > -1;
77031+ return sysctl_perf_event_legitimately_concerned > -1;
77032 }
77033
77034 static inline bool perf_paranoid_cpu(void)
77035 {
77036- return sysctl_perf_event_paranoid > 0;
77037+ return sysctl_perf_event_legitimately_concerned > 0;
77038 }
77039
77040 static inline bool perf_paranoid_kernel(void)
77041 {
77042- return sysctl_perf_event_paranoid > 1;
77043+ return sysctl_perf_event_legitimately_concerned > 1;
77044 }
77045
77046 extern void perf_event_init(void);
77047@@ -806,7 +811,7 @@ static inline void perf_restore_debug_store(void) { }
77048 */
77049 #define perf_cpu_notifier(fn) \
77050 do { \
77051- static struct notifier_block fn##_nb __cpuinitdata = \
77052+ static struct notifier_block fn##_nb = \
77053 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
77054 unsigned long cpu = smp_processor_id(); \
77055 unsigned long flags; \
77056@@ -826,7 +831,7 @@ struct perf_pmu_events_attr {
77057 struct device_attribute attr;
77058 u64 id;
77059 const char *event_str;
77060-};
77061+} __do_const;
77062
77063 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
77064 static struct perf_pmu_events_attr _var = { \
77065diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
77066index b8809fe..ae4ccd0 100644
77067--- a/include/linux/pipe_fs_i.h
77068+++ b/include/linux/pipe_fs_i.h
77069@@ -47,10 +47,10 @@ struct pipe_inode_info {
77070 struct mutex mutex;
77071 wait_queue_head_t wait;
77072 unsigned int nrbufs, curbuf, buffers;
77073- unsigned int readers;
77074- unsigned int writers;
77075- unsigned int files;
77076- unsigned int waiting_writers;
77077+ atomic_t readers;
77078+ atomic_t writers;
77079+ atomic_t files;
77080+ atomic_t waiting_writers;
77081 unsigned int r_counter;
77082 unsigned int w_counter;
77083 struct page *tmp_page;
77084diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
77085index 5f28cae..3d23723 100644
77086--- a/include/linux/platform_data/usb-ehci-s5p.h
77087+++ b/include/linux/platform_data/usb-ehci-s5p.h
77088@@ -14,7 +14,7 @@
77089 struct s5p_ehci_platdata {
77090 int (*phy_init)(struct platform_device *pdev, int type);
77091 int (*phy_exit)(struct platform_device *pdev, int type);
77092-};
77093+} __no_const;
77094
77095 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
77096
77097diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
77098index c256c59..8ea94c7 100644
77099--- a/include/linux/platform_data/usb-ohci-exynos.h
77100+++ b/include/linux/platform_data/usb-ohci-exynos.h
77101@@ -14,7 +14,7 @@
77102 struct exynos4_ohci_platdata {
77103 int (*phy_init)(struct platform_device *pdev, int type);
77104 int (*phy_exit)(struct platform_device *pdev, int type);
77105-};
77106+} __no_const;
77107
77108 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
77109
77110diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
77111index 7c1d252..c5c773e 100644
77112--- a/include/linux/pm_domain.h
77113+++ b/include/linux/pm_domain.h
77114@@ -48,7 +48,7 @@ struct gpd_dev_ops {
77115
77116 struct gpd_cpu_data {
77117 unsigned int saved_exit_latency;
77118- struct cpuidle_state *idle_state;
77119+ cpuidle_state_no_const *idle_state;
77120 };
77121
77122 struct generic_pm_domain {
77123diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
77124index 7d7e09e..8671ef8 100644
77125--- a/include/linux/pm_runtime.h
77126+++ b/include/linux/pm_runtime.h
77127@@ -104,7 +104,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
77128
77129 static inline void pm_runtime_mark_last_busy(struct device *dev)
77130 {
77131- ACCESS_ONCE(dev->power.last_busy) = jiffies;
77132+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
77133 }
77134
77135 #else /* !CONFIG_PM_RUNTIME */
77136diff --git a/include/linux/pnp.h b/include/linux/pnp.h
77137index 195aafc..49a7bc2 100644
77138--- a/include/linux/pnp.h
77139+++ b/include/linux/pnp.h
77140@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
77141 struct pnp_fixup {
77142 char id[7];
77143 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
77144-};
77145+} __do_const;
77146
77147 /* config parameters */
77148 #define PNP_CONFIG_NORMAL 0x0001
77149diff --git a/include/linux/poison.h b/include/linux/poison.h
77150index 2110a81..13a11bb 100644
77151--- a/include/linux/poison.h
77152+++ b/include/linux/poison.h
77153@@ -19,8 +19,8 @@
77154 * under normal circumstances, used to verify that nobody uses
77155 * non-initialized list entries.
77156 */
77157-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
77158-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
77159+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
77160+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
77161
77162 /********** include/linux/timer.h **********/
77163 /*
77164diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
77165index c0f44c2..1572583 100644
77166--- a/include/linux/power/smartreflex.h
77167+++ b/include/linux/power/smartreflex.h
77168@@ -238,7 +238,7 @@ struct omap_sr_class_data {
77169 int (*notify)(struct omap_sr *sr, u32 status);
77170 u8 notify_flags;
77171 u8 class_type;
77172-};
77173+} __do_const;
77174
77175 /**
77176 * struct omap_sr_nvalue_table - Smartreflex n-target value info
77177diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
77178index 4ea1d37..80f4b33 100644
77179--- a/include/linux/ppp-comp.h
77180+++ b/include/linux/ppp-comp.h
77181@@ -84,7 +84,7 @@ struct compressor {
77182 struct module *owner;
77183 /* Extra skb space needed by the compressor algorithm */
77184 unsigned int comp_extra;
77185-};
77186+} __do_const;
77187
77188 /*
77189 * The return value from decompress routine is the length of the
77190diff --git a/include/linux/preempt.h b/include/linux/preempt.h
77191index f5d4723..a6ea2fa 100644
77192--- a/include/linux/preempt.h
77193+++ b/include/linux/preempt.h
77194@@ -18,8 +18,13 @@
77195 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
77196 #endif
77197
77198+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
77199+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
77200+
77201 #define inc_preempt_count() add_preempt_count(1)
77202+#define raw_inc_preempt_count() raw_add_preempt_count(1)
77203 #define dec_preempt_count() sub_preempt_count(1)
77204+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
77205
77206 #define preempt_count() (current_thread_info()->preempt_count)
77207
77208@@ -64,6 +69,12 @@ do { \
77209 barrier(); \
77210 } while (0)
77211
77212+#define raw_preempt_disable() \
77213+do { \
77214+ raw_inc_preempt_count(); \
77215+ barrier(); \
77216+} while (0)
77217+
77218 #define sched_preempt_enable_no_resched() \
77219 do { \
77220 barrier(); \
77221@@ -72,6 +83,12 @@ do { \
77222
77223 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
77224
77225+#define raw_preempt_enable_no_resched() \
77226+do { \
77227+ barrier(); \
77228+ raw_dec_preempt_count(); \
77229+} while (0)
77230+
77231 #define preempt_enable() \
77232 do { \
77233 preempt_enable_no_resched(); \
77234@@ -116,8 +133,10 @@ do { \
77235 * region.
77236 */
77237 #define preempt_disable() barrier()
77238+#define raw_preempt_disable() barrier()
77239 #define sched_preempt_enable_no_resched() barrier()
77240 #define preempt_enable_no_resched() barrier()
77241+#define raw_preempt_enable_no_resched() barrier()
77242 #define preempt_enable() barrier()
77243
77244 #define preempt_disable_notrace() barrier()
77245diff --git a/include/linux/printk.h b/include/linux/printk.h
77246index 22c7052..ad3fa0a 100644
77247--- a/include/linux/printk.h
77248+++ b/include/linux/printk.h
77249@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
77250 void early_printk(const char *s, ...) { }
77251 #endif
77252
77253+extern int kptr_restrict;
77254+
77255 #ifdef CONFIG_PRINTK
77256 asmlinkage __printf(5, 0)
77257 int vprintk_emit(int facility, int level,
77258@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
77259
77260 extern int printk_delay_msec;
77261 extern int dmesg_restrict;
77262-extern int kptr_restrict;
77263
77264 extern void wake_up_klogd(void);
77265
77266diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
77267index 608e60a..c26f864 100644
77268--- a/include/linux/proc_fs.h
77269+++ b/include/linux/proc_fs.h
77270@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
77271 return proc_create_data(name, mode, parent, proc_fops, NULL);
77272 }
77273
77274+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
77275+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
77276+{
77277+#ifdef CONFIG_GRKERNSEC_PROC_USER
77278+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
77279+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77280+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
77281+#else
77282+ return proc_create_data(name, mode, parent, proc_fops, NULL);
77283+#endif
77284+}
77285+
77286+
77287 extern void proc_set_size(struct proc_dir_entry *, loff_t);
77288 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
77289 extern void *PDE_DATA(const struct inode *);
77290diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
77291index 34a1e10..03a6d03 100644
77292--- a/include/linux/proc_ns.h
77293+++ b/include/linux/proc_ns.h
77294@@ -14,7 +14,7 @@ struct proc_ns_operations {
77295 void (*put)(void *ns);
77296 int (*install)(struct nsproxy *nsproxy, void *ns);
77297 unsigned int (*inum)(void *ns);
77298-};
77299+} __do_const;
77300
77301 struct proc_ns {
77302 void *ns;
77303diff --git a/include/linux/random.h b/include/linux/random.h
77304index 3b9377d..61b506a 100644
77305--- a/include/linux/random.h
77306+++ b/include/linux/random.h
77307@@ -32,6 +32,11 @@ void prandom_seed(u32 seed);
77308 u32 prandom_u32_state(struct rnd_state *);
77309 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
77310
77311+static inline unsigned long pax_get_random_long(void)
77312+{
77313+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
77314+}
77315+
77316 /*
77317 * Handle minimum values for seeds
77318 */
77319diff --git a/include/linux/rculist.h b/include/linux/rculist.h
77320index f4b1001..8ddb2b6 100644
77321--- a/include/linux/rculist.h
77322+++ b/include/linux/rculist.h
77323@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
77324 struct list_head *prev, struct list_head *next);
77325 #endif
77326
77327+extern void __pax_list_add_rcu(struct list_head *new,
77328+ struct list_head *prev, struct list_head *next);
77329+
77330 /**
77331 * list_add_rcu - add a new entry to rcu-protected list
77332 * @new: new entry to be added
77333@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
77334 __list_add_rcu(new, head, head->next);
77335 }
77336
77337+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
77338+{
77339+ __pax_list_add_rcu(new, head, head->next);
77340+}
77341+
77342 /**
77343 * list_add_tail_rcu - add a new entry to rcu-protected list
77344 * @new: new entry to be added
77345@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
77346 __list_add_rcu(new, head->prev, head);
77347 }
77348
77349+static inline void pax_list_add_tail_rcu(struct list_head *new,
77350+ struct list_head *head)
77351+{
77352+ __pax_list_add_rcu(new, head->prev, head);
77353+}
77354+
77355 /**
77356 * list_del_rcu - deletes entry from list without re-initialization
77357 * @entry: the element to delete from the list.
77358@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
77359 entry->prev = LIST_POISON2;
77360 }
77361
77362+extern void pax_list_del_rcu(struct list_head *entry);
77363+
77364 /**
77365 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
77366 * @n: the element to delete from the hash list.
77367diff --git a/include/linux/reboot.h b/include/linux/reboot.h
77368index 23b3630..e1bc12b 100644
77369--- a/include/linux/reboot.h
77370+++ b/include/linux/reboot.h
77371@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
77372 * Architecture-specific implementations of sys_reboot commands.
77373 */
77374
77375-extern void machine_restart(char *cmd);
77376-extern void machine_halt(void);
77377-extern void machine_power_off(void);
77378+extern void machine_restart(char *cmd) __noreturn;
77379+extern void machine_halt(void) __noreturn;
77380+extern void machine_power_off(void) __noreturn;
77381
77382 extern void machine_shutdown(void);
77383 struct pt_regs;
77384@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
77385 */
77386
77387 extern void kernel_restart_prepare(char *cmd);
77388-extern void kernel_restart(char *cmd);
77389-extern void kernel_halt(void);
77390-extern void kernel_power_off(void);
77391+extern void kernel_restart(char *cmd) __noreturn;
77392+extern void kernel_halt(void) __noreturn;
77393+extern void kernel_power_off(void) __noreturn;
77394
77395 extern int C_A_D; /* for sysctl */
77396 void ctrl_alt_del(void);
77397@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
77398 * Emergency restart, callable from an interrupt handler.
77399 */
77400
77401-extern void emergency_restart(void);
77402+extern void emergency_restart(void) __noreturn;
77403 #include <asm/emergency-restart.h>
77404
77405 #endif /* _LINUX_REBOOT_H */
77406diff --git a/include/linux/regset.h b/include/linux/regset.h
77407index 8e0c9fe..ac4d221 100644
77408--- a/include/linux/regset.h
77409+++ b/include/linux/regset.h
77410@@ -161,7 +161,8 @@ struct user_regset {
77411 unsigned int align;
77412 unsigned int bias;
77413 unsigned int core_note_type;
77414-};
77415+} __do_const;
77416+typedef struct user_regset __no_const user_regset_no_const;
77417
77418 /**
77419 * struct user_regset_view - available regsets
77420diff --git a/include/linux/relay.h b/include/linux/relay.h
77421index d7c8359..818daf5 100644
77422--- a/include/linux/relay.h
77423+++ b/include/linux/relay.h
77424@@ -157,7 +157,7 @@ struct rchan_callbacks
77425 * The callback should return 0 if successful, negative if not.
77426 */
77427 int (*remove_buf_file)(struct dentry *dentry);
77428-};
77429+} __no_const;
77430
77431 /*
77432 * CONFIG_RELAY kernel API, kernel/relay.c
77433diff --git a/include/linux/rio.h b/include/linux/rio.h
77434index 18e0993..8ab5b21 100644
77435--- a/include/linux/rio.h
77436+++ b/include/linux/rio.h
77437@@ -345,7 +345,7 @@ struct rio_ops {
77438 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
77439 u64 rstart, u32 size, u32 flags);
77440 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
77441-};
77442+} __no_const;
77443
77444 #define RIO_RESOURCE_MEM 0x00000100
77445 #define RIO_RESOURCE_DOORBELL 0x00000200
77446diff --git a/include/linux/rmap.h b/include/linux/rmap.h
77447index 6dacb93..6174423 100644
77448--- a/include/linux/rmap.h
77449+++ b/include/linux/rmap.h
77450@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
77451 void anon_vma_init(void); /* create anon_vma_cachep */
77452 int anon_vma_prepare(struct vm_area_struct *);
77453 void unlink_anon_vmas(struct vm_area_struct *);
77454-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
77455-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
77456+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
77457+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
77458
77459 static inline void anon_vma_merge(struct vm_area_struct *vma,
77460 struct vm_area_struct *next)
77461diff --git a/include/linux/sched.h b/include/linux/sched.h
77462index 178a8d9..918ea01 100644
77463--- a/include/linux/sched.h
77464+++ b/include/linux/sched.h
77465@@ -62,6 +62,7 @@ struct bio_list;
77466 struct fs_struct;
77467 struct perf_event_context;
77468 struct blk_plug;
77469+struct linux_binprm;
77470
77471 /*
77472 * List of flags we want to share for kernel threads,
77473@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
77474 extern int in_sched_functions(unsigned long addr);
77475
77476 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
77477-extern signed long schedule_timeout(signed long timeout);
77478+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
77479 extern signed long schedule_timeout_interruptible(signed long timeout);
77480 extern signed long schedule_timeout_killable(signed long timeout);
77481 extern signed long schedule_timeout_uninterruptible(signed long timeout);
77482@@ -314,6 +315,18 @@ struct nsproxy;
77483 struct user_namespace;
77484
77485 #ifdef CONFIG_MMU
77486+
77487+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
77488+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
77489+#else
77490+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
77491+{
77492+ return 0;
77493+}
77494+#endif
77495+
77496+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
77497+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
77498 extern void arch_pick_mmap_layout(struct mm_struct *mm);
77499 extern unsigned long
77500 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
77501@@ -591,6 +604,17 @@ struct signal_struct {
77502 #ifdef CONFIG_TASKSTATS
77503 struct taskstats *stats;
77504 #endif
77505+
77506+#ifdef CONFIG_GRKERNSEC
77507+ u32 curr_ip;
77508+ u32 saved_ip;
77509+ u32 gr_saddr;
77510+ u32 gr_daddr;
77511+ u16 gr_sport;
77512+ u16 gr_dport;
77513+ u8 used_accept:1;
77514+#endif
77515+
77516 #ifdef CONFIG_AUDIT
77517 unsigned audit_tty;
77518 unsigned audit_tty_log_passwd;
77519@@ -671,6 +695,14 @@ struct user_struct {
77520 struct key *session_keyring; /* UID's default session keyring */
77521 #endif
77522
77523+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
77524+ unsigned char kernel_banned;
77525+#endif
77526+#ifdef CONFIG_GRKERNSEC_BRUTE
77527+ unsigned char suid_banned;
77528+ unsigned long suid_ban_expires;
77529+#endif
77530+
77531 /* Hash table maintenance information */
77532 struct hlist_node uidhash_node;
77533 kuid_t uid;
77534@@ -1158,8 +1190,8 @@ struct task_struct {
77535 struct list_head thread_group;
77536
77537 struct completion *vfork_done; /* for vfork() */
77538- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
77539- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
77540+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
77541+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
77542
77543 cputime_t utime, stime, utimescaled, stimescaled;
77544 cputime_t gtime;
77545@@ -1184,11 +1216,6 @@ struct task_struct {
77546 struct task_cputime cputime_expires;
77547 struct list_head cpu_timers[3];
77548
77549-/* process credentials */
77550- const struct cred __rcu *real_cred; /* objective and real subjective task
77551- * credentials (COW) */
77552- const struct cred __rcu *cred; /* effective (overridable) subjective task
77553- * credentials (COW) */
77554 char comm[TASK_COMM_LEN]; /* executable name excluding path
77555 - access with [gs]et_task_comm (which lock
77556 it with task_lock())
77557@@ -1205,6 +1232,10 @@ struct task_struct {
77558 #endif
77559 /* CPU-specific state of this task */
77560 struct thread_struct thread;
77561+/* thread_info moved to task_struct */
77562+#ifdef CONFIG_X86
77563+ struct thread_info tinfo;
77564+#endif
77565 /* filesystem information */
77566 struct fs_struct *fs;
77567 /* open file information */
77568@@ -1278,6 +1309,10 @@ struct task_struct {
77569 gfp_t lockdep_reclaim_gfp;
77570 #endif
77571
77572+/* process credentials */
77573+ const struct cred __rcu *real_cred; /* objective and real subjective task
77574+ * credentials (COW) */
77575+
77576 /* journalling filesystem info */
77577 void *journal_info;
77578
77579@@ -1316,6 +1351,10 @@ struct task_struct {
77580 /* cg_list protected by css_set_lock and tsk->alloc_lock */
77581 struct list_head cg_list;
77582 #endif
77583+
77584+ const struct cred __rcu *cred; /* effective (overridable) subjective task
77585+ * credentials (COW) */
77586+
77587 #ifdef CONFIG_FUTEX
77588 struct robust_list_head __user *robust_list;
77589 #ifdef CONFIG_COMPAT
77590@@ -1416,8 +1455,76 @@ struct task_struct {
77591 unsigned int sequential_io;
77592 unsigned int sequential_io_avg;
77593 #endif
77594+
77595+#ifdef CONFIG_GRKERNSEC
77596+ /* grsecurity */
77597+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
77598+ u64 exec_id;
77599+#endif
77600+#ifdef CONFIG_GRKERNSEC_SETXID
77601+ const struct cred *delayed_cred;
77602+#endif
77603+ struct dentry *gr_chroot_dentry;
77604+ struct acl_subject_label *acl;
77605+ struct acl_role_label *role;
77606+ struct file *exec_file;
77607+ unsigned long brute_expires;
77608+ u16 acl_role_id;
77609+ /* is this the task that authenticated to the special role */
77610+ u8 acl_sp_role;
77611+ u8 is_writable;
77612+ u8 brute;
77613+ u8 gr_is_chrooted;
77614+#endif
77615+
77616 };
77617
77618+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
77619+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
77620+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
77621+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
77622+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
77623+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
77624+
77625+#ifdef CONFIG_PAX_SOFTMODE
77626+extern int pax_softmode;
77627+#endif
77628+
77629+extern int pax_check_flags(unsigned long *);
77630+
77631+/* if tsk != current then task_lock must be held on it */
77632+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
77633+static inline unsigned long pax_get_flags(struct task_struct *tsk)
77634+{
77635+ if (likely(tsk->mm))
77636+ return tsk->mm->pax_flags;
77637+ else
77638+ return 0UL;
77639+}
77640+
77641+/* if tsk != current then task_lock must be held on it */
77642+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
77643+{
77644+ if (likely(tsk->mm)) {
77645+ tsk->mm->pax_flags = flags;
77646+ return 0;
77647+ }
77648+ return -EINVAL;
77649+}
77650+#endif
77651+
77652+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
77653+extern void pax_set_initial_flags(struct linux_binprm *bprm);
77654+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
77655+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
77656+#endif
77657+
77658+struct path;
77659+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
77660+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
77661+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
77662+extern void pax_report_refcount_overflow(struct pt_regs *regs);
77663+
77664 /* Future-safe accessor for struct task_struct's cpus_allowed. */
77665 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
77666
77667@@ -1476,7 +1583,7 @@ struct pid_namespace;
77668 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
77669 struct pid_namespace *ns);
77670
77671-static inline pid_t task_pid_nr(struct task_struct *tsk)
77672+static inline pid_t task_pid_nr(const struct task_struct *tsk)
77673 {
77674 return tsk->pid;
77675 }
77676@@ -1919,7 +2026,9 @@ void yield(void);
77677 extern struct exec_domain default_exec_domain;
77678
77679 union thread_union {
77680+#ifndef CONFIG_X86
77681 struct thread_info thread_info;
77682+#endif
77683 unsigned long stack[THREAD_SIZE/sizeof(long)];
77684 };
77685
77686@@ -1952,6 +2061,7 @@ extern struct pid_namespace init_pid_ns;
77687 */
77688
77689 extern struct task_struct *find_task_by_vpid(pid_t nr);
77690+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
77691 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
77692 struct pid_namespace *ns);
77693
77694@@ -2118,7 +2228,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
77695 extern void exit_itimers(struct signal_struct *);
77696 extern void flush_itimer_signals(void);
77697
77698-extern void do_group_exit(int);
77699+extern __noreturn void do_group_exit(int);
77700
77701 extern int allow_signal(int);
77702 extern int disallow_signal(int);
77703@@ -2309,9 +2419,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
77704
77705 #endif
77706
77707-static inline int object_is_on_stack(void *obj)
77708+static inline int object_starts_on_stack(void *obj)
77709 {
77710- void *stack = task_stack_page(current);
77711+ const void *stack = task_stack_page(current);
77712
77713 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
77714 }
77715diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
77716index bf8086b..962b035 100644
77717--- a/include/linux/sched/sysctl.h
77718+++ b/include/linux/sched/sysctl.h
77719@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
77720 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
77721
77722 extern int sysctl_max_map_count;
77723+extern unsigned long sysctl_heap_stack_gap;
77724
77725 extern unsigned int sysctl_sched_latency;
77726 extern unsigned int sysctl_sched_min_granularity;
77727diff --git a/include/linux/security.h b/include/linux/security.h
77728index 4686491..2bd210e 100644
77729--- a/include/linux/security.h
77730+++ b/include/linux/security.h
77731@@ -26,6 +26,7 @@
77732 #include <linux/capability.h>
77733 #include <linux/slab.h>
77734 #include <linux/err.h>
77735+#include <linux/grsecurity.h>
77736
77737 struct linux_binprm;
77738 struct cred;
77739diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
77740index 2da29ac..aac448ec 100644
77741--- a/include/linux/seq_file.h
77742+++ b/include/linux/seq_file.h
77743@@ -26,6 +26,9 @@ struct seq_file {
77744 struct mutex lock;
77745 const struct seq_operations *op;
77746 int poll_event;
77747+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
77748+ u64 exec_id;
77749+#endif
77750 #ifdef CONFIG_USER_NS
77751 struct user_namespace *user_ns;
77752 #endif
77753@@ -38,6 +41,7 @@ struct seq_operations {
77754 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
77755 int (*show) (struct seq_file *m, void *v);
77756 };
77757+typedef struct seq_operations __no_const seq_operations_no_const;
77758
77759 #define SEQ_SKIP 1
77760
77761diff --git a/include/linux/shm.h b/include/linux/shm.h
77762index 429c199..4d42e38 100644
77763--- a/include/linux/shm.h
77764+++ b/include/linux/shm.h
77765@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
77766
77767 /* The task created the shm object. NULL if the task is dead. */
77768 struct task_struct *shm_creator;
77769+#ifdef CONFIG_GRKERNSEC
77770+ time_t shm_createtime;
77771+ pid_t shm_lapid;
77772+#endif
77773 };
77774
77775 /* shm_mode upper byte flags */
77776diff --git a/include/linux/signal.h b/include/linux/signal.h
77777index d897484..323ba98 100644
77778--- a/include/linux/signal.h
77779+++ b/include/linux/signal.h
77780@@ -433,6 +433,7 @@ void signals_init(void);
77781
77782 int restore_altstack(const stack_t __user *);
77783 int __save_altstack(stack_t __user *, unsigned long);
77784+void __save_altstack_ex(stack_t __user *, unsigned long);
77785
77786 #ifdef CONFIG_PROC_FS
77787 struct seq_file;
77788diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
77789index dec1748..112c1f9 100644
77790--- a/include/linux/skbuff.h
77791+++ b/include/linux/skbuff.h
77792@@ -640,7 +640,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
77793 extern struct sk_buff *__alloc_skb(unsigned int size,
77794 gfp_t priority, int flags, int node);
77795 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
77796-static inline struct sk_buff *alloc_skb(unsigned int size,
77797+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
77798 gfp_t priority)
77799 {
77800 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
77801@@ -756,7 +756,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
77802 */
77803 static inline int skb_queue_empty(const struct sk_buff_head *list)
77804 {
77805- return list->next == (struct sk_buff *)list;
77806+ return list->next == (const struct sk_buff *)list;
77807 }
77808
77809 /**
77810@@ -769,7 +769,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
77811 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
77812 const struct sk_buff *skb)
77813 {
77814- return skb->next == (struct sk_buff *)list;
77815+ return skb->next == (const struct sk_buff *)list;
77816 }
77817
77818 /**
77819@@ -782,7 +782,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
77820 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
77821 const struct sk_buff *skb)
77822 {
77823- return skb->prev == (struct sk_buff *)list;
77824+ return skb->prev == (const struct sk_buff *)list;
77825 }
77826
77827 /**
77828@@ -1848,7 +1848,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
77829 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
77830 */
77831 #ifndef NET_SKB_PAD
77832-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
77833+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
77834 #endif
77835
77836 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
77837@@ -2443,7 +2443,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
77838 int noblock, int *err);
77839 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
77840 struct poll_table_struct *wait);
77841-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
77842+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
77843 int offset, struct iovec *to,
77844 int size);
77845 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
77846@@ -2733,6 +2733,9 @@ static inline void nf_reset(struct sk_buff *skb)
77847 nf_bridge_put(skb->nf_bridge);
77848 skb->nf_bridge = NULL;
77849 #endif
77850+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
77851+ skb->nf_trace = 0;
77852+#endif
77853 }
77854
77855 static inline void nf_reset_trace(struct sk_buff *skb)
77856diff --git a/include/linux/slab.h b/include/linux/slab.h
77857index 0c62175..f016ac1 100644
77858--- a/include/linux/slab.h
77859+++ b/include/linux/slab.h
77860@@ -12,15 +12,29 @@
77861 #include <linux/gfp.h>
77862 #include <linux/types.h>
77863 #include <linux/workqueue.h>
77864-
77865+#include <linux/err.h>
77866
77867 /*
77868 * Flags to pass to kmem_cache_create().
77869 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
77870 */
77871 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
77872+
77873+#ifdef CONFIG_PAX_USERCOPY_SLABS
77874+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
77875+#else
77876+#define SLAB_USERCOPY 0x00000000UL
77877+#endif
77878+
77879 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
77880 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
77881+
77882+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77883+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
77884+#else
77885+#define SLAB_NO_SANITIZE 0x00000000UL
77886+#endif
77887+
77888 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
77889 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
77890 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
77891@@ -89,10 +103,13 @@
77892 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
77893 * Both make kfree a no-op.
77894 */
77895-#define ZERO_SIZE_PTR ((void *)16)
77896+#define ZERO_SIZE_PTR \
77897+({ \
77898+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
77899+ (void *)(-MAX_ERRNO-1L); \
77900+})
77901
77902-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
77903- (unsigned long)ZERO_SIZE_PTR)
77904+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
77905
77906
77907 struct mem_cgroup;
77908@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
77909 void kfree(const void *);
77910 void kzfree(const void *);
77911 size_t ksize(const void *);
77912+const char *check_heap_object(const void *ptr, unsigned long n);
77913+bool is_usercopy_object(const void *ptr);
77914
77915 /*
77916 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
77917@@ -164,7 +183,7 @@ struct kmem_cache {
77918 unsigned int align; /* Alignment as calculated */
77919 unsigned long flags; /* Active flags on the slab */
77920 const char *name; /* Slab name for sysfs */
77921- int refcount; /* Use counter */
77922+ atomic_t refcount; /* Use counter */
77923 void (*ctor)(void *); /* Called on object slot creation */
77924 struct list_head list; /* List of all slab caches on the system */
77925 };
77926@@ -226,6 +245,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
77927 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
77928 #endif
77929
77930+#ifdef CONFIG_PAX_USERCOPY_SLABS
77931+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
77932+#endif
77933+
77934 /*
77935 * Figure out which kmalloc slab an allocation of a certain size
77936 * belongs to.
77937@@ -234,7 +257,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
77938 * 2 = 120 .. 192 bytes
77939 * n = 2^(n-1) .. 2^n -1
77940 */
77941-static __always_inline int kmalloc_index(size_t size)
77942+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
77943 {
77944 if (!size)
77945 return 0;
77946@@ -406,6 +429,7 @@ void print_slabinfo_header(struct seq_file *m);
77947 * for general use, and so are not documented here. For a full list of
77948 * potential flags, always refer to linux/gfp.h.
77949 */
77950+
77951 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
77952 {
77953 if (size != 0 && n > SIZE_MAX / size)
77954@@ -465,7 +489,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
77955 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
77956 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
77957 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
77958-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
77959+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
77960 #define kmalloc_track_caller(size, flags) \
77961 __kmalloc_track_caller(size, flags, _RET_IP_)
77962 #else
77963@@ -485,7 +509,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
77964 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
77965 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
77966 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
77967-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
77968+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
77969 #define kmalloc_node_track_caller(size, flags, node) \
77970 __kmalloc_node_track_caller(size, flags, node, \
77971 _RET_IP_)
77972diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
77973index cd40158..4e2f7af 100644
77974--- a/include/linux/slab_def.h
77975+++ b/include/linux/slab_def.h
77976@@ -50,7 +50,7 @@ struct kmem_cache {
77977 /* 4) cache creation/removal */
77978 const char *name;
77979 struct list_head list;
77980- int refcount;
77981+ atomic_t refcount;
77982 int object_size;
77983 int align;
77984
77985@@ -66,10 +66,14 @@ struct kmem_cache {
77986 unsigned long node_allocs;
77987 unsigned long node_frees;
77988 unsigned long node_overflow;
77989- atomic_t allochit;
77990- atomic_t allocmiss;
77991- atomic_t freehit;
77992- atomic_t freemiss;
77993+ atomic_unchecked_t allochit;
77994+ atomic_unchecked_t allocmiss;
77995+ atomic_unchecked_t freehit;
77996+ atomic_unchecked_t freemiss;
77997+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77998+ atomic_unchecked_t sanitized;
77999+ atomic_unchecked_t not_sanitized;
78000+#endif
78001
78002 /*
78003 * If debugging is enabled, then the allocator can add additional
78004@@ -103,7 +107,7 @@ struct kmem_cache {
78005 };
78006
78007 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
78008-void *__kmalloc(size_t size, gfp_t flags);
78009+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
78010
78011 #ifdef CONFIG_TRACING
78012 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
78013@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
78014 cachep = kmalloc_dma_caches[i];
78015 else
78016 #endif
78017+
78018+#ifdef CONFIG_PAX_USERCOPY_SLABS
78019+ if (flags & GFP_USERCOPY)
78020+ cachep = kmalloc_usercopy_caches[i];
78021+ else
78022+#endif
78023+
78024 cachep = kmalloc_caches[i];
78025
78026 ret = kmem_cache_alloc_trace(cachep, flags, size);
78027@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
78028 }
78029
78030 #ifdef CONFIG_NUMA
78031-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
78032+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
78033 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
78034
78035 #ifdef CONFIG_TRACING
78036@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
78037 cachep = kmalloc_dma_caches[i];
78038 else
78039 #endif
78040+
78041+#ifdef CONFIG_PAX_USERCOPY_SLABS
78042+ if (flags & GFP_USERCOPY)
78043+ cachep = kmalloc_usercopy_caches[i];
78044+ else
78045+#endif
78046+
78047 cachep = kmalloc_caches[i];
78048
78049 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
78050diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
78051index f28e14a..7831211 100644
78052--- a/include/linux/slob_def.h
78053+++ b/include/linux/slob_def.h
78054@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
78055 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
78056 }
78057
78058-void *__kmalloc_node(size_t size, gfp_t flags, int node);
78059+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
78060
78061 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
78062 {
78063@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
78064 return __kmalloc_node(size, flags, NUMA_NO_NODE);
78065 }
78066
78067-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
78068+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
78069 {
78070 return kmalloc(size, flags);
78071 }
78072diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
78073index 027276f..092bfe8 100644
78074--- a/include/linux/slub_def.h
78075+++ b/include/linux/slub_def.h
78076@@ -80,7 +80,7 @@ struct kmem_cache {
78077 struct kmem_cache_order_objects max;
78078 struct kmem_cache_order_objects min;
78079 gfp_t allocflags; /* gfp flags to use on each alloc */
78080- int refcount; /* Refcount for slab cache destroy */
78081+ atomic_t refcount; /* Refcount for slab cache destroy */
78082 void (*ctor)(void *);
78083 int inuse; /* Offset to metadata */
78084 int align; /* Alignment */
78085@@ -105,7 +105,7 @@ struct kmem_cache {
78086 };
78087
78088 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
78089-void *__kmalloc(size_t size, gfp_t flags);
78090+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
78091
78092 static __always_inline void *
78093 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
78094@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
78095 }
78096 #endif
78097
78098-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
78099+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
78100 {
78101 unsigned int order = get_order(size);
78102 return kmalloc_order_trace(size, flags, order);
78103@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
78104 }
78105
78106 #ifdef CONFIG_NUMA
78107-void *__kmalloc_node(size_t size, gfp_t flags, int node);
78108+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
78109 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
78110
78111 #ifdef CONFIG_TRACING
78112diff --git a/include/linux/smp.h b/include/linux/smp.h
78113index c848876..11e8a84 100644
78114--- a/include/linux/smp.h
78115+++ b/include/linux/smp.h
78116@@ -221,7 +221,9 @@ static inline void kick_all_cpus_sync(void) { }
78117 #endif
78118
78119 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
78120+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
78121 #define put_cpu() preempt_enable()
78122+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
78123
78124 /*
78125 * Callback to arch code if there's nosmp or maxcpus=0 on the
78126diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
78127index 54f91d3..be2c379 100644
78128--- a/include/linux/sock_diag.h
78129+++ b/include/linux/sock_diag.h
78130@@ -11,7 +11,7 @@ struct sock;
78131 struct sock_diag_handler {
78132 __u8 family;
78133 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
78134-};
78135+} __do_const;
78136
78137 int sock_diag_register(const struct sock_diag_handler *h);
78138 void sock_diag_unregister(const struct sock_diag_handler *h);
78139diff --git a/include/linux/sonet.h b/include/linux/sonet.h
78140index 680f9a3..f13aeb0 100644
78141--- a/include/linux/sonet.h
78142+++ b/include/linux/sonet.h
78143@@ -7,7 +7,7 @@
78144 #include <uapi/linux/sonet.h>
78145
78146 struct k_sonet_stats {
78147-#define __HANDLE_ITEM(i) atomic_t i
78148+#define __HANDLE_ITEM(i) atomic_unchecked_t i
78149 __SONET_ITEMS
78150 #undef __HANDLE_ITEM
78151 };
78152diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
78153index 07d8e53..dc934c9 100644
78154--- a/include/linux/sunrpc/addr.h
78155+++ b/include/linux/sunrpc/addr.h
78156@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
78157 {
78158 switch (sap->sa_family) {
78159 case AF_INET:
78160- return ntohs(((struct sockaddr_in *)sap)->sin_port);
78161+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
78162 case AF_INET6:
78163- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
78164+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
78165 }
78166 return 0;
78167 }
78168@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
78169 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
78170 const struct sockaddr *src)
78171 {
78172- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
78173+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
78174 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
78175
78176 dsin->sin_family = ssin->sin_family;
78177@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
78178 if (sa->sa_family != AF_INET6)
78179 return 0;
78180
78181- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
78182+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
78183 }
78184
78185 #endif /* _LINUX_SUNRPC_ADDR_H */
78186diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
78187index bfe11be..12bc8c4 100644
78188--- a/include/linux/sunrpc/clnt.h
78189+++ b/include/linux/sunrpc/clnt.h
78190@@ -96,7 +96,7 @@ struct rpc_procinfo {
78191 unsigned int p_timer; /* Which RTT timer to use */
78192 u32 p_statidx; /* Which procedure to account */
78193 const char * p_name; /* name of procedure */
78194-};
78195+} __do_const;
78196
78197 #ifdef __KERNEL__
78198
78199diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
78200index 1f0216b..6a4fa50 100644
78201--- a/include/linux/sunrpc/svc.h
78202+++ b/include/linux/sunrpc/svc.h
78203@@ -411,7 +411,7 @@ struct svc_procedure {
78204 unsigned int pc_count; /* call count */
78205 unsigned int pc_cachetype; /* cache info (NFS) */
78206 unsigned int pc_xdrressize; /* maximum size of XDR reply */
78207-};
78208+} __do_const;
78209
78210 /*
78211 * Function prototypes.
78212diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
78213index 0b8e3e6..33e0a01 100644
78214--- a/include/linux/sunrpc/svc_rdma.h
78215+++ b/include/linux/sunrpc/svc_rdma.h
78216@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
78217 extern unsigned int svcrdma_max_requests;
78218 extern unsigned int svcrdma_max_req_size;
78219
78220-extern atomic_t rdma_stat_recv;
78221-extern atomic_t rdma_stat_read;
78222-extern atomic_t rdma_stat_write;
78223-extern atomic_t rdma_stat_sq_starve;
78224-extern atomic_t rdma_stat_rq_starve;
78225-extern atomic_t rdma_stat_rq_poll;
78226-extern atomic_t rdma_stat_rq_prod;
78227-extern atomic_t rdma_stat_sq_poll;
78228-extern atomic_t rdma_stat_sq_prod;
78229+extern atomic_unchecked_t rdma_stat_recv;
78230+extern atomic_unchecked_t rdma_stat_read;
78231+extern atomic_unchecked_t rdma_stat_write;
78232+extern atomic_unchecked_t rdma_stat_sq_starve;
78233+extern atomic_unchecked_t rdma_stat_rq_starve;
78234+extern atomic_unchecked_t rdma_stat_rq_poll;
78235+extern atomic_unchecked_t rdma_stat_rq_prod;
78236+extern atomic_unchecked_t rdma_stat_sq_poll;
78237+extern atomic_unchecked_t rdma_stat_sq_prod;
78238
78239 #define RPCRDMA_VERSION 1
78240
78241diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
78242index ff374ab..7fd2ecb 100644
78243--- a/include/linux/sunrpc/svcauth.h
78244+++ b/include/linux/sunrpc/svcauth.h
78245@@ -109,7 +109,7 @@ struct auth_ops {
78246 int (*release)(struct svc_rqst *rq);
78247 void (*domain_release)(struct auth_domain *);
78248 int (*set_client)(struct svc_rqst *rq);
78249-};
78250+} __do_const;
78251
78252 #define SVC_GARBAGE 1
78253 #define SVC_SYSERR 2
78254diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
78255index a5ffd32..0935dea 100644
78256--- a/include/linux/swiotlb.h
78257+++ b/include/linux/swiotlb.h
78258@@ -60,7 +60,8 @@ extern void
78259
78260 extern void
78261 swiotlb_free_coherent(struct device *hwdev, size_t size,
78262- void *vaddr, dma_addr_t dma_handle);
78263+ void *vaddr, dma_addr_t dma_handle,
78264+ struct dma_attrs *attrs);
78265
78266 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
78267 unsigned long offset, size_t size,
78268diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
78269index 84662ec..5271947 100644
78270--- a/include/linux/syscalls.h
78271+++ b/include/linux/syscalls.h
78272@@ -97,8 +97,14 @@ struct sigaltstack;
78273 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
78274
78275 #define __SC_DECL(t, a) t a
78276+#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))
78277 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
78278-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
78279+#define __SC_LONG(t, a) __typeof( \
78280+ __builtin_choose_expr( \
78281+ sizeof(t) > sizeof(int), \
78282+ (t) 0, \
78283+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
78284+ )) a
78285 #define __SC_CAST(t, a) (t) a
78286 #define __SC_ARGS(t, a) a
78287 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
78288@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
78289 asmlinkage long sys_fsync(unsigned int fd);
78290 asmlinkage long sys_fdatasync(unsigned int fd);
78291 asmlinkage long sys_bdflush(int func, long data);
78292-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
78293- char __user *type, unsigned long flags,
78294+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
78295+ const char __user *type, unsigned long flags,
78296 void __user *data);
78297-asmlinkage long sys_umount(char __user *name, int flags);
78298-asmlinkage long sys_oldumount(char __user *name);
78299+asmlinkage long sys_umount(const char __user *name, int flags);
78300+asmlinkage long sys_oldumount(const char __user *name);
78301 asmlinkage long sys_truncate(const char __user *path, long length);
78302 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
78303 asmlinkage long sys_stat(const char __user *filename,
78304@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
78305 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
78306 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
78307 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
78308- struct sockaddr __user *, int);
78309+ struct sockaddr __user *, int) __intentional_overflow(0);
78310 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
78311 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
78312 unsigned int vlen, unsigned flags);
78313diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
78314index 27b3b0b..e093dd9 100644
78315--- a/include/linux/syscore_ops.h
78316+++ b/include/linux/syscore_ops.h
78317@@ -16,7 +16,7 @@ struct syscore_ops {
78318 int (*suspend)(void);
78319 void (*resume)(void);
78320 void (*shutdown)(void);
78321-};
78322+} __do_const;
78323
78324 extern void register_syscore_ops(struct syscore_ops *ops);
78325 extern void unregister_syscore_ops(struct syscore_ops *ops);
78326diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
78327index 14a8ff2..af52bad 100644
78328--- a/include/linux/sysctl.h
78329+++ b/include/linux/sysctl.h
78330@@ -34,13 +34,13 @@ struct ctl_table_root;
78331 struct ctl_table_header;
78332 struct ctl_dir;
78333
78334-typedef struct ctl_table ctl_table;
78335-
78336 typedef int proc_handler (struct ctl_table *ctl, int write,
78337 void __user *buffer, size_t *lenp, loff_t *ppos);
78338
78339 extern int proc_dostring(struct ctl_table *, int,
78340 void __user *, size_t *, loff_t *);
78341+extern int proc_dostring_modpriv(struct ctl_table *, int,
78342+ void __user *, size_t *, loff_t *);
78343 extern int proc_dointvec(struct ctl_table *, int,
78344 void __user *, size_t *, loff_t *);
78345 extern int proc_dointvec_minmax(struct ctl_table *, int,
78346@@ -115,7 +115,9 @@ struct ctl_table
78347 struct ctl_table_poll *poll;
78348 void *extra1;
78349 void *extra2;
78350-};
78351+} __do_const;
78352+typedef struct ctl_table __no_const ctl_table_no_const;
78353+typedef struct ctl_table ctl_table;
78354
78355 struct ctl_node {
78356 struct rb_node node;
78357diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
78358index e2cee22..3ddb921 100644
78359--- a/include/linux/sysfs.h
78360+++ b/include/linux/sysfs.h
78361@@ -31,7 +31,8 @@ struct attribute {
78362 struct lock_class_key *key;
78363 struct lock_class_key skey;
78364 #endif
78365-};
78366+} __do_const;
78367+typedef struct attribute __no_const attribute_no_const;
78368
78369 /**
78370 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
78371@@ -59,8 +60,8 @@ struct attribute_group {
78372 umode_t (*is_visible)(struct kobject *,
78373 struct attribute *, int);
78374 struct attribute **attrs;
78375-};
78376-
78377+} __do_const;
78378+typedef struct attribute_group __no_const attribute_group_no_const;
78379
78380
78381 /**
78382@@ -107,7 +108,8 @@ struct bin_attribute {
78383 char *, loff_t, size_t);
78384 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
78385 struct vm_area_struct *vma);
78386-};
78387+} __do_const;
78388+typedef struct bin_attribute __no_const bin_attribute_no_const;
78389
78390 /**
78391 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
78392diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
78393index 7faf933..9b85a0c 100644
78394--- a/include/linux/sysrq.h
78395+++ b/include/linux/sysrq.h
78396@@ -16,6 +16,7 @@
78397
78398 #include <linux/errno.h>
78399 #include <linux/types.h>
78400+#include <linux/compiler.h>
78401
78402 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
78403 #define SYSRQ_DEFAULT_ENABLE 1
78404@@ -36,7 +37,7 @@ struct sysrq_key_op {
78405 char *help_msg;
78406 char *action_msg;
78407 int enable_mask;
78408-};
78409+} __do_const;
78410
78411 #ifdef CONFIG_MAGIC_SYSRQ
78412
78413diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
78414index e7e0473..7989295 100644
78415--- a/include/linux/thread_info.h
78416+++ b/include/linux/thread_info.h
78417@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
78418 #error "no set_restore_sigmask() provided and default one won't work"
78419 #endif
78420
78421+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
78422+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
78423+{
78424+#ifndef CONFIG_PAX_USERCOPY_DEBUG
78425+ if (!__builtin_constant_p(n))
78426+#endif
78427+ __check_object_size(ptr, n, to_user);
78428+}
78429+
78430 #endif /* __KERNEL__ */
78431
78432 #endif /* _LINUX_THREAD_INFO_H */
78433diff --git a/include/linux/tty.h b/include/linux/tty.h
78434index 8780bd2..d1ae08b 100644
78435--- a/include/linux/tty.h
78436+++ b/include/linux/tty.h
78437@@ -194,7 +194,7 @@ struct tty_port {
78438 const struct tty_port_operations *ops; /* Port operations */
78439 spinlock_t lock; /* Lock protecting tty field */
78440 int blocked_open; /* Waiting to open */
78441- int count; /* Usage count */
78442+ atomic_t count; /* Usage count */
78443 wait_queue_head_t open_wait; /* Open waiters */
78444 wait_queue_head_t close_wait; /* Close waiters */
78445 wait_queue_head_t delta_msr_wait; /* Modem status change */
78446@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
78447 struct tty_struct *tty, struct file *filp);
78448 static inline int tty_port_users(struct tty_port *port)
78449 {
78450- return port->count + port->blocked_open;
78451+ return atomic_read(&port->count) + port->blocked_open;
78452 }
78453
78454 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
78455diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
78456index 756a609..b302dd6 100644
78457--- a/include/linux/tty_driver.h
78458+++ b/include/linux/tty_driver.h
78459@@ -285,7 +285,7 @@ struct tty_operations {
78460 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
78461 #endif
78462 const struct file_operations *proc_fops;
78463-};
78464+} __do_const;
78465
78466 struct tty_driver {
78467 int magic; /* magic number for this structure */
78468diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
78469index 58390c7..95e214c 100644
78470--- a/include/linux/tty_ldisc.h
78471+++ b/include/linux/tty_ldisc.h
78472@@ -146,7 +146,7 @@ struct tty_ldisc_ops {
78473
78474 struct module *owner;
78475
78476- int refcount;
78477+ atomic_t refcount;
78478 };
78479
78480 struct tty_ldisc {
78481diff --git a/include/linux/types.h b/include/linux/types.h
78482index 4d118ba..c3ee9bf 100644
78483--- a/include/linux/types.h
78484+++ b/include/linux/types.h
78485@@ -176,10 +176,26 @@ typedef struct {
78486 int counter;
78487 } atomic_t;
78488
78489+#ifdef CONFIG_PAX_REFCOUNT
78490+typedef struct {
78491+ int counter;
78492+} atomic_unchecked_t;
78493+#else
78494+typedef atomic_t atomic_unchecked_t;
78495+#endif
78496+
78497 #ifdef CONFIG_64BIT
78498 typedef struct {
78499 long counter;
78500 } atomic64_t;
78501+
78502+#ifdef CONFIG_PAX_REFCOUNT
78503+typedef struct {
78504+ long counter;
78505+} atomic64_unchecked_t;
78506+#else
78507+typedef atomic64_t atomic64_unchecked_t;
78508+#endif
78509 #endif
78510
78511 struct list_head {
78512diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
78513index 5ca0951..ab496a5 100644
78514--- a/include/linux/uaccess.h
78515+++ b/include/linux/uaccess.h
78516@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
78517 long ret; \
78518 mm_segment_t old_fs = get_fs(); \
78519 \
78520- set_fs(KERNEL_DS); \
78521 pagefault_disable(); \
78522- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
78523- pagefault_enable(); \
78524+ set_fs(KERNEL_DS); \
78525+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
78526 set_fs(old_fs); \
78527+ pagefault_enable(); \
78528 ret; \
78529 })
78530
78531diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
78532index 8e522cbc..aa8572d 100644
78533--- a/include/linux/uidgid.h
78534+++ b/include/linux/uidgid.h
78535@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
78536
78537 #endif /* CONFIG_USER_NS */
78538
78539+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
78540+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
78541+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
78542+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
78543+
78544 #endif /* _LINUX_UIDGID_H */
78545diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
78546index 99c1b4d..562e6f3 100644
78547--- a/include/linux/unaligned/access_ok.h
78548+++ b/include/linux/unaligned/access_ok.h
78549@@ -4,34 +4,34 @@
78550 #include <linux/kernel.h>
78551 #include <asm/byteorder.h>
78552
78553-static inline u16 get_unaligned_le16(const void *p)
78554+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
78555 {
78556- return le16_to_cpup((__le16 *)p);
78557+ return le16_to_cpup((const __le16 *)p);
78558 }
78559
78560-static inline u32 get_unaligned_le32(const void *p)
78561+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
78562 {
78563- return le32_to_cpup((__le32 *)p);
78564+ return le32_to_cpup((const __le32 *)p);
78565 }
78566
78567-static inline u64 get_unaligned_le64(const void *p)
78568+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
78569 {
78570- return le64_to_cpup((__le64 *)p);
78571+ return le64_to_cpup((const __le64 *)p);
78572 }
78573
78574-static inline u16 get_unaligned_be16(const void *p)
78575+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
78576 {
78577- return be16_to_cpup((__be16 *)p);
78578+ return be16_to_cpup((const __be16 *)p);
78579 }
78580
78581-static inline u32 get_unaligned_be32(const void *p)
78582+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
78583 {
78584- return be32_to_cpup((__be32 *)p);
78585+ return be32_to_cpup((const __be32 *)p);
78586 }
78587
78588-static inline u64 get_unaligned_be64(const void *p)
78589+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
78590 {
78591- return be64_to_cpup((__be64 *)p);
78592+ return be64_to_cpup((const __be64 *)p);
78593 }
78594
78595 static inline void put_unaligned_le16(u16 val, void *p)
78596diff --git a/include/linux/usb.h b/include/linux/usb.h
78597index a0bee5a..5533a52 100644
78598--- a/include/linux/usb.h
78599+++ b/include/linux/usb.h
78600@@ -552,7 +552,7 @@ struct usb_device {
78601 int maxchild;
78602
78603 u32 quirks;
78604- atomic_t urbnum;
78605+ atomic_unchecked_t urbnum;
78606
78607 unsigned long active_duration;
78608
78609@@ -1607,7 +1607,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
78610
78611 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
78612 __u8 request, __u8 requesttype, __u16 value, __u16 index,
78613- void *data, __u16 size, int timeout);
78614+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
78615 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
78616 void *data, int len, int *actual_length, int timeout);
78617 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
78618diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
78619index e452ba6..78f8e80 100644
78620--- a/include/linux/usb/renesas_usbhs.h
78621+++ b/include/linux/usb/renesas_usbhs.h
78622@@ -39,7 +39,7 @@ enum {
78623 */
78624 struct renesas_usbhs_driver_callback {
78625 int (*notify_hotplug)(struct platform_device *pdev);
78626-};
78627+} __no_const;
78628
78629 /*
78630 * callback functions for platform
78631diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
78632index 6f8fbcf..8259001 100644
78633--- a/include/linux/vermagic.h
78634+++ b/include/linux/vermagic.h
78635@@ -25,9 +25,35 @@
78636 #define MODULE_ARCH_VERMAGIC ""
78637 #endif
78638
78639+#ifdef CONFIG_PAX_REFCOUNT
78640+#define MODULE_PAX_REFCOUNT "REFCOUNT "
78641+#else
78642+#define MODULE_PAX_REFCOUNT ""
78643+#endif
78644+
78645+#ifdef CONSTIFY_PLUGIN
78646+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
78647+#else
78648+#define MODULE_CONSTIFY_PLUGIN ""
78649+#endif
78650+
78651+#ifdef STACKLEAK_PLUGIN
78652+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
78653+#else
78654+#define MODULE_STACKLEAK_PLUGIN ""
78655+#endif
78656+
78657+#ifdef CONFIG_GRKERNSEC
78658+#define MODULE_GRSEC "GRSEC "
78659+#else
78660+#define MODULE_GRSEC ""
78661+#endif
78662+
78663 #define VERMAGIC_STRING \
78664 UTS_RELEASE " " \
78665 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
78666 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
78667- MODULE_ARCH_VERMAGIC
78668+ MODULE_ARCH_VERMAGIC \
78669+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
78670+ MODULE_GRSEC
78671
78672diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
78673index 7d5773a..541c01c 100644
78674--- a/include/linux/vmalloc.h
78675+++ b/include/linux/vmalloc.h
78676@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
78677 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
78678 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
78679 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
78680+
78681+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78682+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
78683+#endif
78684+
78685 /* bits [20..32] reserved for arch specific ioremap internals */
78686
78687 /*
78688@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
78689 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
78690 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
78691 unsigned long start, unsigned long end, gfp_t gfp_mask,
78692- pgprot_t prot, int node, const void *caller);
78693+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
78694 extern void vfree(const void *addr);
78695
78696 extern void *vmap(struct page **pages, unsigned int count,
78697@@ -137,8 +142,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
78698 extern void free_vm_area(struct vm_struct *area);
78699
78700 /* for /dev/kmem */
78701-extern long vread(char *buf, char *addr, unsigned long count);
78702-extern long vwrite(char *buf, char *addr, unsigned long count);
78703+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
78704+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
78705
78706 /*
78707 * Internals. Dont't use..
78708diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
78709index c586679..f06b389 100644
78710--- a/include/linux/vmstat.h
78711+++ b/include/linux/vmstat.h
78712@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
78713 /*
78714 * Zone based page accounting with per cpu differentials.
78715 */
78716-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
78717+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
78718
78719 static inline void zone_page_state_add(long x, struct zone *zone,
78720 enum zone_stat_item item)
78721 {
78722- atomic_long_add(x, &zone->vm_stat[item]);
78723- atomic_long_add(x, &vm_stat[item]);
78724+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
78725+ atomic_long_add_unchecked(x, &vm_stat[item]);
78726 }
78727
78728 static inline unsigned long global_page_state(enum zone_stat_item item)
78729 {
78730- long x = atomic_long_read(&vm_stat[item]);
78731+ long x = atomic_long_read_unchecked(&vm_stat[item]);
78732 #ifdef CONFIG_SMP
78733 if (x < 0)
78734 x = 0;
78735@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
78736 static inline unsigned long zone_page_state(struct zone *zone,
78737 enum zone_stat_item item)
78738 {
78739- long x = atomic_long_read(&zone->vm_stat[item]);
78740+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
78741 #ifdef CONFIG_SMP
78742 if (x < 0)
78743 x = 0;
78744@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
78745 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
78746 enum zone_stat_item item)
78747 {
78748- long x = atomic_long_read(&zone->vm_stat[item]);
78749+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
78750
78751 #ifdef CONFIG_SMP
78752 int cpu;
78753@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
78754
78755 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
78756 {
78757- atomic_long_inc(&zone->vm_stat[item]);
78758- atomic_long_inc(&vm_stat[item]);
78759+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
78760+ atomic_long_inc_unchecked(&vm_stat[item]);
78761 }
78762
78763 static inline void __inc_zone_page_state(struct page *page,
78764@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
78765
78766 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
78767 {
78768- atomic_long_dec(&zone->vm_stat[item]);
78769- atomic_long_dec(&vm_stat[item]);
78770+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
78771+ atomic_long_dec_unchecked(&vm_stat[item]);
78772 }
78773
78774 static inline void __dec_zone_page_state(struct page *page,
78775diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
78776index 623488f..44b5742 100644
78777--- a/include/linux/workqueue.h
78778+++ b/include/linux/workqueue.h
78779@@ -410,11 +410,11 @@ __alloc_workqueue_key(const char *fmt, unsigned int flags, int max_active,
78780 alloc_workqueue(fmt, WQ_UNBOUND | __WQ_ORDERED | (flags), 1, ##args)
78781
78782 #define create_workqueue(name) \
78783- alloc_workqueue((name), WQ_MEM_RECLAIM, 1)
78784+ alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, (name))
78785 #define create_freezable_workqueue(name) \
78786- alloc_workqueue((name), WQ_FREEZABLE | WQ_UNBOUND | WQ_MEM_RECLAIM, 1)
78787+ alloc_workqueue("%s", WQ_FREEZABLE | WQ_UNBOUND | WQ_MEM_RECLAIM, 1, (name))
78788 #define create_singlethread_workqueue(name) \
78789- alloc_workqueue((name), WQ_UNBOUND | WQ_MEM_RECLAIM, 1)
78790+ alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1, (name))
78791
78792 extern void destroy_workqueue(struct workqueue_struct *wq);
78793
78794diff --git a/include/linux/xattr.h b/include/linux/xattr.h
78795index fdbafc6..49dfe4f 100644
78796--- a/include/linux/xattr.h
78797+++ b/include/linux/xattr.h
78798@@ -28,7 +28,7 @@ struct xattr_handler {
78799 size_t size, int handler_flags);
78800 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
78801 size_t size, int flags, int handler_flags);
78802-};
78803+} __do_const;
78804
78805 struct xattr {
78806 char *name;
78807@@ -37,6 +37,9 @@ struct xattr {
78808 };
78809
78810 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
78811+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78812+ssize_t pax_getxattr(struct dentry *, void *, size_t);
78813+#endif
78814 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
78815 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
78816 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
78817diff --git a/include/linux/zlib.h b/include/linux/zlib.h
78818index 9c5a6b4..09c9438 100644
78819--- a/include/linux/zlib.h
78820+++ b/include/linux/zlib.h
78821@@ -31,6 +31,7 @@
78822 #define _ZLIB_H
78823
78824 #include <linux/zconf.h>
78825+#include <linux/compiler.h>
78826
78827 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
78828 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
78829@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
78830
78831 /* basic functions */
78832
78833-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
78834+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
78835 /*
78836 Returns the number of bytes that needs to be allocated for a per-
78837 stream workspace with the specified parameters. A pointer to this
78838diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
78839index 95d1c91..6798cca 100644
78840--- a/include/media/v4l2-dev.h
78841+++ b/include/media/v4l2-dev.h
78842@@ -76,7 +76,7 @@ struct v4l2_file_operations {
78843 int (*mmap) (struct file *, struct vm_area_struct *);
78844 int (*open) (struct file *);
78845 int (*release) (struct file *);
78846-};
78847+} __do_const;
78848
78849 /*
78850 * Newer version of video_device, handled by videodev2.c
78851diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
78852index c9b1593..a572459 100644
78853--- a/include/media/v4l2-device.h
78854+++ b/include/media/v4l2-device.h
78855@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
78856 this function returns 0. If the name ends with a digit (e.g. cx18),
78857 then the name will be set to cx18-0 since cx180 looks really odd. */
78858 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
78859- atomic_t *instance);
78860+ atomic_unchecked_t *instance);
78861
78862 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
78863 Since the parent disappears this ensures that v4l2_dev doesn't have an
78864diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
78865index adcbb20..62c2559 100644
78866--- a/include/net/9p/transport.h
78867+++ b/include/net/9p/transport.h
78868@@ -57,7 +57,7 @@ struct p9_trans_module {
78869 int (*cancel) (struct p9_client *, struct p9_req_t *req);
78870 int (*zc_request)(struct p9_client *, struct p9_req_t *,
78871 char *, char *, int , int, int, int);
78872-};
78873+} __do_const;
78874
78875 void v9fs_register_trans(struct p9_trans_module *m);
78876 void v9fs_unregister_trans(struct p9_trans_module *m);
78877diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
78878index fb94cf1..7c0c987 100644
78879--- a/include/net/bluetooth/l2cap.h
78880+++ b/include/net/bluetooth/l2cap.h
78881@@ -551,7 +551,7 @@ struct l2cap_ops {
78882 void (*defer) (struct l2cap_chan *chan);
78883 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
78884 unsigned long len, int nb);
78885-};
78886+} __do_const;
78887
78888 struct l2cap_conn {
78889 struct hci_conn *hcon;
78890diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
78891index f2ae33d..c457cf0 100644
78892--- a/include/net/caif/cfctrl.h
78893+++ b/include/net/caif/cfctrl.h
78894@@ -52,7 +52,7 @@ struct cfctrl_rsp {
78895 void (*radioset_rsp)(void);
78896 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
78897 struct cflayer *client_layer);
78898-};
78899+} __no_const;
78900
78901 /* Link Setup Parameters for CAIF-Links. */
78902 struct cfctrl_link_param {
78903@@ -101,8 +101,8 @@ struct cfctrl_request_info {
78904 struct cfctrl {
78905 struct cfsrvl serv;
78906 struct cfctrl_rsp res;
78907- atomic_t req_seq_no;
78908- atomic_t rsp_seq_no;
78909+ atomic_unchecked_t req_seq_no;
78910+ atomic_unchecked_t rsp_seq_no;
78911 struct list_head list;
78912 /* Protects from simultaneous access to first_req list */
78913 spinlock_t info_list_lock;
78914diff --git a/include/net/flow.h b/include/net/flow.h
78915index 628e11b..4c475df 100644
78916--- a/include/net/flow.h
78917+++ b/include/net/flow.h
78918@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
78919
78920 extern void flow_cache_flush(void);
78921 extern void flow_cache_flush_deferred(void);
78922-extern atomic_t flow_cache_genid;
78923+extern atomic_unchecked_t flow_cache_genid;
78924
78925 #endif
78926diff --git a/include/net/genetlink.h b/include/net/genetlink.h
78927index 93024a4..eeb6b6e 100644
78928--- a/include/net/genetlink.h
78929+++ b/include/net/genetlink.h
78930@@ -119,7 +119,7 @@ struct genl_ops {
78931 struct netlink_callback *cb);
78932 int (*done)(struct netlink_callback *cb);
78933 struct list_head ops_list;
78934-};
78935+} __do_const;
78936
78937 extern int genl_register_family(struct genl_family *family);
78938 extern int genl_register_family_with_ops(struct genl_family *family,
78939diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
78940index 734d9b5..48a9a4b 100644
78941--- a/include/net/gro_cells.h
78942+++ b/include/net/gro_cells.h
78943@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
78944 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
78945
78946 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
78947- atomic_long_inc(&dev->rx_dropped);
78948+ atomic_long_inc_unchecked(&dev->rx_dropped);
78949 kfree_skb(skb);
78950 return;
78951 }
78952diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
78953index de2c785..0588a6b 100644
78954--- a/include/net/inet_connection_sock.h
78955+++ b/include/net/inet_connection_sock.h
78956@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
78957 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
78958 int (*bind_conflict)(const struct sock *sk,
78959 const struct inet_bind_bucket *tb, bool relax);
78960-};
78961+} __do_const;
78962
78963 /** inet_connection_sock - INET connection oriented sock
78964 *
78965diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
78966index 53f464d..0bd0b49 100644
78967--- a/include/net/inetpeer.h
78968+++ b/include/net/inetpeer.h
78969@@ -47,8 +47,8 @@ struct inet_peer {
78970 */
78971 union {
78972 struct {
78973- atomic_t rid; /* Frag reception counter */
78974- atomic_t ip_id_count; /* IP ID for the next packet */
78975+ atomic_unchecked_t rid; /* Frag reception counter */
78976+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
78977 };
78978 struct rcu_head rcu;
78979 struct inet_peer *gc_next;
78980@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
78981 /* can be called with or without local BH being disabled */
78982 static inline int inet_getid(struct inet_peer *p, int more)
78983 {
78984- int old, new;
78985+ int id;
78986 more++;
78987 inet_peer_refcheck(p);
78988- do {
78989- old = atomic_read(&p->ip_id_count);
78990- new = old + more;
78991- if (!new)
78992- new = 1;
78993- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
78994- return new;
78995+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
78996+ if (!id)
78997+ id = atomic_inc_return_unchecked(&p->ip_id_count);
78998+ return id;
78999 }
79000
79001 #endif /* _NET_INETPEER_H */
79002diff --git a/include/net/ip.h b/include/net/ip.h
79003index a68f838..74518ab 100644
79004--- a/include/net/ip.h
79005+++ b/include/net/ip.h
79006@@ -202,7 +202,7 @@ extern struct local_ports {
79007 } sysctl_local_ports;
79008 extern void inet_get_local_port_range(int *low, int *high);
79009
79010-extern unsigned long *sysctl_local_reserved_ports;
79011+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
79012 static inline int inet_is_reserved_local_port(int port)
79013 {
79014 return test_bit(port, sysctl_local_reserved_ports);
79015diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
79016index e49db91..76a81de 100644
79017--- a/include/net/ip_fib.h
79018+++ b/include/net/ip_fib.h
79019@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
79020
79021 #define FIB_RES_SADDR(net, res) \
79022 ((FIB_RES_NH(res).nh_saddr_genid == \
79023- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
79024+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
79025 FIB_RES_NH(res).nh_saddr : \
79026 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
79027 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
79028diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
79029index 4c062cc..3562c31 100644
79030--- a/include/net/ip_vs.h
79031+++ b/include/net/ip_vs.h
79032@@ -612,7 +612,7 @@ struct ip_vs_conn {
79033 struct ip_vs_conn *control; /* Master control connection */
79034 atomic_t n_control; /* Number of controlled ones */
79035 struct ip_vs_dest *dest; /* real server */
79036- atomic_t in_pkts; /* incoming packet counter */
79037+ atomic_unchecked_t in_pkts; /* incoming packet counter */
79038
79039 /* packet transmitter for different forwarding methods. If it
79040 mangles the packet, it must return NF_DROP or better NF_STOLEN,
79041@@ -761,7 +761,7 @@ struct ip_vs_dest {
79042 __be16 port; /* port number of the server */
79043 union nf_inet_addr addr; /* IP address of the server */
79044 volatile unsigned int flags; /* dest status flags */
79045- atomic_t conn_flags; /* flags to copy to conn */
79046+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
79047 atomic_t weight; /* server weight */
79048
79049 atomic_t refcnt; /* reference counter */
79050@@ -1013,11 +1013,11 @@ struct netns_ipvs {
79051 /* ip_vs_lblc */
79052 int sysctl_lblc_expiration;
79053 struct ctl_table_header *lblc_ctl_header;
79054- struct ctl_table *lblc_ctl_table;
79055+ ctl_table_no_const *lblc_ctl_table;
79056 /* ip_vs_lblcr */
79057 int sysctl_lblcr_expiration;
79058 struct ctl_table_header *lblcr_ctl_header;
79059- struct ctl_table *lblcr_ctl_table;
79060+ ctl_table_no_const *lblcr_ctl_table;
79061 /* ip_vs_est */
79062 struct list_head est_list; /* estimator list */
79063 spinlock_t est_lock;
79064diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
79065index 80ffde3..968b0f4 100644
79066--- a/include/net/irda/ircomm_tty.h
79067+++ b/include/net/irda/ircomm_tty.h
79068@@ -35,6 +35,7 @@
79069 #include <linux/termios.h>
79070 #include <linux/timer.h>
79071 #include <linux/tty.h> /* struct tty_struct */
79072+#include <asm/local.h>
79073
79074 #include <net/irda/irias_object.h>
79075 #include <net/irda/ircomm_core.h>
79076diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
79077index 714cc9a..ea05f3e 100644
79078--- a/include/net/iucv/af_iucv.h
79079+++ b/include/net/iucv/af_iucv.h
79080@@ -149,7 +149,7 @@ struct iucv_skb_cb {
79081 struct iucv_sock_list {
79082 struct hlist_head head;
79083 rwlock_t lock;
79084- atomic_t autobind_name;
79085+ atomic_unchecked_t autobind_name;
79086 };
79087
79088 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
79089diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
79090index df83f69..9b640b8 100644
79091--- a/include/net/llc_c_ac.h
79092+++ b/include/net/llc_c_ac.h
79093@@ -87,7 +87,7 @@
79094 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
79095 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
79096
79097-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
79098+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
79099
79100 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
79101 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
79102diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
79103index 6ca3113..f8026dd 100644
79104--- a/include/net/llc_c_ev.h
79105+++ b/include/net/llc_c_ev.h
79106@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
79107 return (struct llc_conn_state_ev *)skb->cb;
79108 }
79109
79110-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
79111-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
79112+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
79113+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
79114
79115 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
79116 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
79117diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
79118index 0e79cfb..f46db31 100644
79119--- a/include/net/llc_c_st.h
79120+++ b/include/net/llc_c_st.h
79121@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
79122 u8 next_state;
79123 llc_conn_ev_qfyr_t *ev_qualifiers;
79124 llc_conn_action_t *ev_actions;
79125-};
79126+} __do_const;
79127
79128 struct llc_conn_state {
79129 u8 current_state;
79130diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
79131index 37a3bbd..55a4241 100644
79132--- a/include/net/llc_s_ac.h
79133+++ b/include/net/llc_s_ac.h
79134@@ -23,7 +23,7 @@
79135 #define SAP_ACT_TEST_IND 9
79136
79137 /* All action functions must look like this */
79138-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
79139+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
79140
79141 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
79142 struct sk_buff *skb);
79143diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
79144index 567c681..cd73ac0 100644
79145--- a/include/net/llc_s_st.h
79146+++ b/include/net/llc_s_st.h
79147@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
79148 llc_sap_ev_t ev;
79149 u8 next_state;
79150 llc_sap_action_t *ev_actions;
79151-};
79152+} __do_const;
79153
79154 struct llc_sap_state {
79155 u8 curr_state;
79156diff --git a/include/net/mac80211.h b/include/net/mac80211.h
79157index 4e50d36..c7585a7 100644
79158--- a/include/net/mac80211.h
79159+++ b/include/net/mac80211.h
79160@@ -4206,7 +4206,7 @@ struct rate_control_ops {
79161 void (*add_sta_debugfs)(void *priv, void *priv_sta,
79162 struct dentry *dir);
79163 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
79164-};
79165+} __do_const;
79166
79167 static inline int rate_supported(struct ieee80211_sta *sta,
79168 enum ieee80211_band band,
79169diff --git a/include/net/neighbour.h b/include/net/neighbour.h
79170index 7e748ad..5c6229b 100644
79171--- a/include/net/neighbour.h
79172+++ b/include/net/neighbour.h
79173@@ -123,7 +123,7 @@ struct neigh_ops {
79174 void (*error_report)(struct neighbour *, struct sk_buff *);
79175 int (*output)(struct neighbour *, struct sk_buff *);
79176 int (*connected_output)(struct neighbour *, struct sk_buff *);
79177-};
79178+} __do_const;
79179
79180 struct pneigh_entry {
79181 struct pneigh_entry *next;
79182diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
79183index b176978..ea169f4 100644
79184--- a/include/net/net_namespace.h
79185+++ b/include/net/net_namespace.h
79186@@ -117,7 +117,7 @@ struct net {
79187 #endif
79188 struct netns_ipvs *ipvs;
79189 struct sock *diag_nlsk;
79190- atomic_t rt_genid;
79191+ atomic_unchecked_t rt_genid;
79192 };
79193
79194 /*
79195@@ -274,7 +274,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
79196 #define __net_init __init
79197 #define __net_exit __exit_refok
79198 #define __net_initdata __initdata
79199+#ifdef CONSTIFY_PLUGIN
79200 #define __net_initconst __initconst
79201+#else
79202+#define __net_initconst __initdata
79203+#endif
79204 #endif
79205
79206 struct pernet_operations {
79207@@ -284,7 +288,7 @@ struct pernet_operations {
79208 void (*exit_batch)(struct list_head *net_exit_list);
79209 int *id;
79210 size_t size;
79211-};
79212+} __do_const;
79213
79214 /*
79215 * Use these carefully. If you implement a network device and it
79216@@ -332,12 +336,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
79217
79218 static inline int rt_genid(struct net *net)
79219 {
79220- return atomic_read(&net->rt_genid);
79221+ return atomic_read_unchecked(&net->rt_genid);
79222 }
79223
79224 static inline void rt_genid_bump(struct net *net)
79225 {
79226- atomic_inc(&net->rt_genid);
79227+ atomic_inc_unchecked(&net->rt_genid);
79228 }
79229
79230 #endif /* __NET_NET_NAMESPACE_H */
79231diff --git a/include/net/netdma.h b/include/net/netdma.h
79232index 8ba8ce2..99b7fff 100644
79233--- a/include/net/netdma.h
79234+++ b/include/net/netdma.h
79235@@ -24,7 +24,7 @@
79236 #include <linux/dmaengine.h>
79237 #include <linux/skbuff.h>
79238
79239-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
79240+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
79241 struct sk_buff *skb, int offset, struct iovec *to,
79242 size_t len, struct dma_pinned_list *pinned_list);
79243
79244diff --git a/include/net/netlink.h b/include/net/netlink.h
79245index 9690b0f..87aded7 100644
79246--- a/include/net/netlink.h
79247+++ b/include/net/netlink.h
79248@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
79249 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
79250 {
79251 if (mark)
79252- skb_trim(skb, (unsigned char *) mark - skb->data);
79253+ skb_trim(skb, (const unsigned char *) mark - skb->data);
79254 }
79255
79256 /**
79257diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
79258index c9c0c53..53f24c3 100644
79259--- a/include/net/netns/conntrack.h
79260+++ b/include/net/netns/conntrack.h
79261@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
79262 struct nf_proto_net {
79263 #ifdef CONFIG_SYSCTL
79264 struct ctl_table_header *ctl_table_header;
79265- struct ctl_table *ctl_table;
79266+ ctl_table_no_const *ctl_table;
79267 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
79268 struct ctl_table_header *ctl_compat_header;
79269- struct ctl_table *ctl_compat_table;
79270+ ctl_table_no_const *ctl_compat_table;
79271 #endif
79272 #endif
79273 unsigned int users;
79274@@ -58,7 +58,7 @@ struct nf_ip_net {
79275 struct nf_icmp_net icmpv6;
79276 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
79277 struct ctl_table_header *ctl_table_header;
79278- struct ctl_table *ctl_table;
79279+ ctl_table_no_const *ctl_table;
79280 #endif
79281 };
79282
79283diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
79284index 2ba9de8..47bd6c7 100644
79285--- a/include/net/netns/ipv4.h
79286+++ b/include/net/netns/ipv4.h
79287@@ -67,7 +67,7 @@ struct netns_ipv4 {
79288 kgid_t sysctl_ping_group_range[2];
79289 long sysctl_tcp_mem[3];
79290
79291- atomic_t dev_addr_genid;
79292+ atomic_unchecked_t dev_addr_genid;
79293
79294 #ifdef CONFIG_IP_MROUTE
79295 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
79296diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
79297index 005e2c2..023d340 100644
79298--- a/include/net/netns/ipv6.h
79299+++ b/include/net/netns/ipv6.h
79300@@ -71,7 +71,7 @@ struct netns_ipv6 {
79301 struct fib_rules_ops *mr6_rules_ops;
79302 #endif
79303 #endif
79304- atomic_t dev_addr_genid;
79305+ atomic_unchecked_t dev_addr_genid;
79306 };
79307
79308 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
79309diff --git a/include/net/protocol.h b/include/net/protocol.h
79310index 047c047..b9dad15 100644
79311--- a/include/net/protocol.h
79312+++ b/include/net/protocol.h
79313@@ -44,7 +44,7 @@ struct net_protocol {
79314 void (*err_handler)(struct sk_buff *skb, u32 info);
79315 unsigned int no_policy:1,
79316 netns_ok:1;
79317-};
79318+} __do_const;
79319
79320 #if IS_ENABLED(CONFIG_IPV6)
79321 struct inet6_protocol {
79322@@ -57,7 +57,7 @@ struct inet6_protocol {
79323 u8 type, u8 code, int offset,
79324 __be32 info);
79325 unsigned int flags; /* INET6_PROTO_xxx */
79326-};
79327+} __do_const;
79328
79329 #define INET6_PROTO_NOPOLICY 0x1
79330 #define INET6_PROTO_FINAL 0x2
79331diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
79332index 7026648..584cc8c 100644
79333--- a/include/net/rtnetlink.h
79334+++ b/include/net/rtnetlink.h
79335@@ -81,7 +81,7 @@ struct rtnl_link_ops {
79336 const struct net_device *dev);
79337 unsigned int (*get_num_tx_queues)(void);
79338 unsigned int (*get_num_rx_queues)(void);
79339-};
79340+} __do_const;
79341
79342 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
79343 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
79344diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
79345index cd89510..d67810f 100644
79346--- a/include/net/sctp/sctp.h
79347+++ b/include/net/sctp/sctp.h
79348@@ -330,9 +330,9 @@ do { \
79349
79350 #else /* SCTP_DEBUG */
79351
79352-#define SCTP_DEBUG_PRINTK(whatever...)
79353-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
79354-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
79355+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
79356+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
79357+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
79358 #define SCTP_ENABLE_DEBUG
79359 #define SCTP_DISABLE_DEBUG
79360 #define SCTP_ASSERT(expr, str, func)
79361diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
79362index 2a82d13..62a31c2 100644
79363--- a/include/net/sctp/sm.h
79364+++ b/include/net/sctp/sm.h
79365@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
79366 typedef struct {
79367 sctp_state_fn_t *fn;
79368 const char *name;
79369-} sctp_sm_table_entry_t;
79370+} __do_const sctp_sm_table_entry_t;
79371
79372 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
79373 * currently in use.
79374@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
79375 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
79376
79377 /* Extern declarations for major data structures. */
79378-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
79379+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
79380
79381
79382 /* Get the size of a DATA chunk payload. */
79383diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
79384index 1bd4c41..9250b5b 100644
79385--- a/include/net/sctp/structs.h
79386+++ b/include/net/sctp/structs.h
79387@@ -516,7 +516,7 @@ struct sctp_pf {
79388 struct sctp_association *asoc);
79389 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
79390 struct sctp_af *af;
79391-};
79392+} __do_const;
79393
79394
79395 /* Structure to track chunk fragments that have been acked, but peer
79396diff --git a/include/net/sock.h b/include/net/sock.h
79397index 66772cf..25bc45b 100644
79398--- a/include/net/sock.h
79399+++ b/include/net/sock.h
79400@@ -325,7 +325,7 @@ struct sock {
79401 #ifdef CONFIG_RPS
79402 __u32 sk_rxhash;
79403 #endif
79404- atomic_t sk_drops;
79405+ atomic_unchecked_t sk_drops;
79406 int sk_rcvbuf;
79407
79408 struct sk_filter __rcu *sk_filter;
79409@@ -1797,7 +1797,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
79410 }
79411
79412 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
79413- char __user *from, char *to,
79414+ char __user *from, unsigned char *to,
79415 int copy, int offset)
79416 {
79417 if (skb->ip_summed == CHECKSUM_NONE) {
79418@@ -2056,7 +2056,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
79419 }
79420 }
79421
79422-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
79423+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
79424
79425 /**
79426 * sk_page_frag - return an appropriate page_frag
79427diff --git a/include/net/tcp.h b/include/net/tcp.h
79428index 5bba80f..8520a82 100644
79429--- a/include/net/tcp.h
79430+++ b/include/net/tcp.h
79431@@ -524,7 +524,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
79432 extern void tcp_xmit_retransmit_queue(struct sock *);
79433 extern void tcp_simple_retransmit(struct sock *);
79434 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
79435-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
79436+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
79437
79438 extern void tcp_send_probe0(struct sock *);
79439 extern void tcp_send_partial(struct sock *);
79440@@ -697,8 +697,8 @@ struct tcp_skb_cb {
79441 struct inet6_skb_parm h6;
79442 #endif
79443 } header; /* For incoming frames */
79444- __u32 seq; /* Starting sequence number */
79445- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
79446+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
79447+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
79448 __u32 when; /* used to compute rtt's */
79449 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
79450
79451@@ -712,7 +712,7 @@ struct tcp_skb_cb {
79452
79453 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
79454 /* 1 byte hole */
79455- __u32 ack_seq; /* Sequence number ACK'd */
79456+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
79457 };
79458
79459 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
79460diff --git a/include/net/xfrm.h b/include/net/xfrm.h
79461index 94ce082..62b278d 100644
79462--- a/include/net/xfrm.h
79463+++ b/include/net/xfrm.h
79464@@ -305,7 +305,7 @@ struct xfrm_policy_afinfo {
79465 struct net_device *dev,
79466 const struct flowi *fl);
79467 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
79468-};
79469+} __do_const;
79470
79471 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
79472 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
79473@@ -341,7 +341,7 @@ struct xfrm_state_afinfo {
79474 struct sk_buff *skb);
79475 int (*transport_finish)(struct sk_buff *skb,
79476 int async);
79477-};
79478+} __do_const;
79479
79480 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
79481 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
79482@@ -424,7 +424,7 @@ struct xfrm_mode {
79483 struct module *owner;
79484 unsigned int encap;
79485 int flags;
79486-};
79487+} __do_const;
79488
79489 /* Flags for xfrm_mode. */
79490 enum {
79491@@ -521,7 +521,7 @@ struct xfrm_policy {
79492 struct timer_list timer;
79493
79494 struct flow_cache_object flo;
79495- atomic_t genid;
79496+ atomic_unchecked_t genid;
79497 u32 priority;
79498 u32 index;
79499 struct xfrm_mark mark;
79500diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
79501index 1a046b1..ee0bef0 100644
79502--- a/include/rdma/iw_cm.h
79503+++ b/include/rdma/iw_cm.h
79504@@ -122,7 +122,7 @@ struct iw_cm_verbs {
79505 int backlog);
79506
79507 int (*destroy_listen)(struct iw_cm_id *cm_id);
79508-};
79509+} __no_const;
79510
79511 /**
79512 * iw_create_cm_id - Create an IW CM identifier.
79513diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
79514index e1379b4..67eafbe 100644
79515--- a/include/scsi/libfc.h
79516+++ b/include/scsi/libfc.h
79517@@ -762,6 +762,7 @@ struct libfc_function_template {
79518 */
79519 void (*disc_stop_final) (struct fc_lport *);
79520 };
79521+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
79522
79523 /**
79524 * struct fc_disc - Discovery context
79525@@ -866,7 +867,7 @@ struct fc_lport {
79526 struct fc_vport *vport;
79527
79528 /* Operational Information */
79529- struct libfc_function_template tt;
79530+ libfc_function_template_no_const tt;
79531 u8 link_up;
79532 u8 qfull;
79533 enum fc_lport_state state;
79534diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
79535index cc64587..608f523 100644
79536--- a/include/scsi/scsi_device.h
79537+++ b/include/scsi/scsi_device.h
79538@@ -171,9 +171,9 @@ struct scsi_device {
79539 unsigned int max_device_blocked; /* what device_blocked counts down from */
79540 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
79541
79542- atomic_t iorequest_cnt;
79543- atomic_t iodone_cnt;
79544- atomic_t ioerr_cnt;
79545+ atomic_unchecked_t iorequest_cnt;
79546+ atomic_unchecked_t iodone_cnt;
79547+ atomic_unchecked_t ioerr_cnt;
79548
79549 struct device sdev_gendev,
79550 sdev_dev;
79551diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
79552index b797e8f..8e2c3aa 100644
79553--- a/include/scsi/scsi_transport_fc.h
79554+++ b/include/scsi/scsi_transport_fc.h
79555@@ -751,7 +751,8 @@ struct fc_function_template {
79556 unsigned long show_host_system_hostname:1;
79557
79558 unsigned long disable_target_scan:1;
79559-};
79560+} __do_const;
79561+typedef struct fc_function_template __no_const fc_function_template_no_const;
79562
79563
79564 /**
79565diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
79566index 9031a26..750d592 100644
79567--- a/include/sound/compress_driver.h
79568+++ b/include/sound/compress_driver.h
79569@@ -128,7 +128,7 @@ struct snd_compr_ops {
79570 struct snd_compr_caps *caps);
79571 int (*get_codec_caps) (struct snd_compr_stream *stream,
79572 struct snd_compr_codec_caps *codec);
79573-};
79574+} __no_const;
79575
79576 /**
79577 * struct snd_compr: Compressed device
79578diff --git a/include/sound/soc.h b/include/sound/soc.h
79579index 85c1522..f44bad1 100644
79580--- a/include/sound/soc.h
79581+++ b/include/sound/soc.h
79582@@ -781,7 +781,7 @@ struct snd_soc_codec_driver {
79583 /* probe ordering - for components with runtime dependencies */
79584 int probe_order;
79585 int remove_order;
79586-};
79587+} __do_const;
79588
79589 /* SoC platform interface */
79590 struct snd_soc_platform_driver {
79591@@ -827,7 +827,7 @@ struct snd_soc_platform_driver {
79592 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
79593 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
79594 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
79595-};
79596+} __do_const;
79597
79598 struct snd_soc_platform {
79599 const char *name;
79600diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
79601index 4ea4f98..a63629b 100644
79602--- a/include/target/target_core_base.h
79603+++ b/include/target/target_core_base.h
79604@@ -653,7 +653,7 @@ struct se_device {
79605 spinlock_t stats_lock;
79606 /* Active commands on this virtual SE device */
79607 atomic_t simple_cmds;
79608- atomic_t dev_ordered_id;
79609+ atomic_unchecked_t dev_ordered_id;
79610 atomic_t dev_ordered_sync;
79611 atomic_t dev_qf_count;
79612 int export_count;
79613diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
79614new file mode 100644
79615index 0000000..fb634b7
79616--- /dev/null
79617+++ b/include/trace/events/fs.h
79618@@ -0,0 +1,53 @@
79619+#undef TRACE_SYSTEM
79620+#define TRACE_SYSTEM fs
79621+
79622+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
79623+#define _TRACE_FS_H
79624+
79625+#include <linux/fs.h>
79626+#include <linux/tracepoint.h>
79627+
79628+TRACE_EVENT(do_sys_open,
79629+
79630+ TP_PROTO(const char *filename, int flags, int mode),
79631+
79632+ TP_ARGS(filename, flags, mode),
79633+
79634+ TP_STRUCT__entry(
79635+ __string( filename, filename )
79636+ __field( int, flags )
79637+ __field( int, mode )
79638+ ),
79639+
79640+ TP_fast_assign(
79641+ __assign_str(filename, filename);
79642+ __entry->flags = flags;
79643+ __entry->mode = mode;
79644+ ),
79645+
79646+ TP_printk("\"%s\" %x %o",
79647+ __get_str(filename), __entry->flags, __entry->mode)
79648+);
79649+
79650+TRACE_EVENT(open_exec,
79651+
79652+ TP_PROTO(const char *filename),
79653+
79654+ TP_ARGS(filename),
79655+
79656+ TP_STRUCT__entry(
79657+ __string( filename, filename )
79658+ ),
79659+
79660+ TP_fast_assign(
79661+ __assign_str(filename, filename);
79662+ ),
79663+
79664+ TP_printk("\"%s\"",
79665+ __get_str(filename))
79666+);
79667+
79668+#endif /* _TRACE_FS_H */
79669+
79670+/* This part must be outside protection */
79671+#include <trace/define_trace.h>
79672diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
79673index 1c09820..7f5ec79 100644
79674--- a/include/trace/events/irq.h
79675+++ b/include/trace/events/irq.h
79676@@ -36,7 +36,7 @@ struct softirq_action;
79677 */
79678 TRACE_EVENT(irq_handler_entry,
79679
79680- TP_PROTO(int irq, struct irqaction *action),
79681+ TP_PROTO(int irq, const struct irqaction *action),
79682
79683 TP_ARGS(irq, action),
79684
79685@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
79686 */
79687 TRACE_EVENT(irq_handler_exit,
79688
79689- TP_PROTO(int irq, struct irqaction *action, int ret),
79690+ TP_PROTO(int irq, const struct irqaction *action, int ret),
79691
79692 TP_ARGS(irq, action, ret),
79693
79694diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
79695index 7caf44c..23c6f27 100644
79696--- a/include/uapi/linux/a.out.h
79697+++ b/include/uapi/linux/a.out.h
79698@@ -39,6 +39,14 @@ enum machine_type {
79699 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
79700 };
79701
79702+/* Constants for the N_FLAGS field */
79703+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
79704+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
79705+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
79706+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
79707+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
79708+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
79709+
79710 #if !defined (N_MAGIC)
79711 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
79712 #endif
79713diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
79714index d876736..ccce5c0 100644
79715--- a/include/uapi/linux/byteorder/little_endian.h
79716+++ b/include/uapi/linux/byteorder/little_endian.h
79717@@ -42,51 +42,51 @@
79718
79719 static inline __le64 __cpu_to_le64p(const __u64 *p)
79720 {
79721- return (__force __le64)*p;
79722+ return (__force const __le64)*p;
79723 }
79724-static inline __u64 __le64_to_cpup(const __le64 *p)
79725+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
79726 {
79727- return (__force __u64)*p;
79728+ return (__force const __u64)*p;
79729 }
79730 static inline __le32 __cpu_to_le32p(const __u32 *p)
79731 {
79732- return (__force __le32)*p;
79733+ return (__force const __le32)*p;
79734 }
79735 static inline __u32 __le32_to_cpup(const __le32 *p)
79736 {
79737- return (__force __u32)*p;
79738+ return (__force const __u32)*p;
79739 }
79740 static inline __le16 __cpu_to_le16p(const __u16 *p)
79741 {
79742- return (__force __le16)*p;
79743+ return (__force const __le16)*p;
79744 }
79745 static inline __u16 __le16_to_cpup(const __le16 *p)
79746 {
79747- return (__force __u16)*p;
79748+ return (__force const __u16)*p;
79749 }
79750 static inline __be64 __cpu_to_be64p(const __u64 *p)
79751 {
79752- return (__force __be64)__swab64p(p);
79753+ return (__force const __be64)__swab64p(p);
79754 }
79755 static inline __u64 __be64_to_cpup(const __be64 *p)
79756 {
79757- return __swab64p((__u64 *)p);
79758+ return __swab64p((const __u64 *)p);
79759 }
79760 static inline __be32 __cpu_to_be32p(const __u32 *p)
79761 {
79762- return (__force __be32)__swab32p(p);
79763+ return (__force const __be32)__swab32p(p);
79764 }
79765-static inline __u32 __be32_to_cpup(const __be32 *p)
79766+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
79767 {
79768- return __swab32p((__u32 *)p);
79769+ return __swab32p((const __u32 *)p);
79770 }
79771 static inline __be16 __cpu_to_be16p(const __u16 *p)
79772 {
79773- return (__force __be16)__swab16p(p);
79774+ return (__force const __be16)__swab16p(p);
79775 }
79776 static inline __u16 __be16_to_cpup(const __be16 *p)
79777 {
79778- return __swab16p((__u16 *)p);
79779+ return __swab16p((const __u16 *)p);
79780 }
79781 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
79782 #define __le64_to_cpus(x) do { (void)(x); } while (0)
79783diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
79784index ef6103b..d4e65dd 100644
79785--- a/include/uapi/linux/elf.h
79786+++ b/include/uapi/linux/elf.h
79787@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
79788 #define PT_GNU_EH_FRAME 0x6474e550
79789
79790 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
79791+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
79792+
79793+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
79794+
79795+/* Constants for the e_flags field */
79796+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
79797+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
79798+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
79799+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
79800+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
79801+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
79802
79803 /*
79804 * Extended Numbering
79805@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
79806 #define DT_DEBUG 21
79807 #define DT_TEXTREL 22
79808 #define DT_JMPREL 23
79809+#define DT_FLAGS 30
79810+ #define DF_TEXTREL 0x00000004
79811 #define DT_ENCODING 32
79812 #define OLD_DT_LOOS 0x60000000
79813 #define DT_LOOS 0x6000000d
79814@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
79815 #define PF_W 0x2
79816 #define PF_X 0x1
79817
79818+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
79819+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
79820+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
79821+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
79822+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
79823+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
79824+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
79825+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
79826+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
79827+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
79828+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
79829+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
79830+
79831 typedef struct elf32_phdr{
79832 Elf32_Word p_type;
79833 Elf32_Off p_offset;
79834@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
79835 #define EI_OSABI 7
79836 #define EI_PAD 8
79837
79838+#define EI_PAX 14
79839+
79840 #define ELFMAG0 0x7f /* EI_MAG */
79841 #define ELFMAG1 'E'
79842 #define ELFMAG2 'L'
79843diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
79844index aa169c4..6a2771d 100644
79845--- a/include/uapi/linux/personality.h
79846+++ b/include/uapi/linux/personality.h
79847@@ -30,6 +30,7 @@ enum {
79848 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
79849 ADDR_NO_RANDOMIZE | \
79850 ADDR_COMPAT_LAYOUT | \
79851+ ADDR_LIMIT_3GB | \
79852 MMAP_PAGE_ZERO)
79853
79854 /*
79855diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
79856index 7530e74..e714828 100644
79857--- a/include/uapi/linux/screen_info.h
79858+++ b/include/uapi/linux/screen_info.h
79859@@ -43,7 +43,8 @@ struct screen_info {
79860 __u16 pages; /* 0x32 */
79861 __u16 vesa_attributes; /* 0x34 */
79862 __u32 capabilities; /* 0x36 */
79863- __u8 _reserved[6]; /* 0x3a */
79864+ __u16 vesapm_size; /* 0x3a */
79865+ __u8 _reserved[4]; /* 0x3c */
79866 } __attribute__((packed));
79867
79868 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
79869diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
79870index 0e011eb..82681b1 100644
79871--- a/include/uapi/linux/swab.h
79872+++ b/include/uapi/linux/swab.h
79873@@ -43,7 +43,7 @@
79874 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
79875 */
79876
79877-static inline __attribute_const__ __u16 __fswab16(__u16 val)
79878+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
79879 {
79880 #ifdef __HAVE_BUILTIN_BSWAP16__
79881 return __builtin_bswap16(val);
79882@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
79883 #endif
79884 }
79885
79886-static inline __attribute_const__ __u32 __fswab32(__u32 val)
79887+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
79888 {
79889 #ifdef __HAVE_BUILTIN_BSWAP32__
79890 return __builtin_bswap32(val);
79891@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
79892 #endif
79893 }
79894
79895-static inline __attribute_const__ __u64 __fswab64(__u64 val)
79896+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
79897 {
79898 #ifdef __HAVE_BUILTIN_BSWAP64__
79899 return __builtin_bswap64(val);
79900diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
79901index 6d67213..8dab561 100644
79902--- a/include/uapi/linux/sysctl.h
79903+++ b/include/uapi/linux/sysctl.h
79904@@ -155,7 +155,11 @@ enum
79905 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
79906 };
79907
79908-
79909+#ifdef CONFIG_PAX_SOFTMODE
79910+enum {
79911+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
79912+};
79913+#endif
79914
79915 /* CTL_VM names: */
79916 enum
79917diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
79918index e4629b9..6958086 100644
79919--- a/include/uapi/linux/xattr.h
79920+++ b/include/uapi/linux/xattr.h
79921@@ -63,5 +63,9 @@
79922 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
79923 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
79924
79925+/* User namespace */
79926+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
79927+#define XATTR_PAX_FLAGS_SUFFIX "flags"
79928+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
79929
79930 #endif /* _UAPI_LINUX_XATTR_H */
79931diff --git a/include/video/udlfb.h b/include/video/udlfb.h
79932index f9466fa..f4e2b81 100644
79933--- a/include/video/udlfb.h
79934+++ b/include/video/udlfb.h
79935@@ -53,10 +53,10 @@ struct dlfb_data {
79936 u32 pseudo_palette[256];
79937 int blank_mode; /*one of FB_BLANK_ */
79938 /* blit-only rendering path metrics, exposed through sysfs */
79939- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
79940- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
79941- atomic_t bytes_sent; /* to usb, after compression including overhead */
79942- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
79943+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
79944+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
79945+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
79946+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
79947 };
79948
79949 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
79950diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
79951index 1a91850..28573f8 100644
79952--- a/include/video/uvesafb.h
79953+++ b/include/video/uvesafb.h
79954@@ -122,6 +122,7 @@ struct uvesafb_par {
79955 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
79956 u8 pmi_setpal; /* PMI for palette changes */
79957 u16 *pmi_base; /* protected mode interface location */
79958+ u8 *pmi_code; /* protected mode code location */
79959 void *pmi_start;
79960 void *pmi_pal;
79961 u8 *vbe_state_orig; /*
79962diff --git a/init/Kconfig b/init/Kconfig
79963index 2d9b831..ae4c8ac 100644
79964--- a/init/Kconfig
79965+++ b/init/Kconfig
79966@@ -1029,6 +1029,7 @@ endif # CGROUPS
79967
79968 config CHECKPOINT_RESTORE
79969 bool "Checkpoint/restore support" if EXPERT
79970+ depends on !GRKERNSEC
79971 default n
79972 help
79973 Enables additional kernel features in a sake of checkpoint/restore.
79974@@ -1516,7 +1517,7 @@ config SLUB_DEBUG
79975
79976 config COMPAT_BRK
79977 bool "Disable heap randomization"
79978- default y
79979+ default n
79980 help
79981 Randomizing heap placement makes heap exploits harder, but it
79982 also breaks ancient binaries (including anything libc5 based).
79983@@ -1779,7 +1780,7 @@ config INIT_ALL_POSSIBLE
79984 config STOP_MACHINE
79985 bool
79986 default y
79987- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
79988+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
79989 help
79990 Need stop_machine() primitive.
79991
79992diff --git a/init/Makefile b/init/Makefile
79993index 7bc47ee..6da2dc7 100644
79994--- a/init/Makefile
79995+++ b/init/Makefile
79996@@ -2,6 +2,9 @@
79997 # Makefile for the linux kernel.
79998 #
79999
80000+ccflags-y := $(GCC_PLUGINS_CFLAGS)
80001+asflags-y := $(GCC_PLUGINS_AFLAGS)
80002+
80003 obj-y := main.o version.o mounts.o
80004 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
80005 obj-y += noinitramfs.o
80006diff --git a/init/do_mounts.c b/init/do_mounts.c
80007index a2b49f2..03a0e17c 100644
80008--- a/init/do_mounts.c
80009+++ b/init/do_mounts.c
80010@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
80011 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
80012 {
80013 struct super_block *s;
80014- int err = sys_mount(name, "/root", fs, flags, data);
80015+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
80016 if (err)
80017 return err;
80018
80019- sys_chdir("/root");
80020+ sys_chdir((const char __force_user *)"/root");
80021 s = current->fs->pwd.dentry->d_sb;
80022 ROOT_DEV = s->s_dev;
80023 printk(KERN_INFO
80024@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
80025 va_start(args, fmt);
80026 vsprintf(buf, fmt, args);
80027 va_end(args);
80028- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
80029+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
80030 if (fd >= 0) {
80031 sys_ioctl(fd, FDEJECT, 0);
80032 sys_close(fd);
80033 }
80034 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
80035- fd = sys_open("/dev/console", O_RDWR, 0);
80036+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
80037 if (fd >= 0) {
80038 sys_ioctl(fd, TCGETS, (long)&termios);
80039 termios.c_lflag &= ~ICANON;
80040 sys_ioctl(fd, TCSETSF, (long)&termios);
80041- sys_read(fd, &c, 1);
80042+ sys_read(fd, (char __user *)&c, 1);
80043 termios.c_lflag |= ICANON;
80044 sys_ioctl(fd, TCSETSF, (long)&termios);
80045 sys_close(fd);
80046@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
80047 mount_root();
80048 out:
80049 devtmpfs_mount("dev");
80050- sys_mount(".", "/", NULL, MS_MOVE, NULL);
80051- sys_chroot(".");
80052+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
80053+ sys_chroot((const char __force_user *)".");
80054 }
80055diff --git a/init/do_mounts.h b/init/do_mounts.h
80056index f5b978a..69dbfe8 100644
80057--- a/init/do_mounts.h
80058+++ b/init/do_mounts.h
80059@@ -15,15 +15,15 @@ extern int root_mountflags;
80060
80061 static inline int create_dev(char *name, dev_t dev)
80062 {
80063- sys_unlink(name);
80064- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
80065+ sys_unlink((char __force_user *)name);
80066+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
80067 }
80068
80069 #if BITS_PER_LONG == 32
80070 static inline u32 bstat(char *name)
80071 {
80072 struct stat64 stat;
80073- if (sys_stat64(name, &stat) != 0)
80074+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
80075 return 0;
80076 if (!S_ISBLK(stat.st_mode))
80077 return 0;
80078@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
80079 static inline u32 bstat(char *name)
80080 {
80081 struct stat stat;
80082- if (sys_newstat(name, &stat) != 0)
80083+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
80084 return 0;
80085 if (!S_ISBLK(stat.st_mode))
80086 return 0;
80087diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
80088index 3e0878e..8a9d7a0 100644
80089--- a/init/do_mounts_initrd.c
80090+++ b/init/do_mounts_initrd.c
80091@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
80092 {
80093 sys_unshare(CLONE_FS | CLONE_FILES);
80094 /* stdin/stdout/stderr for /linuxrc */
80095- sys_open("/dev/console", O_RDWR, 0);
80096+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
80097 sys_dup(0);
80098 sys_dup(0);
80099 /* move initrd over / and chdir/chroot in initrd root */
80100- sys_chdir("/root");
80101- sys_mount(".", "/", NULL, MS_MOVE, NULL);
80102- sys_chroot(".");
80103+ sys_chdir((const char __force_user *)"/root");
80104+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
80105+ sys_chroot((const char __force_user *)".");
80106 sys_setsid();
80107 return 0;
80108 }
80109@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
80110 create_dev("/dev/root.old", Root_RAM0);
80111 /* mount initrd on rootfs' /root */
80112 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
80113- sys_mkdir("/old", 0700);
80114- sys_chdir("/old");
80115+ sys_mkdir((const char __force_user *)"/old", 0700);
80116+ sys_chdir((const char __force_user *)"/old");
80117
80118 /* try loading default modules from initrd */
80119 load_default_modules();
80120@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
80121 current->flags &= ~PF_FREEZER_SKIP;
80122
80123 /* move initrd to rootfs' /old */
80124- sys_mount("..", ".", NULL, MS_MOVE, NULL);
80125+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
80126 /* switch root and cwd back to / of rootfs */
80127- sys_chroot("..");
80128+ sys_chroot((const char __force_user *)"..");
80129
80130 if (new_decode_dev(real_root_dev) == Root_RAM0) {
80131- sys_chdir("/old");
80132+ sys_chdir((const char __force_user *)"/old");
80133 return;
80134 }
80135
80136- sys_chdir("/");
80137+ sys_chdir((const char __force_user *)"/");
80138 ROOT_DEV = new_decode_dev(real_root_dev);
80139 mount_root();
80140
80141 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
80142- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
80143+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
80144 if (!error)
80145 printk("okay\n");
80146 else {
80147- int fd = sys_open("/dev/root.old", O_RDWR, 0);
80148+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
80149 if (error == -ENOENT)
80150 printk("/initrd does not exist. Ignored.\n");
80151 else
80152 printk("failed\n");
80153 printk(KERN_NOTICE "Unmounting old root\n");
80154- sys_umount("/old", MNT_DETACH);
80155+ sys_umount((char __force_user *)"/old", MNT_DETACH);
80156 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
80157 if (fd < 0) {
80158 error = fd;
80159@@ -127,11 +127,11 @@ int __init initrd_load(void)
80160 * mounted in the normal path.
80161 */
80162 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
80163- sys_unlink("/initrd.image");
80164+ sys_unlink((const char __force_user *)"/initrd.image");
80165 handle_initrd();
80166 return 1;
80167 }
80168 }
80169- sys_unlink("/initrd.image");
80170+ sys_unlink((const char __force_user *)"/initrd.image");
80171 return 0;
80172 }
80173diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
80174index 8cb6db5..d729f50 100644
80175--- a/init/do_mounts_md.c
80176+++ b/init/do_mounts_md.c
80177@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
80178 partitioned ? "_d" : "", minor,
80179 md_setup_args[ent].device_names);
80180
80181- fd = sys_open(name, 0, 0);
80182+ fd = sys_open((char __force_user *)name, 0, 0);
80183 if (fd < 0) {
80184 printk(KERN_ERR "md: open failed - cannot start "
80185 "array %s\n", name);
80186@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
80187 * array without it
80188 */
80189 sys_close(fd);
80190- fd = sys_open(name, 0, 0);
80191+ fd = sys_open((char __force_user *)name, 0, 0);
80192 sys_ioctl(fd, BLKRRPART, 0);
80193 }
80194 sys_close(fd);
80195@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
80196
80197 wait_for_device_probe();
80198
80199- fd = sys_open("/dev/md0", 0, 0);
80200+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
80201 if (fd >= 0) {
80202 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
80203 sys_close(fd);
80204diff --git a/init/init_task.c b/init/init_task.c
80205index ba0a7f36..2bcf1d5 100644
80206--- a/init/init_task.c
80207+++ b/init/init_task.c
80208@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
80209 * Initial thread structure. Alignment of this is handled by a special
80210 * linker map entry.
80211 */
80212+#ifdef CONFIG_X86
80213+union thread_union init_thread_union __init_task_data;
80214+#else
80215 union thread_union init_thread_union __init_task_data =
80216 { INIT_THREAD_INFO(init_task) };
80217+#endif
80218diff --git a/init/initramfs.c b/init/initramfs.c
80219index a67ef9d..2d17ed9 100644
80220--- a/init/initramfs.c
80221+++ b/init/initramfs.c
80222@@ -84,7 +84,7 @@ static void __init free_hash(void)
80223 }
80224 }
80225
80226-static long __init do_utime(char *filename, time_t mtime)
80227+static long __init do_utime(char __force_user *filename, time_t mtime)
80228 {
80229 struct timespec t[2];
80230
80231@@ -119,7 +119,7 @@ static void __init dir_utime(void)
80232 struct dir_entry *de, *tmp;
80233 list_for_each_entry_safe(de, tmp, &dir_list, list) {
80234 list_del(&de->list);
80235- do_utime(de->name, de->mtime);
80236+ do_utime((char __force_user *)de->name, de->mtime);
80237 kfree(de->name);
80238 kfree(de);
80239 }
80240@@ -281,7 +281,7 @@ static int __init maybe_link(void)
80241 if (nlink >= 2) {
80242 char *old = find_link(major, minor, ino, mode, collected);
80243 if (old)
80244- return (sys_link(old, collected) < 0) ? -1 : 1;
80245+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
80246 }
80247 return 0;
80248 }
80249@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
80250 {
80251 struct stat st;
80252
80253- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
80254+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
80255 if (S_ISDIR(st.st_mode))
80256- sys_rmdir(path);
80257+ sys_rmdir((char __force_user *)path);
80258 else
80259- sys_unlink(path);
80260+ sys_unlink((char __force_user *)path);
80261 }
80262 }
80263
80264@@ -315,7 +315,7 @@ static int __init do_name(void)
80265 int openflags = O_WRONLY|O_CREAT;
80266 if (ml != 1)
80267 openflags |= O_TRUNC;
80268- wfd = sys_open(collected, openflags, mode);
80269+ wfd = sys_open((char __force_user *)collected, openflags, mode);
80270
80271 if (wfd >= 0) {
80272 sys_fchown(wfd, uid, gid);
80273@@ -327,17 +327,17 @@ static int __init do_name(void)
80274 }
80275 }
80276 } else if (S_ISDIR(mode)) {
80277- sys_mkdir(collected, mode);
80278- sys_chown(collected, uid, gid);
80279- sys_chmod(collected, mode);
80280+ sys_mkdir((char __force_user *)collected, mode);
80281+ sys_chown((char __force_user *)collected, uid, gid);
80282+ sys_chmod((char __force_user *)collected, mode);
80283 dir_add(collected, mtime);
80284 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
80285 S_ISFIFO(mode) || S_ISSOCK(mode)) {
80286 if (maybe_link() == 0) {
80287- sys_mknod(collected, mode, rdev);
80288- sys_chown(collected, uid, gid);
80289- sys_chmod(collected, mode);
80290- do_utime(collected, mtime);
80291+ sys_mknod((char __force_user *)collected, mode, rdev);
80292+ sys_chown((char __force_user *)collected, uid, gid);
80293+ sys_chmod((char __force_user *)collected, mode);
80294+ do_utime((char __force_user *)collected, mtime);
80295 }
80296 }
80297 return 0;
80298@@ -346,15 +346,15 @@ static int __init do_name(void)
80299 static int __init do_copy(void)
80300 {
80301 if (count >= body_len) {
80302- sys_write(wfd, victim, body_len);
80303+ sys_write(wfd, (char __force_user *)victim, body_len);
80304 sys_close(wfd);
80305- do_utime(vcollected, mtime);
80306+ do_utime((char __force_user *)vcollected, mtime);
80307 kfree(vcollected);
80308 eat(body_len);
80309 state = SkipIt;
80310 return 0;
80311 } else {
80312- sys_write(wfd, victim, count);
80313+ sys_write(wfd, (char __force_user *)victim, count);
80314 body_len -= count;
80315 eat(count);
80316 return 1;
80317@@ -365,9 +365,9 @@ static int __init do_symlink(void)
80318 {
80319 collected[N_ALIGN(name_len) + body_len] = '\0';
80320 clean_path(collected, 0);
80321- sys_symlink(collected + N_ALIGN(name_len), collected);
80322- sys_lchown(collected, uid, gid);
80323- do_utime(collected, mtime);
80324+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
80325+ sys_lchown((char __force_user *)collected, uid, gid);
80326+ do_utime((char __force_user *)collected, mtime);
80327 state = SkipIt;
80328 next_state = Reset;
80329 return 0;
80330@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
80331 {
80332 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
80333 if (err)
80334- panic(err); /* Failed to decompress INTERNAL initramfs */
80335+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
80336 if (initrd_start) {
80337 #ifdef CONFIG_BLK_DEV_RAM
80338 int fd;
80339diff --git a/init/main.c b/init/main.c
80340index 9484f4b..0eac7c3 100644
80341--- a/init/main.c
80342+++ b/init/main.c
80343@@ -100,6 +100,8 @@ static inline void mark_rodata_ro(void) { }
80344 extern void tc_init(void);
80345 #endif
80346
80347+extern void grsecurity_init(void);
80348+
80349 /*
80350 * Debug helper: via this flag we know that we are in 'early bootup code'
80351 * where only the boot processor is running with IRQ disabled. This means
80352@@ -153,6 +155,74 @@ static int __init set_reset_devices(char *str)
80353
80354 __setup("reset_devices", set_reset_devices);
80355
80356+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80357+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
80358+static int __init setup_grsec_proc_gid(char *str)
80359+{
80360+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
80361+ return 1;
80362+}
80363+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
80364+#endif
80365+
80366+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
80367+unsigned long pax_user_shadow_base __read_only;
80368+EXPORT_SYMBOL(pax_user_shadow_base);
80369+extern char pax_enter_kernel_user[];
80370+extern char pax_exit_kernel_user[];
80371+#endif
80372+
80373+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
80374+static int __init setup_pax_nouderef(char *str)
80375+{
80376+#ifdef CONFIG_X86_32
80377+ unsigned int cpu;
80378+ struct desc_struct *gdt;
80379+
80380+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
80381+ gdt = get_cpu_gdt_table(cpu);
80382+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
80383+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
80384+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
80385+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
80386+ }
80387+ loadsegment(ds, __KERNEL_DS);
80388+ loadsegment(es, __KERNEL_DS);
80389+ loadsegment(ss, __KERNEL_DS);
80390+#else
80391+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
80392+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
80393+ clone_pgd_mask = ~(pgdval_t)0UL;
80394+ pax_user_shadow_base = 0UL;
80395+ setup_clear_cpu_cap(X86_FEATURE_PCID);
80396+#endif
80397+
80398+ return 0;
80399+}
80400+early_param("pax_nouderef", setup_pax_nouderef);
80401+
80402+#ifdef CONFIG_X86_64
80403+static int __init setup_pax_weakuderef(char *str)
80404+{
80405+ if (clone_pgd_mask != ~(pgdval_t)0UL)
80406+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
80407+ return 1;
80408+}
80409+__setup("pax_weakuderef", setup_pax_weakuderef);
80410+#endif
80411+#endif
80412+
80413+#ifdef CONFIG_PAX_SOFTMODE
80414+int pax_softmode;
80415+
80416+static int __init setup_pax_softmode(char *str)
80417+{
80418+ get_option(&str, &pax_softmode);
80419+ return 1;
80420+}
80421+__setup("pax_softmode=", setup_pax_softmode);
80422+#endif
80423+
80424 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
80425 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
80426 static const char *panic_later, *panic_param;
80427@@ -655,8 +725,6 @@ static void __init do_ctors(void)
80428 bool initcall_debug;
80429 core_param(initcall_debug, initcall_debug, bool, 0644);
80430
80431-static char msgbuf[64];
80432-
80433 static int __init_or_module do_one_initcall_debug(initcall_t fn)
80434 {
80435 ktime_t calltime, delta, rettime;
80436@@ -679,23 +747,22 @@ int __init_or_module do_one_initcall(initcall_t fn)
80437 {
80438 int count = preempt_count();
80439 int ret;
80440+ const char *msg1 = "", *msg2 = "";
80441
80442 if (initcall_debug)
80443 ret = do_one_initcall_debug(fn);
80444 else
80445 ret = fn();
80446
80447- msgbuf[0] = 0;
80448-
80449 if (preempt_count() != count) {
80450- sprintf(msgbuf, "preemption imbalance ");
80451+ msg1 = " preemption imbalance";
80452 preempt_count() = count;
80453 }
80454 if (irqs_disabled()) {
80455- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
80456+ msg2 = " disabled interrupts";
80457 local_irq_enable();
80458 }
80459- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
80460+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
80461
80462 return ret;
80463 }
80464@@ -748,8 +815,14 @@ static void __init do_initcall_level(int level)
80465 level, level,
80466 &repair_env_string);
80467
80468- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
80469+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
80470 do_one_initcall(*fn);
80471+
80472+#ifdef LATENT_ENTROPY_PLUGIN
80473+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
80474+#endif
80475+
80476+ }
80477 }
80478
80479 static void __init do_initcalls(void)
80480@@ -783,8 +856,14 @@ static void __init do_pre_smp_initcalls(void)
80481 {
80482 initcall_t *fn;
80483
80484- for (fn = __initcall_start; fn < __initcall0_start; fn++)
80485+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
80486 do_one_initcall(*fn);
80487+
80488+#ifdef LATENT_ENTROPY_PLUGIN
80489+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
80490+#endif
80491+
80492+ }
80493 }
80494
80495 /*
80496@@ -802,8 +881,8 @@ static int run_init_process(const char *init_filename)
80497 {
80498 argv_init[0] = init_filename;
80499 return do_execve(init_filename,
80500- (const char __user *const __user *)argv_init,
80501- (const char __user *const __user *)envp_init);
80502+ (const char __user *const __force_user *)argv_init,
80503+ (const char __user *const __force_user *)envp_init);
80504 }
80505
80506 static noinline void __init kernel_init_freeable(void);
80507@@ -880,7 +959,7 @@ static noinline void __init kernel_init_freeable(void)
80508 do_basic_setup();
80509
80510 /* Open the /dev/console on the rootfs, this should never fail */
80511- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
80512+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
80513 pr_err("Warning: unable to open an initial console.\n");
80514
80515 (void) sys_dup(0);
80516@@ -893,11 +972,13 @@ static noinline void __init kernel_init_freeable(void)
80517 if (!ramdisk_execute_command)
80518 ramdisk_execute_command = "/init";
80519
80520- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
80521+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
80522 ramdisk_execute_command = NULL;
80523 prepare_namespace();
80524 }
80525
80526+ grsecurity_init();
80527+
80528 /*
80529 * Ok, we have completed the initial bootup, and
80530 * we're essentially up and running. Get rid of the
80531diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
80532index 130dfec..cc88451 100644
80533--- a/ipc/ipc_sysctl.c
80534+++ b/ipc/ipc_sysctl.c
80535@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
80536 static int proc_ipc_dointvec(ctl_table *table, int write,
80537 void __user *buffer, size_t *lenp, loff_t *ppos)
80538 {
80539- struct ctl_table ipc_table;
80540+ ctl_table_no_const ipc_table;
80541
80542 memcpy(&ipc_table, table, sizeof(ipc_table));
80543 ipc_table.data = get_ipc(table);
80544@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
80545 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
80546 void __user *buffer, size_t *lenp, loff_t *ppos)
80547 {
80548- struct ctl_table ipc_table;
80549+ ctl_table_no_const ipc_table;
80550
80551 memcpy(&ipc_table, table, sizeof(ipc_table));
80552 ipc_table.data = get_ipc(table);
80553@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
80554 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
80555 void __user *buffer, size_t *lenp, loff_t *ppos)
80556 {
80557- struct ctl_table ipc_table;
80558+ ctl_table_no_const ipc_table;
80559 size_t lenp_bef = *lenp;
80560 int rc;
80561
80562@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
80563 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
80564 void __user *buffer, size_t *lenp, loff_t *ppos)
80565 {
80566- struct ctl_table ipc_table;
80567+ ctl_table_no_const ipc_table;
80568 memcpy(&ipc_table, table, sizeof(ipc_table));
80569 ipc_table.data = get_ipc(table);
80570
80571@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
80572 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
80573 void __user *buffer, size_t *lenp, loff_t *ppos)
80574 {
80575- struct ctl_table ipc_table;
80576+ ctl_table_no_const ipc_table;
80577 size_t lenp_bef = *lenp;
80578 int oldval;
80579 int rc;
80580diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
80581index 383d638..943fdbb 100644
80582--- a/ipc/mq_sysctl.c
80583+++ b/ipc/mq_sysctl.c
80584@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
80585 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
80586 void __user *buffer, size_t *lenp, loff_t *ppos)
80587 {
80588- struct ctl_table mq_table;
80589+ ctl_table_no_const mq_table;
80590 memcpy(&mq_table, table, sizeof(mq_table));
80591 mq_table.data = get_mq(table);
80592
80593diff --git a/ipc/mqueue.c b/ipc/mqueue.c
80594index e4e47f6..a85e0ad 100644
80595--- a/ipc/mqueue.c
80596+++ b/ipc/mqueue.c
80597@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
80598 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
80599 info->attr.mq_msgsize);
80600
80601+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
80602 spin_lock(&mq_lock);
80603 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
80604 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
80605diff --git a/ipc/msg.c b/ipc/msg.c
80606index f8fbe2c..074649e 100644
80607--- a/ipc/msg.c
80608+++ b/ipc/msg.c
80609@@ -296,18 +296,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
80610 return security_msg_queue_associate(msq, msgflg);
80611 }
80612
80613+static struct ipc_ops msg_ops = {
80614+ .getnew = newque,
80615+ .associate = msg_security,
80616+ .more_checks = NULL
80617+};
80618+
80619 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
80620 {
80621 struct ipc_namespace *ns;
80622- struct ipc_ops msg_ops;
80623 struct ipc_params msg_params;
80624
80625 ns = current->nsproxy->ipc_ns;
80626
80627- msg_ops.getnew = newque;
80628- msg_ops.associate = msg_security;
80629- msg_ops.more_checks = NULL;
80630-
80631 msg_params.key = key;
80632 msg_params.flg = msgflg;
80633
80634diff --git a/ipc/sem.c b/ipc/sem.c
80635index 70480a3..f4e8262 100644
80636--- a/ipc/sem.c
80637+++ b/ipc/sem.c
80638@@ -460,10 +460,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
80639 return 0;
80640 }
80641
80642+static struct ipc_ops sem_ops = {
80643+ .getnew = newary,
80644+ .associate = sem_security,
80645+ .more_checks = sem_more_checks
80646+};
80647+
80648 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
80649 {
80650 struct ipc_namespace *ns;
80651- struct ipc_ops sem_ops;
80652 struct ipc_params sem_params;
80653
80654 ns = current->nsproxy->ipc_ns;
80655@@ -471,10 +476,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
80656 if (nsems < 0 || nsems > ns->sc_semmsl)
80657 return -EINVAL;
80658
80659- sem_ops.getnew = newary;
80660- sem_ops.associate = sem_security;
80661- sem_ops.more_checks = sem_more_checks;
80662-
80663 sem_params.key = key;
80664 sem_params.flg = semflg;
80665 sem_params.u.nsems = nsems;
80666diff --git a/ipc/shm.c b/ipc/shm.c
80667index 7e199fa..180a1ca 100644
80668--- a/ipc/shm.c
80669+++ b/ipc/shm.c
80670@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
80671 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
80672 #endif
80673
80674+#ifdef CONFIG_GRKERNSEC
80675+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
80676+ const time_t shm_createtime, const kuid_t cuid,
80677+ const int shmid);
80678+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
80679+ const time_t shm_createtime);
80680+#endif
80681+
80682 void shm_init_ns(struct ipc_namespace *ns)
80683 {
80684 ns->shm_ctlmax = SHMMAX;
80685@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
80686 shp->shm_lprid = 0;
80687 shp->shm_atim = shp->shm_dtim = 0;
80688 shp->shm_ctim = get_seconds();
80689+#ifdef CONFIG_GRKERNSEC
80690+ {
80691+ struct timespec timeval;
80692+ do_posix_clock_monotonic_gettime(&timeval);
80693+
80694+ shp->shm_createtime = timeval.tv_sec;
80695+ }
80696+#endif
80697 shp->shm_segsz = size;
80698 shp->shm_nattch = 0;
80699 shp->shm_file = file;
80700@@ -582,18 +598,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
80701 return 0;
80702 }
80703
80704+static struct ipc_ops shm_ops = {
80705+ .getnew = newseg,
80706+ .associate = shm_security,
80707+ .more_checks = shm_more_checks
80708+};
80709+
80710 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
80711 {
80712 struct ipc_namespace *ns;
80713- struct ipc_ops shm_ops;
80714 struct ipc_params shm_params;
80715
80716 ns = current->nsproxy->ipc_ns;
80717
80718- shm_ops.getnew = newseg;
80719- shm_ops.associate = shm_security;
80720- shm_ops.more_checks = shm_more_checks;
80721-
80722 shm_params.key = key;
80723 shm_params.flg = shmflg;
80724 shm_params.u.size = size;
80725@@ -1014,6 +1031,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
80726 f_mode = FMODE_READ | FMODE_WRITE;
80727 }
80728 if (shmflg & SHM_EXEC) {
80729+
80730+#ifdef CONFIG_PAX_MPROTECT
80731+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
80732+ goto out;
80733+#endif
80734+
80735 prot |= PROT_EXEC;
80736 acc_mode |= S_IXUGO;
80737 }
80738@@ -1037,9 +1060,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
80739 if (err)
80740 goto out_unlock;
80741
80742+#ifdef CONFIG_GRKERNSEC
80743+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
80744+ shp->shm_perm.cuid, shmid) ||
80745+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
80746+ err = -EACCES;
80747+ goto out_unlock;
80748+ }
80749+#endif
80750+
80751 path = shp->shm_file->f_path;
80752 path_get(&path);
80753 shp->shm_nattch++;
80754+#ifdef CONFIG_GRKERNSEC
80755+ shp->shm_lapid = current->pid;
80756+#endif
80757 size = i_size_read(path.dentry->d_inode);
80758 shm_unlock(shp);
80759
80760diff --git a/kernel/acct.c b/kernel/acct.c
80761index 8d6e145..33e0b1e 100644
80762--- a/kernel/acct.c
80763+++ b/kernel/acct.c
80764@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
80765 */
80766 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
80767 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
80768- file->f_op->write(file, (char *)&ac,
80769+ file->f_op->write(file, (char __force_user *)&ac,
80770 sizeof(acct_t), &file->f_pos);
80771 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
80772 set_fs(fs);
80773diff --git a/kernel/audit.c b/kernel/audit.c
80774index 91e53d0..d9e3ec4 100644
80775--- a/kernel/audit.c
80776+++ b/kernel/audit.c
80777@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
80778 3) suppressed due to audit_rate_limit
80779 4) suppressed due to audit_backlog_limit
80780 */
80781-static atomic_t audit_lost = ATOMIC_INIT(0);
80782+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
80783
80784 /* The netlink socket. */
80785 static struct sock *audit_sock;
80786@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
80787 unsigned long now;
80788 int print;
80789
80790- atomic_inc(&audit_lost);
80791+ atomic_inc_unchecked(&audit_lost);
80792
80793 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
80794
80795@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
80796 printk(KERN_WARNING
80797 "audit: audit_lost=%d audit_rate_limit=%d "
80798 "audit_backlog_limit=%d\n",
80799- atomic_read(&audit_lost),
80800+ atomic_read_unchecked(&audit_lost),
80801 audit_rate_limit,
80802 audit_backlog_limit);
80803 audit_panic(message);
80804@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80805 status_set.pid = audit_pid;
80806 status_set.rate_limit = audit_rate_limit;
80807 status_set.backlog_limit = audit_backlog_limit;
80808- status_set.lost = atomic_read(&audit_lost);
80809+ status_set.lost = atomic_read_unchecked(&audit_lost);
80810 status_set.backlog = skb_queue_len(&audit_skb_queue);
80811 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
80812 &status_set, sizeof(status_set));
80813diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
80814index 6bd4a90..0ee9eff 100644
80815--- a/kernel/auditfilter.c
80816+++ b/kernel/auditfilter.c
80817@@ -423,7 +423,7 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
80818 f->lsm_rule = NULL;
80819
80820 /* Support legacy tests for a valid loginuid */
80821- if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295)) {
80822+ if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295U)) {
80823 f->type = AUDIT_LOGINUID_SET;
80824 f->val = 0;
80825 }
80826diff --git a/kernel/auditsc.c b/kernel/auditsc.c
80827index 3c8a601..3a416f6 100644
80828--- a/kernel/auditsc.c
80829+++ b/kernel/auditsc.c
80830@@ -1956,7 +1956,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
80831 }
80832
80833 /* global counter which is incremented every time something logs in */
80834-static atomic_t session_id = ATOMIC_INIT(0);
80835+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
80836
80837 /**
80838 * audit_set_loginuid - set current task's audit_context loginuid
80839@@ -1980,7 +1980,7 @@ int audit_set_loginuid(kuid_t loginuid)
80840 return -EPERM;
80841 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
80842
80843- sessionid = atomic_inc_return(&session_id);
80844+ sessionid = atomic_inc_return_unchecked(&session_id);
80845 if (context && context->in_syscall) {
80846 struct audit_buffer *ab;
80847
80848diff --git a/kernel/capability.c b/kernel/capability.c
80849index f6c2ce5..982c0f9 100644
80850--- a/kernel/capability.c
80851+++ b/kernel/capability.c
80852@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
80853 * before modification is attempted and the application
80854 * fails.
80855 */
80856+ if (tocopy > ARRAY_SIZE(kdata))
80857+ return -EFAULT;
80858+
80859 if (copy_to_user(dataptr, kdata, tocopy
80860 * sizeof(struct __user_cap_data_struct))) {
80861 return -EFAULT;
80862@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
80863 int ret;
80864
80865 rcu_read_lock();
80866- ret = security_capable(__task_cred(t), ns, cap);
80867+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
80868+ gr_task_is_capable(t, __task_cred(t), cap);
80869 rcu_read_unlock();
80870
80871- return (ret == 0);
80872+ return ret;
80873 }
80874
80875 /**
80876@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
80877 int ret;
80878
80879 rcu_read_lock();
80880- ret = security_capable_noaudit(__task_cred(t), ns, cap);
80881+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
80882 rcu_read_unlock();
80883
80884- return (ret == 0);
80885+ return ret;
80886 }
80887
80888 /**
80889@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
80890 BUG();
80891 }
80892
80893- if (security_capable(current_cred(), ns, cap) == 0) {
80894+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
80895 current->flags |= PF_SUPERPRIV;
80896 return true;
80897 }
80898@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
80899 }
80900 EXPORT_SYMBOL(ns_capable);
80901
80902+bool ns_capable_nolog(struct user_namespace *ns, int cap)
80903+{
80904+ if (unlikely(!cap_valid(cap))) {
80905+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
80906+ BUG();
80907+ }
80908+
80909+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
80910+ current->flags |= PF_SUPERPRIV;
80911+ return true;
80912+ }
80913+ return false;
80914+}
80915+EXPORT_SYMBOL(ns_capable_nolog);
80916+
80917 /**
80918 * file_ns_capable - Determine if the file's opener had a capability in effect
80919 * @file: The file we want to check
80920@@ -432,6 +451,12 @@ bool capable(int cap)
80921 }
80922 EXPORT_SYMBOL(capable);
80923
80924+bool capable_nolog(int cap)
80925+{
80926+ return ns_capable_nolog(&init_user_ns, cap);
80927+}
80928+EXPORT_SYMBOL(capable_nolog);
80929+
80930 /**
80931 * nsown_capable - Check superior capability to one's own user_ns
80932 * @cap: The capability in question
80933@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
80934
80935 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
80936 }
80937+
80938+bool inode_capable_nolog(const struct inode *inode, int cap)
80939+{
80940+ struct user_namespace *ns = current_user_ns();
80941+
80942+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
80943+}
80944diff --git a/kernel/cgroup.c b/kernel/cgroup.c
80945index 2e9b387..61817b1 100644
80946--- a/kernel/cgroup.c
80947+++ b/kernel/cgroup.c
80948@@ -5398,7 +5398,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
80949 struct css_set *cg = link->cg;
80950 struct task_struct *task;
80951 int count = 0;
80952- seq_printf(seq, "css_set %p\n", cg);
80953+ seq_printf(seq, "css_set %pK\n", cg);
80954 list_for_each_entry(task, &cg->tasks, cg_list) {
80955 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
80956 seq_puts(seq, " ...\n");
80957diff --git a/kernel/compat.c b/kernel/compat.c
80958index 0a09e48..f44f3f0 100644
80959--- a/kernel/compat.c
80960+++ b/kernel/compat.c
80961@@ -13,6 +13,7 @@
80962
80963 #include <linux/linkage.h>
80964 #include <linux/compat.h>
80965+#include <linux/module.h>
80966 #include <linux/errno.h>
80967 #include <linux/time.h>
80968 #include <linux/signal.h>
80969@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
80970 mm_segment_t oldfs;
80971 long ret;
80972
80973- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
80974+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
80975 oldfs = get_fs();
80976 set_fs(KERNEL_DS);
80977 ret = hrtimer_nanosleep_restart(restart);
80978@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
80979 oldfs = get_fs();
80980 set_fs(KERNEL_DS);
80981 ret = hrtimer_nanosleep(&tu,
80982- rmtp ? (struct timespec __user *)&rmt : NULL,
80983+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
80984 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
80985 set_fs(oldfs);
80986
80987@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
80988 mm_segment_t old_fs = get_fs();
80989
80990 set_fs(KERNEL_DS);
80991- ret = sys_sigpending((old_sigset_t __user *) &s);
80992+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
80993 set_fs(old_fs);
80994 if (ret == 0)
80995 ret = put_user(s, set);
80996@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
80997 mm_segment_t old_fs = get_fs();
80998
80999 set_fs(KERNEL_DS);
81000- ret = sys_old_getrlimit(resource, &r);
81001+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
81002 set_fs(old_fs);
81003
81004 if (!ret) {
81005@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
81006 set_fs (KERNEL_DS);
81007 ret = sys_wait4(pid,
81008 (stat_addr ?
81009- (unsigned int __user *) &status : NULL),
81010- options, (struct rusage __user *) &r);
81011+ (unsigned int __force_user *) &status : NULL),
81012+ options, (struct rusage __force_user *) &r);
81013 set_fs (old_fs);
81014
81015 if (ret > 0) {
81016@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
81017 memset(&info, 0, sizeof(info));
81018
81019 set_fs(KERNEL_DS);
81020- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
81021- uru ? (struct rusage __user *)&ru : NULL);
81022+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
81023+ uru ? (struct rusage __force_user *)&ru : NULL);
81024 set_fs(old_fs);
81025
81026 if ((ret < 0) || (info.si_signo == 0))
81027@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
81028 oldfs = get_fs();
81029 set_fs(KERNEL_DS);
81030 err = sys_timer_settime(timer_id, flags,
81031- (struct itimerspec __user *) &newts,
81032- (struct itimerspec __user *) &oldts);
81033+ (struct itimerspec __force_user *) &newts,
81034+ (struct itimerspec __force_user *) &oldts);
81035 set_fs(oldfs);
81036 if (!err && old && put_compat_itimerspec(old, &oldts))
81037 return -EFAULT;
81038@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
81039 oldfs = get_fs();
81040 set_fs(KERNEL_DS);
81041 err = sys_timer_gettime(timer_id,
81042- (struct itimerspec __user *) &ts);
81043+ (struct itimerspec __force_user *) &ts);
81044 set_fs(oldfs);
81045 if (!err && put_compat_itimerspec(setting, &ts))
81046 return -EFAULT;
81047@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
81048 oldfs = get_fs();
81049 set_fs(KERNEL_DS);
81050 err = sys_clock_settime(which_clock,
81051- (struct timespec __user *) &ts);
81052+ (struct timespec __force_user *) &ts);
81053 set_fs(oldfs);
81054 return err;
81055 }
81056@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
81057 oldfs = get_fs();
81058 set_fs(KERNEL_DS);
81059 err = sys_clock_gettime(which_clock,
81060- (struct timespec __user *) &ts);
81061+ (struct timespec __force_user *) &ts);
81062 set_fs(oldfs);
81063 if (!err && put_compat_timespec(&ts, tp))
81064 return -EFAULT;
81065@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
81066
81067 oldfs = get_fs();
81068 set_fs(KERNEL_DS);
81069- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
81070+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
81071 set_fs(oldfs);
81072
81073 err = compat_put_timex(utp, &txc);
81074@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
81075 oldfs = get_fs();
81076 set_fs(KERNEL_DS);
81077 err = sys_clock_getres(which_clock,
81078- (struct timespec __user *) &ts);
81079+ (struct timespec __force_user *) &ts);
81080 set_fs(oldfs);
81081 if (!err && tp && put_compat_timespec(&ts, tp))
81082 return -EFAULT;
81083@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
81084 long err;
81085 mm_segment_t oldfs;
81086 struct timespec tu;
81087- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
81088+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
81089
81090- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
81091+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
81092 oldfs = get_fs();
81093 set_fs(KERNEL_DS);
81094 err = clock_nanosleep_restart(restart);
81095@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
81096 oldfs = get_fs();
81097 set_fs(KERNEL_DS);
81098 err = sys_clock_nanosleep(which_clock, flags,
81099- (struct timespec __user *) &in,
81100- (struct timespec __user *) &out);
81101+ (struct timespec __force_user *) &in,
81102+ (struct timespec __force_user *) &out);
81103 set_fs(oldfs);
81104
81105 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
81106diff --git a/kernel/configs.c b/kernel/configs.c
81107index c18b1f1..b9a0132 100644
81108--- a/kernel/configs.c
81109+++ b/kernel/configs.c
81110@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
81111 struct proc_dir_entry *entry;
81112
81113 /* create the current config file */
81114+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
81115+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
81116+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
81117+ &ikconfig_file_ops);
81118+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81119+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
81120+ &ikconfig_file_ops);
81121+#endif
81122+#else
81123 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
81124 &ikconfig_file_ops);
81125+#endif
81126+
81127 if (!entry)
81128 return -ENOMEM;
81129
81130diff --git a/kernel/cred.c b/kernel/cred.c
81131index e0573a4..3874e41 100644
81132--- a/kernel/cred.c
81133+++ b/kernel/cred.c
81134@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
81135 validate_creds(cred);
81136 alter_cred_subscribers(cred, -1);
81137 put_cred(cred);
81138+
81139+#ifdef CONFIG_GRKERNSEC_SETXID
81140+ cred = (struct cred *) tsk->delayed_cred;
81141+ if (cred != NULL) {
81142+ tsk->delayed_cred = NULL;
81143+ validate_creds(cred);
81144+ alter_cred_subscribers(cred, -1);
81145+ put_cred(cred);
81146+ }
81147+#endif
81148 }
81149
81150 /**
81151@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
81152 * Always returns 0 thus allowing this function to be tail-called at the end
81153 * of, say, sys_setgid().
81154 */
81155-int commit_creds(struct cred *new)
81156+static int __commit_creds(struct cred *new)
81157 {
81158 struct task_struct *task = current;
81159 const struct cred *old = task->real_cred;
81160@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
81161
81162 get_cred(new); /* we will require a ref for the subj creds too */
81163
81164+ gr_set_role_label(task, new->uid, new->gid);
81165+
81166 /* dumpability changes */
81167 if (!uid_eq(old->euid, new->euid) ||
81168 !gid_eq(old->egid, new->egid) ||
81169@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
81170 put_cred(old);
81171 return 0;
81172 }
81173+#ifdef CONFIG_GRKERNSEC_SETXID
81174+extern int set_user(struct cred *new);
81175+
81176+void gr_delayed_cred_worker(void)
81177+{
81178+ const struct cred *new = current->delayed_cred;
81179+ struct cred *ncred;
81180+
81181+ current->delayed_cred = NULL;
81182+
81183+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
81184+ // from doing get_cred on it when queueing this
81185+ put_cred(new);
81186+ return;
81187+ } else if (new == NULL)
81188+ return;
81189+
81190+ ncred = prepare_creds();
81191+ if (!ncred)
81192+ goto die;
81193+ // uids
81194+ ncred->uid = new->uid;
81195+ ncred->euid = new->euid;
81196+ ncred->suid = new->suid;
81197+ ncred->fsuid = new->fsuid;
81198+ // gids
81199+ ncred->gid = new->gid;
81200+ ncred->egid = new->egid;
81201+ ncred->sgid = new->sgid;
81202+ ncred->fsgid = new->fsgid;
81203+ // groups
81204+ if (set_groups(ncred, new->group_info) < 0) {
81205+ abort_creds(ncred);
81206+ goto die;
81207+ }
81208+ // caps
81209+ ncred->securebits = new->securebits;
81210+ ncred->cap_inheritable = new->cap_inheritable;
81211+ ncred->cap_permitted = new->cap_permitted;
81212+ ncred->cap_effective = new->cap_effective;
81213+ ncred->cap_bset = new->cap_bset;
81214+
81215+ if (set_user(ncred)) {
81216+ abort_creds(ncred);
81217+ goto die;
81218+ }
81219+
81220+ // from doing get_cred on it when queueing this
81221+ put_cred(new);
81222+
81223+ __commit_creds(ncred);
81224+ return;
81225+die:
81226+ // from doing get_cred on it when queueing this
81227+ put_cred(new);
81228+ do_group_exit(SIGKILL);
81229+}
81230+#endif
81231+
81232+int commit_creds(struct cred *new)
81233+{
81234+#ifdef CONFIG_GRKERNSEC_SETXID
81235+ int ret;
81236+ int schedule_it = 0;
81237+ struct task_struct *t;
81238+
81239+ /* we won't get called with tasklist_lock held for writing
81240+ and interrupts disabled as the cred struct in that case is
81241+ init_cred
81242+ */
81243+ if (grsec_enable_setxid && !current_is_single_threaded() &&
81244+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
81245+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
81246+ schedule_it = 1;
81247+ }
81248+ ret = __commit_creds(new);
81249+ if (schedule_it) {
81250+ rcu_read_lock();
81251+ read_lock(&tasklist_lock);
81252+ for (t = next_thread(current); t != current;
81253+ t = next_thread(t)) {
81254+ if (t->delayed_cred == NULL) {
81255+ t->delayed_cred = get_cred(new);
81256+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
81257+ set_tsk_need_resched(t);
81258+ }
81259+ }
81260+ read_unlock(&tasklist_lock);
81261+ rcu_read_unlock();
81262+ }
81263+ return ret;
81264+#else
81265+ return __commit_creds(new);
81266+#endif
81267+}
81268+
81269 EXPORT_SYMBOL(commit_creds);
81270
81271 /**
81272diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
81273index 0506d44..2c20034 100644
81274--- a/kernel/debug/debug_core.c
81275+++ b/kernel/debug/debug_core.c
81276@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
81277 */
81278 static atomic_t masters_in_kgdb;
81279 static atomic_t slaves_in_kgdb;
81280-static atomic_t kgdb_break_tasklet_var;
81281+static atomic_unchecked_t kgdb_break_tasklet_var;
81282 atomic_t kgdb_setting_breakpoint;
81283
81284 struct task_struct *kgdb_usethread;
81285@@ -133,7 +133,7 @@ int kgdb_single_step;
81286 static pid_t kgdb_sstep_pid;
81287
81288 /* to keep track of the CPU which is doing the single stepping*/
81289-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
81290+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
81291
81292 /*
81293 * If you are debugging a problem where roundup (the collection of
81294@@ -541,7 +541,7 @@ return_normal:
81295 * kernel will only try for the value of sstep_tries before
81296 * giving up and continuing on.
81297 */
81298- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
81299+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
81300 (kgdb_info[cpu].task &&
81301 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
81302 atomic_set(&kgdb_active, -1);
81303@@ -635,8 +635,8 @@ cpu_master_loop:
81304 }
81305
81306 kgdb_restore:
81307- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
81308- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
81309+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
81310+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
81311 if (kgdb_info[sstep_cpu].task)
81312 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
81313 else
81314@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
81315 static void kgdb_tasklet_bpt(unsigned long ing)
81316 {
81317 kgdb_breakpoint();
81318- atomic_set(&kgdb_break_tasklet_var, 0);
81319+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
81320 }
81321
81322 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
81323
81324 void kgdb_schedule_breakpoint(void)
81325 {
81326- if (atomic_read(&kgdb_break_tasklet_var) ||
81327+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
81328 atomic_read(&kgdb_active) != -1 ||
81329 atomic_read(&kgdb_setting_breakpoint))
81330 return;
81331- atomic_inc(&kgdb_break_tasklet_var);
81332+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
81333 tasklet_schedule(&kgdb_tasklet_breakpoint);
81334 }
81335 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
81336diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
81337index 00eb8f7..d7e3244 100644
81338--- a/kernel/debug/kdb/kdb_main.c
81339+++ b/kernel/debug/kdb/kdb_main.c
81340@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
81341 continue;
81342
81343 kdb_printf("%-20s%8u 0x%p ", mod->name,
81344- mod->core_size, (void *)mod);
81345+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
81346 #ifdef CONFIG_MODULE_UNLOAD
81347 kdb_printf("%4ld ", module_refcount(mod));
81348 #endif
81349@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
81350 kdb_printf(" (Loading)");
81351 else
81352 kdb_printf(" (Live)");
81353- kdb_printf(" 0x%p", mod->module_core);
81354+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
81355
81356 #ifdef CONFIG_MODULE_UNLOAD
81357 {
81358diff --git a/kernel/events/core.c b/kernel/events/core.c
81359index e76e495..cbfe63a 100644
81360--- a/kernel/events/core.c
81361+++ b/kernel/events/core.c
81362@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
81363 * 0 - disallow raw tracepoint access for unpriv
81364 * 1 - disallow cpu events for unpriv
81365 * 2 - disallow kernel profiling for unpriv
81366+ * 3 - disallow all unpriv perf event use
81367 */
81368-int sysctl_perf_event_paranoid __read_mostly = 1;
81369+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
81370+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
81371+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
81372+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
81373+#else
81374+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
81375+#endif
81376
81377 /* Minimum for 512 kiB + 1 user control page */
81378 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
81379@@ -184,7 +191,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
81380 return 0;
81381 }
81382
81383-static atomic64_t perf_event_id;
81384+static atomic64_unchecked_t perf_event_id;
81385
81386 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
81387 enum event_type_t event_type);
81388@@ -2747,7 +2754,7 @@ static void __perf_event_read(void *info)
81389
81390 static inline u64 perf_event_count(struct perf_event *event)
81391 {
81392- return local64_read(&event->count) + atomic64_read(&event->child_count);
81393+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
81394 }
81395
81396 static u64 perf_event_read(struct perf_event *event)
81397@@ -3093,9 +3100,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
81398 mutex_lock(&event->child_mutex);
81399 total += perf_event_read(event);
81400 *enabled += event->total_time_enabled +
81401- atomic64_read(&event->child_total_time_enabled);
81402+ atomic64_read_unchecked(&event->child_total_time_enabled);
81403 *running += event->total_time_running +
81404- atomic64_read(&event->child_total_time_running);
81405+ atomic64_read_unchecked(&event->child_total_time_running);
81406
81407 list_for_each_entry(child, &event->child_list, child_list) {
81408 total += perf_event_read(child);
81409@@ -3481,10 +3488,10 @@ void perf_event_update_userpage(struct perf_event *event)
81410 userpg->offset -= local64_read(&event->hw.prev_count);
81411
81412 userpg->time_enabled = enabled +
81413- atomic64_read(&event->child_total_time_enabled);
81414+ atomic64_read_unchecked(&event->child_total_time_enabled);
81415
81416 userpg->time_running = running +
81417- atomic64_read(&event->child_total_time_running);
81418+ atomic64_read_unchecked(&event->child_total_time_running);
81419
81420 arch_perf_update_userpage(userpg, now);
81421
81422@@ -4034,7 +4041,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
81423
81424 /* Data. */
81425 sp = perf_user_stack_pointer(regs);
81426- rem = __output_copy_user(handle, (void *) sp, dump_size);
81427+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
81428 dyn_size = dump_size - rem;
81429
81430 perf_output_skip(handle, rem);
81431@@ -4122,11 +4129,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
81432 values[n++] = perf_event_count(event);
81433 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
81434 values[n++] = enabled +
81435- atomic64_read(&event->child_total_time_enabled);
81436+ atomic64_read_unchecked(&event->child_total_time_enabled);
81437 }
81438 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
81439 values[n++] = running +
81440- atomic64_read(&event->child_total_time_running);
81441+ atomic64_read_unchecked(&event->child_total_time_running);
81442 }
81443 if (read_format & PERF_FORMAT_ID)
81444 values[n++] = primary_event_id(event);
81445@@ -4835,12 +4842,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
81446 * need to add enough zero bytes after the string to handle
81447 * the 64bit alignment we do later.
81448 */
81449- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
81450+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
81451 if (!buf) {
81452 name = strncpy(tmp, "//enomem", sizeof(tmp));
81453 goto got_name;
81454 }
81455- name = d_path(&file->f_path, buf, PATH_MAX);
81456+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
81457 if (IS_ERR(name)) {
81458 name = strncpy(tmp, "//toolong", sizeof(tmp));
81459 goto got_name;
81460@@ -6262,7 +6269,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
81461 event->parent = parent_event;
81462
81463 event->ns = get_pid_ns(task_active_pid_ns(current));
81464- event->id = atomic64_inc_return(&perf_event_id);
81465+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
81466
81467 event->state = PERF_EVENT_STATE_INACTIVE;
81468
81469@@ -6572,6 +6579,11 @@ SYSCALL_DEFINE5(perf_event_open,
81470 if (flags & ~PERF_FLAG_ALL)
81471 return -EINVAL;
81472
81473+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
81474+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
81475+ return -EACCES;
81476+#endif
81477+
81478 err = perf_copy_attr(attr_uptr, &attr);
81479 if (err)
81480 return err;
81481@@ -6904,10 +6916,10 @@ static void sync_child_event(struct perf_event *child_event,
81482 /*
81483 * Add back the child's count to the parent's count:
81484 */
81485- atomic64_add(child_val, &parent_event->child_count);
81486- atomic64_add(child_event->total_time_enabled,
81487+ atomic64_add_unchecked(child_val, &parent_event->child_count);
81488+ atomic64_add_unchecked(child_event->total_time_enabled,
81489 &parent_event->child_total_time_enabled);
81490- atomic64_add(child_event->total_time_running,
81491+ atomic64_add_unchecked(child_event->total_time_running,
81492 &parent_event->child_total_time_running);
81493
81494 /*
81495diff --git a/kernel/events/internal.h b/kernel/events/internal.h
81496index ca65997..60df03d 100644
81497--- a/kernel/events/internal.h
81498+++ b/kernel/events/internal.h
81499@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
81500 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
81501 }
81502
81503-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
81504-static inline unsigned int \
81505+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
81506+static inline unsigned long \
81507 func_name(struct perf_output_handle *handle, \
81508- const void *buf, unsigned int len) \
81509+ const void user *buf, unsigned long len) \
81510 { \
81511 unsigned long size, written; \
81512 \
81513@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
81514 return n;
81515 }
81516
81517-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
81518+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
81519
81520 #define MEMCPY_SKIP(dst, src, n) (n)
81521
81522-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
81523+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
81524
81525 #ifndef arch_perf_out_copy_user
81526 #define arch_perf_out_copy_user __copy_from_user_inatomic
81527 #endif
81528
81529-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
81530+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
81531
81532 /* Callchain handling */
81533 extern struct perf_callchain_entry *
81534diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
81535index f356974..cb8c570 100644
81536--- a/kernel/events/uprobes.c
81537+++ b/kernel/events/uprobes.c
81538@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
81539 {
81540 struct page *page;
81541 uprobe_opcode_t opcode;
81542- int result;
81543+ long result;
81544
81545 pagefault_disable();
81546 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
81547diff --git a/kernel/exit.c b/kernel/exit.c
81548index 7bb73f9..d7978ed 100644
81549--- a/kernel/exit.c
81550+++ b/kernel/exit.c
81551@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
81552 struct task_struct *leader;
81553 int zap_leader;
81554 repeat:
81555+#ifdef CONFIG_NET
81556+ gr_del_task_from_ip_table(p);
81557+#endif
81558+
81559 /* don't need to get the RCU readlock here - the process is dead and
81560 * can't be modifying its own credentials. But shut RCU-lockdep up */
81561 rcu_read_lock();
81562@@ -340,7 +344,7 @@ int allow_signal(int sig)
81563 * know it'll be handled, so that they don't get converted to
81564 * SIGKILL or just silently dropped.
81565 */
81566- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
81567+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
81568 recalc_sigpending();
81569 spin_unlock_irq(&current->sighand->siglock);
81570 return 0;
81571@@ -709,6 +713,8 @@ void do_exit(long code)
81572 struct task_struct *tsk = current;
81573 int group_dead;
81574
81575+ set_fs(USER_DS);
81576+
81577 profile_task_exit(tsk);
81578
81579 WARN_ON(blk_needs_flush_plug(tsk));
81580@@ -725,7 +731,6 @@ void do_exit(long code)
81581 * mm_release()->clear_child_tid() from writing to a user-controlled
81582 * kernel address.
81583 */
81584- set_fs(USER_DS);
81585
81586 ptrace_event(PTRACE_EVENT_EXIT, code);
81587
81588@@ -784,6 +789,9 @@ void do_exit(long code)
81589 tsk->exit_code = code;
81590 taskstats_exit(tsk, group_dead);
81591
81592+ gr_acl_handle_psacct(tsk, code);
81593+ gr_acl_handle_exit();
81594+
81595 exit_mm(tsk);
81596
81597 if (group_dead)
81598@@ -905,7 +913,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
81599 * Take down every thread in the group. This is called by fatal signals
81600 * as well as by sys_exit_group (below).
81601 */
81602-void
81603+__noreturn void
81604 do_group_exit(int exit_code)
81605 {
81606 struct signal_struct *sig = current->signal;
81607diff --git a/kernel/fork.c b/kernel/fork.c
81608index ffbc090..08ceeee 100644
81609--- a/kernel/fork.c
81610+++ b/kernel/fork.c
81611@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
81612 *stackend = STACK_END_MAGIC; /* for overflow detection */
81613
81614 #ifdef CONFIG_CC_STACKPROTECTOR
81615- tsk->stack_canary = get_random_int();
81616+ tsk->stack_canary = pax_get_random_long();
81617 #endif
81618
81619 /*
81620@@ -345,13 +345,81 @@ free_tsk:
81621 }
81622
81623 #ifdef CONFIG_MMU
81624+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
81625+{
81626+ struct vm_area_struct *tmp;
81627+ unsigned long charge;
81628+ struct mempolicy *pol;
81629+ struct file *file;
81630+
81631+ charge = 0;
81632+ if (mpnt->vm_flags & VM_ACCOUNT) {
81633+ unsigned long len = vma_pages(mpnt);
81634+
81635+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
81636+ goto fail_nomem;
81637+ charge = len;
81638+ }
81639+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81640+ if (!tmp)
81641+ goto fail_nomem;
81642+ *tmp = *mpnt;
81643+ tmp->vm_mm = mm;
81644+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
81645+ pol = mpol_dup(vma_policy(mpnt));
81646+ if (IS_ERR(pol))
81647+ goto fail_nomem_policy;
81648+ vma_set_policy(tmp, pol);
81649+ if (anon_vma_fork(tmp, mpnt))
81650+ goto fail_nomem_anon_vma_fork;
81651+ tmp->vm_flags &= ~VM_LOCKED;
81652+ tmp->vm_next = tmp->vm_prev = NULL;
81653+ tmp->vm_mirror = NULL;
81654+ file = tmp->vm_file;
81655+ if (file) {
81656+ struct inode *inode = file_inode(file);
81657+ struct address_space *mapping = file->f_mapping;
81658+
81659+ get_file(file);
81660+ if (tmp->vm_flags & VM_DENYWRITE)
81661+ atomic_dec(&inode->i_writecount);
81662+ mutex_lock(&mapping->i_mmap_mutex);
81663+ if (tmp->vm_flags & VM_SHARED)
81664+ mapping->i_mmap_writable++;
81665+ flush_dcache_mmap_lock(mapping);
81666+ /* insert tmp into the share list, just after mpnt */
81667+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
81668+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
81669+ else
81670+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
81671+ flush_dcache_mmap_unlock(mapping);
81672+ mutex_unlock(&mapping->i_mmap_mutex);
81673+ }
81674+
81675+ /*
81676+ * Clear hugetlb-related page reserves for children. This only
81677+ * affects MAP_PRIVATE mappings. Faults generated by the child
81678+ * are not guaranteed to succeed, even if read-only
81679+ */
81680+ if (is_vm_hugetlb_page(tmp))
81681+ reset_vma_resv_huge_pages(tmp);
81682+
81683+ return tmp;
81684+
81685+fail_nomem_anon_vma_fork:
81686+ mpol_put(pol);
81687+fail_nomem_policy:
81688+ kmem_cache_free(vm_area_cachep, tmp);
81689+fail_nomem:
81690+ vm_unacct_memory(charge);
81691+ return NULL;
81692+}
81693+
81694 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81695 {
81696 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
81697 struct rb_node **rb_link, *rb_parent;
81698 int retval;
81699- unsigned long charge;
81700- struct mempolicy *pol;
81701
81702 uprobe_start_dup_mmap();
81703 down_write(&oldmm->mmap_sem);
81704@@ -365,8 +433,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81705 mm->locked_vm = 0;
81706 mm->mmap = NULL;
81707 mm->mmap_cache = NULL;
81708- mm->free_area_cache = oldmm->mmap_base;
81709- mm->cached_hole_size = ~0UL;
81710+ mm->free_area_cache = oldmm->free_area_cache;
81711+ mm->cached_hole_size = oldmm->cached_hole_size;
81712 mm->map_count = 0;
81713 cpumask_clear(mm_cpumask(mm));
81714 mm->mm_rb = RB_ROOT;
81715@@ -382,57 +450,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81716
81717 prev = NULL;
81718 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
81719- struct file *file;
81720-
81721 if (mpnt->vm_flags & VM_DONTCOPY) {
81722 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
81723 -vma_pages(mpnt));
81724 continue;
81725 }
81726- charge = 0;
81727- if (mpnt->vm_flags & VM_ACCOUNT) {
81728- unsigned long len = vma_pages(mpnt);
81729-
81730- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
81731- goto fail_nomem;
81732- charge = len;
81733- }
81734- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81735- if (!tmp)
81736- goto fail_nomem;
81737- *tmp = *mpnt;
81738- INIT_LIST_HEAD(&tmp->anon_vma_chain);
81739- pol = mpol_dup(vma_policy(mpnt));
81740- retval = PTR_ERR(pol);
81741- if (IS_ERR(pol))
81742- goto fail_nomem_policy;
81743- vma_set_policy(tmp, pol);
81744- tmp->vm_mm = mm;
81745- if (anon_vma_fork(tmp, mpnt))
81746- goto fail_nomem_anon_vma_fork;
81747- tmp->vm_flags &= ~VM_LOCKED;
81748- tmp->vm_next = tmp->vm_prev = NULL;
81749- file = tmp->vm_file;
81750- if (file) {
81751- struct inode *inode = file_inode(file);
81752- struct address_space *mapping = file->f_mapping;
81753-
81754- get_file(file);
81755- if (tmp->vm_flags & VM_DENYWRITE)
81756- atomic_dec(&inode->i_writecount);
81757- mutex_lock(&mapping->i_mmap_mutex);
81758- if (tmp->vm_flags & VM_SHARED)
81759- mapping->i_mmap_writable++;
81760- flush_dcache_mmap_lock(mapping);
81761- /* insert tmp into the share list, just after mpnt */
81762- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
81763- vma_nonlinear_insert(tmp,
81764- &mapping->i_mmap_nonlinear);
81765- else
81766- vma_interval_tree_insert_after(tmp, mpnt,
81767- &mapping->i_mmap);
81768- flush_dcache_mmap_unlock(mapping);
81769- mutex_unlock(&mapping->i_mmap_mutex);
81770+ tmp = dup_vma(mm, oldmm, mpnt);
81771+ if (!tmp) {
81772+ retval = -ENOMEM;
81773+ goto out;
81774 }
81775
81776 /*
81777@@ -464,6 +490,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81778 if (retval)
81779 goto out;
81780 }
81781+
81782+#ifdef CONFIG_PAX_SEGMEXEC
81783+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
81784+ struct vm_area_struct *mpnt_m;
81785+
81786+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
81787+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
81788+
81789+ if (!mpnt->vm_mirror)
81790+ continue;
81791+
81792+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
81793+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
81794+ mpnt->vm_mirror = mpnt_m;
81795+ } else {
81796+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
81797+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
81798+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
81799+ mpnt->vm_mirror->vm_mirror = mpnt;
81800+ }
81801+ }
81802+ BUG_ON(mpnt_m);
81803+ }
81804+#endif
81805+
81806 /* a new mm has just been created */
81807 arch_dup_mmap(oldmm, mm);
81808 retval = 0;
81809@@ -473,14 +524,6 @@ out:
81810 up_write(&oldmm->mmap_sem);
81811 uprobe_end_dup_mmap();
81812 return retval;
81813-fail_nomem_anon_vma_fork:
81814- mpol_put(pol);
81815-fail_nomem_policy:
81816- kmem_cache_free(vm_area_cachep, tmp);
81817-fail_nomem:
81818- retval = -ENOMEM;
81819- vm_unacct_memory(charge);
81820- goto out;
81821 }
81822
81823 static inline int mm_alloc_pgd(struct mm_struct *mm)
81824@@ -695,8 +738,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
81825 return ERR_PTR(err);
81826
81827 mm = get_task_mm(task);
81828- if (mm && mm != current->mm &&
81829- !ptrace_may_access(task, mode)) {
81830+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
81831+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
81832 mmput(mm);
81833 mm = ERR_PTR(-EACCES);
81834 }
81835@@ -918,13 +961,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
81836 spin_unlock(&fs->lock);
81837 return -EAGAIN;
81838 }
81839- fs->users++;
81840+ atomic_inc(&fs->users);
81841 spin_unlock(&fs->lock);
81842 return 0;
81843 }
81844 tsk->fs = copy_fs_struct(fs);
81845 if (!tsk->fs)
81846 return -ENOMEM;
81847+ /* Carry through gr_chroot_dentry and is_chrooted instead
81848+ of recomputing it here. Already copied when the task struct
81849+ is duplicated. This allows pivot_root to not be treated as
81850+ a chroot
81851+ */
81852+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
81853+
81854 return 0;
81855 }
81856
81857@@ -1197,10 +1247,13 @@ static struct task_struct *copy_process(unsigned long clone_flags,
81858 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
81859 #endif
81860 retval = -EAGAIN;
81861+
81862+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
81863+
81864 if (atomic_read(&p->real_cred->user->processes) >=
81865 task_rlimit(p, RLIMIT_NPROC)) {
81866- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
81867- p->real_cred->user != INIT_USER)
81868+ if (p->real_cred->user != INIT_USER &&
81869+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
81870 goto bad_fork_free;
81871 }
81872 current->flags &= ~PF_NPROC_EXCEEDED;
81873@@ -1446,6 +1499,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
81874 goto bad_fork_free_pid;
81875 }
81876
81877+ /* synchronizes with gr_set_acls()
81878+ we need to call this past the point of no return for fork()
81879+ */
81880+ gr_copy_label(p);
81881+
81882 if (clone_flags & CLONE_THREAD) {
81883 current->signal->nr_threads++;
81884 atomic_inc(&current->signal->live);
81885@@ -1529,6 +1587,8 @@ bad_fork_cleanup_count:
81886 bad_fork_free:
81887 free_task(p);
81888 fork_out:
81889+ gr_log_forkfail(retval);
81890+
81891 return ERR_PTR(retval);
81892 }
81893
81894@@ -1613,6 +1673,8 @@ long do_fork(unsigned long clone_flags,
81895 if (clone_flags & CLONE_PARENT_SETTID)
81896 put_user(nr, parent_tidptr);
81897
81898+ gr_handle_brute_check();
81899+
81900 if (clone_flags & CLONE_VFORK) {
81901 p->vfork_done = &vfork;
81902 init_completion(&vfork);
81903@@ -1729,7 +1791,7 @@ void __init proc_caches_init(void)
81904 mm_cachep = kmem_cache_create("mm_struct",
81905 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
81906 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
81907- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
81908+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
81909 mmap_init();
81910 nsproxy_cache_init();
81911 }
81912@@ -1769,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
81913 return 0;
81914
81915 /* don't need lock here; in the worst case we'll do useless copy */
81916- if (fs->users == 1)
81917+ if (atomic_read(&fs->users) == 1)
81918 return 0;
81919
81920 *new_fsp = copy_fs_struct(fs);
81921@@ -1881,7 +1943,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
81922 fs = current->fs;
81923 spin_lock(&fs->lock);
81924 current->fs = new_fs;
81925- if (--fs->users)
81926+ gr_set_chroot_entries(current, &current->fs->root);
81927+ if (atomic_dec_return(&fs->users))
81928 new_fs = NULL;
81929 else
81930 new_fs = fs;
81931diff --git a/kernel/futex.c b/kernel/futex.c
81932index 49dacfb..2ac4526 100644
81933--- a/kernel/futex.c
81934+++ b/kernel/futex.c
81935@@ -54,6 +54,7 @@
81936 #include <linux/mount.h>
81937 #include <linux/pagemap.h>
81938 #include <linux/syscalls.h>
81939+#include <linux/ptrace.h>
81940 #include <linux/signal.h>
81941 #include <linux/export.h>
81942 #include <linux/magic.h>
81943@@ -242,6 +243,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
81944 struct page *page, *page_head;
81945 int err, ro = 0;
81946
81947+#ifdef CONFIG_PAX_SEGMEXEC
81948+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
81949+ return -EFAULT;
81950+#endif
81951+
81952 /*
81953 * The futex address must be "naturally" aligned.
81954 */
81955@@ -440,7 +446,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
81956
81957 static int get_futex_value_locked(u32 *dest, u32 __user *from)
81958 {
81959- int ret;
81960+ unsigned long ret;
81961
81962 pagefault_disable();
81963 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
81964@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
81965 {
81966 u32 curval;
81967 int i;
81968+ mm_segment_t oldfs;
81969
81970 /*
81971 * This will fail and we want it. Some arch implementations do
81972@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
81973 * implementation, the non-functional ones will return
81974 * -ENOSYS.
81975 */
81976+ oldfs = get_fs();
81977+ set_fs(USER_DS);
81978 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
81979 futex_cmpxchg_enabled = 1;
81980+ set_fs(oldfs);
81981
81982 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
81983 plist_head_init(&futex_queues[i].chain);
81984diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
81985index f9f44fd..29885e4 100644
81986--- a/kernel/futex_compat.c
81987+++ b/kernel/futex_compat.c
81988@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
81989 return 0;
81990 }
81991
81992-static void __user *futex_uaddr(struct robust_list __user *entry,
81993+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
81994 compat_long_t futex_offset)
81995 {
81996 compat_uptr_t base = ptr_to_compat(entry);
81997diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
81998index 9b22d03..6295b62 100644
81999--- a/kernel/gcov/base.c
82000+++ b/kernel/gcov/base.c
82001@@ -102,11 +102,6 @@ void gcov_enable_events(void)
82002 }
82003
82004 #ifdef CONFIG_MODULES
82005-static inline int within(void *addr, void *start, unsigned long size)
82006-{
82007- return ((addr >= start) && (addr < start + size));
82008-}
82009-
82010 /* Update list and generate events when modules are unloaded. */
82011 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
82012 void *data)
82013@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
82014 prev = NULL;
82015 /* Remove entries located in module from linked list. */
82016 for (info = gcov_info_head; info; info = info->next) {
82017- if (within(info, mod->module_core, mod->core_size)) {
82018+ if (within_module_core_rw((unsigned long)info, mod)) {
82019 if (prev)
82020 prev->next = info->next;
82021 else
82022diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
82023index 2288fbd..0f3941f 100644
82024--- a/kernel/hrtimer.c
82025+++ b/kernel/hrtimer.c
82026@@ -1435,7 +1435,7 @@ void hrtimer_peek_ahead_timers(void)
82027 local_irq_restore(flags);
82028 }
82029
82030-static void run_hrtimer_softirq(struct softirq_action *h)
82031+static void run_hrtimer_softirq(void)
82032 {
82033 hrtimer_peek_ahead_timers();
82034 }
82035@@ -1770,7 +1770,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
82036 return NOTIFY_OK;
82037 }
82038
82039-static struct notifier_block __cpuinitdata hrtimers_nb = {
82040+static struct notifier_block hrtimers_nb = {
82041 .notifier_call = hrtimer_cpu_notify,
82042 };
82043
82044diff --git a/kernel/irq_work.c b/kernel/irq_work.c
82045index 55fcce6..0e4cf34 100644
82046--- a/kernel/irq_work.c
82047+++ b/kernel/irq_work.c
82048@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
82049 return NOTIFY_OK;
82050 }
82051
82052-static struct notifier_block cpu_notify;
82053+static struct notifier_block cpu_notify = {
82054+ .notifier_call = irq_work_cpu_notify,
82055+ .priority = 0,
82056+};
82057
82058 static __init int irq_work_init_cpu_notifier(void)
82059 {
82060- cpu_notify.notifier_call = irq_work_cpu_notify;
82061- cpu_notify.priority = 0;
82062 register_cpu_notifier(&cpu_notify);
82063 return 0;
82064 }
82065diff --git a/kernel/jump_label.c b/kernel/jump_label.c
82066index 60f48fa..7f3a770 100644
82067--- a/kernel/jump_label.c
82068+++ b/kernel/jump_label.c
82069@@ -13,6 +13,7 @@
82070 #include <linux/sort.h>
82071 #include <linux/err.h>
82072 #include <linux/static_key.h>
82073+#include <linux/mm.h>
82074
82075 #ifdef HAVE_JUMP_LABEL
82076
82077@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
82078
82079 size = (((unsigned long)stop - (unsigned long)start)
82080 / sizeof(struct jump_entry));
82081+ pax_open_kernel();
82082 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
82083+ pax_close_kernel();
82084 }
82085
82086 static void jump_label_update(struct static_key *key, int enable);
82087@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
82088 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
82089 struct jump_entry *iter;
82090
82091+ pax_open_kernel();
82092 for (iter = iter_start; iter < iter_stop; iter++) {
82093 if (within_module_init(iter->code, mod))
82094 iter->code = 0;
82095 }
82096+ pax_close_kernel();
82097 }
82098
82099 static int
82100diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
82101index 3127ad5..159d880 100644
82102--- a/kernel/kallsyms.c
82103+++ b/kernel/kallsyms.c
82104@@ -11,6 +11,9 @@
82105 * Changed the compression method from stem compression to "table lookup"
82106 * compression (see scripts/kallsyms.c for a more complete description)
82107 */
82108+#ifdef CONFIG_GRKERNSEC_HIDESYM
82109+#define __INCLUDED_BY_HIDESYM 1
82110+#endif
82111 #include <linux/kallsyms.h>
82112 #include <linux/module.h>
82113 #include <linux/init.h>
82114@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
82115
82116 static inline int is_kernel_inittext(unsigned long addr)
82117 {
82118+ if (system_state != SYSTEM_BOOTING)
82119+ return 0;
82120+
82121 if (addr >= (unsigned long)_sinittext
82122 && addr <= (unsigned long)_einittext)
82123 return 1;
82124 return 0;
82125 }
82126
82127+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82128+#ifdef CONFIG_MODULES
82129+static inline int is_module_text(unsigned long addr)
82130+{
82131+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
82132+ return 1;
82133+
82134+ addr = ktla_ktva(addr);
82135+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
82136+}
82137+#else
82138+static inline int is_module_text(unsigned long addr)
82139+{
82140+ return 0;
82141+}
82142+#endif
82143+#endif
82144+
82145 static inline int is_kernel_text(unsigned long addr)
82146 {
82147 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
82148@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
82149
82150 static inline int is_kernel(unsigned long addr)
82151 {
82152+
82153+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82154+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
82155+ return 1;
82156+
82157+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
82158+#else
82159 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
82160+#endif
82161+
82162 return 1;
82163 return in_gate_area_no_mm(addr);
82164 }
82165
82166 static int is_ksym_addr(unsigned long addr)
82167 {
82168+
82169+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82170+ if (is_module_text(addr))
82171+ return 0;
82172+#endif
82173+
82174 if (all_var)
82175 return is_kernel(addr);
82176
82177@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
82178
82179 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
82180 {
82181- iter->name[0] = '\0';
82182 iter->nameoff = get_symbol_offset(new_pos);
82183 iter->pos = new_pos;
82184 }
82185@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
82186 {
82187 struct kallsym_iter *iter = m->private;
82188
82189+#ifdef CONFIG_GRKERNSEC_HIDESYM
82190+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
82191+ return 0;
82192+#endif
82193+
82194 /* Some debugging symbols have no name. Ignore them. */
82195 if (!iter->name[0])
82196 return 0;
82197@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
82198 */
82199 type = iter->exported ? toupper(iter->type) :
82200 tolower(iter->type);
82201+
82202 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
82203 type, iter->name, iter->module_name);
82204 } else
82205@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
82206 struct kallsym_iter *iter;
82207 int ret;
82208
82209- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
82210+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
82211 if (!iter)
82212 return -ENOMEM;
82213 reset_iter(iter, 0);
82214diff --git a/kernel/kcmp.c b/kernel/kcmp.c
82215index e30ac0f..3528cac 100644
82216--- a/kernel/kcmp.c
82217+++ b/kernel/kcmp.c
82218@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
82219 struct task_struct *task1, *task2;
82220 int ret;
82221
82222+#ifdef CONFIG_GRKERNSEC
82223+ return -ENOSYS;
82224+#endif
82225+
82226 rcu_read_lock();
82227
82228 /*
82229diff --git a/kernel/kexec.c b/kernel/kexec.c
82230index 59f7b55..4022f65 100644
82231--- a/kernel/kexec.c
82232+++ b/kernel/kexec.c
82233@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
82234 unsigned long flags)
82235 {
82236 struct compat_kexec_segment in;
82237- struct kexec_segment out, __user *ksegments;
82238+ struct kexec_segment out;
82239+ struct kexec_segment __user *ksegments;
82240 unsigned long i, result;
82241
82242 /* Don't allow clients that don't understand the native
82243diff --git a/kernel/kmod.c b/kernel/kmod.c
82244index 8241906..d625f2c 100644
82245--- a/kernel/kmod.c
82246+++ b/kernel/kmod.c
82247@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
82248 kfree(info->argv);
82249 }
82250
82251-static int call_modprobe(char *module_name, int wait)
82252+static int call_modprobe(char *module_name, char *module_param, int wait)
82253 {
82254 struct subprocess_info *info;
82255 static char *envp[] = {
82256@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
82257 NULL
82258 };
82259
82260- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
82261+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
82262 if (!argv)
82263 goto out;
82264
82265@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
82266 argv[1] = "-q";
82267 argv[2] = "--";
82268 argv[3] = module_name; /* check free_modprobe_argv() */
82269- argv[4] = NULL;
82270+ argv[4] = module_param;
82271+ argv[5] = NULL;
82272
82273 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
82274 NULL, free_modprobe_argv, NULL);
82275@@ -129,9 +130,8 @@ out:
82276 * If module auto-loading support is disabled then this function
82277 * becomes a no-operation.
82278 */
82279-int __request_module(bool wait, const char *fmt, ...)
82280+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
82281 {
82282- va_list args;
82283 char module_name[MODULE_NAME_LEN];
82284 unsigned int max_modprobes;
82285 int ret;
82286@@ -147,9 +147,7 @@ int __request_module(bool wait, const char *fmt, ...)
82287 */
82288 WARN_ON_ONCE(wait && current_is_async());
82289
82290- va_start(args, fmt);
82291- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
82292- va_end(args);
82293+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
82294 if (ret >= MODULE_NAME_LEN)
82295 return -ENAMETOOLONG;
82296
82297@@ -157,6 +155,20 @@ int __request_module(bool wait, const char *fmt, ...)
82298 if (ret)
82299 return ret;
82300
82301+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82302+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
82303+ /* hack to workaround consolekit/udisks stupidity */
82304+ read_lock(&tasklist_lock);
82305+ if (!strcmp(current->comm, "mount") &&
82306+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
82307+ read_unlock(&tasklist_lock);
82308+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
82309+ return -EPERM;
82310+ }
82311+ read_unlock(&tasklist_lock);
82312+ }
82313+#endif
82314+
82315 /* If modprobe needs a service that is in a module, we get a recursive
82316 * loop. Limit the number of running kmod threads to max_threads/2 or
82317 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
82318@@ -185,11 +197,52 @@ int __request_module(bool wait, const char *fmt, ...)
82319
82320 trace_module_request(module_name, wait, _RET_IP_);
82321
82322- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
82323+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
82324
82325 atomic_dec(&kmod_concurrent);
82326 return ret;
82327 }
82328+
82329+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
82330+{
82331+ va_list args;
82332+ int ret;
82333+
82334+ va_start(args, fmt);
82335+ ret = ____request_module(wait, module_param, fmt, args);
82336+ va_end(args);
82337+
82338+ return ret;
82339+}
82340+
82341+int __request_module(bool wait, const char *fmt, ...)
82342+{
82343+ va_list args;
82344+ int ret;
82345+
82346+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82347+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
82348+ char module_param[MODULE_NAME_LEN];
82349+
82350+ memset(module_param, 0, sizeof(module_param));
82351+
82352+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
82353+
82354+ va_start(args, fmt);
82355+ ret = ____request_module(wait, module_param, fmt, args);
82356+ va_end(args);
82357+
82358+ return ret;
82359+ }
82360+#endif
82361+
82362+ va_start(args, fmt);
82363+ ret = ____request_module(wait, NULL, fmt, args);
82364+ va_end(args);
82365+
82366+ return ret;
82367+}
82368+
82369 EXPORT_SYMBOL(__request_module);
82370 #endif /* CONFIG_MODULES */
82371
82372@@ -300,7 +353,7 @@ static int wait_for_helper(void *data)
82373 *
82374 * Thus the __user pointer cast is valid here.
82375 */
82376- sys_wait4(pid, (int __user *)&ret, 0, NULL);
82377+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
82378
82379 /*
82380 * If ret is 0, either ____call_usermodehelper failed and the
82381@@ -651,7 +704,7 @@ EXPORT_SYMBOL(call_usermodehelper);
82382 static int proc_cap_handler(struct ctl_table *table, int write,
82383 void __user *buffer, size_t *lenp, loff_t *ppos)
82384 {
82385- struct ctl_table t;
82386+ ctl_table_no_const t;
82387 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
82388 kernel_cap_t new_cap;
82389 int err, i;
82390diff --git a/kernel/kprobes.c b/kernel/kprobes.c
82391index bddf3b2..233bf40 100644
82392--- a/kernel/kprobes.c
82393+++ b/kernel/kprobes.c
82394@@ -31,6 +31,9 @@
82395 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
82396 * <prasanna@in.ibm.com> added function-return probes.
82397 */
82398+#ifdef CONFIG_GRKERNSEC_HIDESYM
82399+#define __INCLUDED_BY_HIDESYM 1
82400+#endif
82401 #include <linux/kprobes.h>
82402 #include <linux/hash.h>
82403 #include <linux/init.h>
82404@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
82405 * kernel image and loaded module images reside. This is required
82406 * so x86_64 can correctly handle the %rip-relative fixups.
82407 */
82408- kip->insns = module_alloc(PAGE_SIZE);
82409+ kip->insns = module_alloc_exec(PAGE_SIZE);
82410 if (!kip->insns) {
82411 kfree(kip);
82412 return NULL;
82413@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
82414 */
82415 if (!list_is_singular(&kip->list)) {
82416 list_del(&kip->list);
82417- module_free(NULL, kip->insns);
82418+ module_free_exec(NULL, kip->insns);
82419 kfree(kip);
82420 }
82421 return 1;
82422@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
82423 {
82424 int i, err = 0;
82425 unsigned long offset = 0, size = 0;
82426- char *modname, namebuf[128];
82427+ char *modname, namebuf[KSYM_NAME_LEN];
82428 const char *symbol_name;
82429 void *addr;
82430 struct kprobe_blackpoint *kb;
82431@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
82432 kprobe_type = "k";
82433
82434 if (sym)
82435- seq_printf(pi, "%p %s %s+0x%x %s ",
82436+ seq_printf(pi, "%pK %s %s+0x%x %s ",
82437 p->addr, kprobe_type, sym, offset,
82438 (modname ? modname : " "));
82439 else
82440- seq_printf(pi, "%p %s %p ",
82441+ seq_printf(pi, "%pK %s %pK ",
82442 p->addr, kprobe_type, p->addr);
82443
82444 if (!pp)
82445@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
82446 const char *sym = NULL;
82447 unsigned int i = *(loff_t *) v;
82448 unsigned long offset = 0;
82449- char *modname, namebuf[128];
82450+ char *modname, namebuf[KSYM_NAME_LEN];
82451
82452 head = &kprobe_table[i];
82453 preempt_disable();
82454diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
82455index 6ada93c..dce7d5d 100644
82456--- a/kernel/ksysfs.c
82457+++ b/kernel/ksysfs.c
82458@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
82459 {
82460 if (count+1 > UEVENT_HELPER_PATH_LEN)
82461 return -ENOENT;
82462+ if (!capable(CAP_SYS_ADMIN))
82463+ return -EPERM;
82464 memcpy(uevent_helper, buf, count);
82465 uevent_helper[count] = '\0';
82466 if (count && uevent_helper[count-1] == '\n')
82467@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
82468 return count;
82469 }
82470
82471-static struct bin_attribute notes_attr = {
82472+static bin_attribute_no_const notes_attr __read_only = {
82473 .attr = {
82474 .name = "notes",
82475 .mode = S_IRUGO,
82476diff --git a/kernel/lockdep.c b/kernel/lockdep.c
82477index 1f3186b..bb7dbc6 100644
82478--- a/kernel/lockdep.c
82479+++ b/kernel/lockdep.c
82480@@ -596,6 +596,10 @@ static int static_obj(void *obj)
82481 end = (unsigned long) &_end,
82482 addr = (unsigned long) obj;
82483
82484+#ifdef CONFIG_PAX_KERNEXEC
82485+ start = ktla_ktva(start);
82486+#endif
82487+
82488 /*
82489 * static variable?
82490 */
82491@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
82492 if (!static_obj(lock->key)) {
82493 debug_locks_off();
82494 printk("INFO: trying to register non-static key.\n");
82495+ printk("lock:%pS key:%pS.\n", lock, lock->key);
82496 printk("the code is fine but needs lockdep annotation.\n");
82497 printk("turning off the locking correctness validator.\n");
82498 dump_stack();
82499@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
82500 if (!class)
82501 return 0;
82502 }
82503- atomic_inc((atomic_t *)&class->ops);
82504+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
82505 if (very_verbose(class)) {
82506 printk("\nacquire class [%p] %s", class->key, class->name);
82507 if (class->name_version > 1)
82508diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
82509index b2c71c5..7b88d63 100644
82510--- a/kernel/lockdep_proc.c
82511+++ b/kernel/lockdep_proc.c
82512@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
82513 return 0;
82514 }
82515
82516- seq_printf(m, "%p", class->key);
82517+ seq_printf(m, "%pK", class->key);
82518 #ifdef CONFIG_DEBUG_LOCKDEP
82519 seq_printf(m, " OPS:%8ld", class->ops);
82520 #endif
82521@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
82522
82523 list_for_each_entry(entry, &class->locks_after, entry) {
82524 if (entry->distance == 1) {
82525- seq_printf(m, " -> [%p] ", entry->class->key);
82526+ seq_printf(m, " -> [%pK] ", entry->class->key);
82527 print_name(m, entry->class);
82528 seq_puts(m, "\n");
82529 }
82530@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
82531 if (!class->key)
82532 continue;
82533
82534- seq_printf(m, "[%p] ", class->key);
82535+ seq_printf(m, "[%pK] ", class->key);
82536 print_name(m, class);
82537 seq_puts(m, "\n");
82538 }
82539@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
82540 if (!i)
82541 seq_line(m, '-', 40-namelen, namelen);
82542
82543- snprintf(ip, sizeof(ip), "[<%p>]",
82544+ snprintf(ip, sizeof(ip), "[<%pK>]",
82545 (void *)class->contention_point[i]);
82546 seq_printf(m, "%40s %14lu %29s %pS\n",
82547 name, stats->contention_point[i],
82548@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
82549 if (!i)
82550 seq_line(m, '-', 40-namelen, namelen);
82551
82552- snprintf(ip, sizeof(ip), "[<%p>]",
82553+ snprintf(ip, sizeof(ip), "[<%pK>]",
82554 (void *)class->contending_point[i]);
82555 seq_printf(m, "%40s %14lu %29s %pS\n",
82556 name, stats->contending_point[i],
82557diff --git a/kernel/module.c b/kernel/module.c
82558index fa53db8..6f17200 100644
82559--- a/kernel/module.c
82560+++ b/kernel/module.c
82561@@ -61,6 +61,7 @@
82562 #include <linux/pfn.h>
82563 #include <linux/bsearch.h>
82564 #include <linux/fips.h>
82565+#include <linux/grsecurity.h>
82566 #include <uapi/linux/module.h>
82567 #include "module-internal.h"
82568
82569@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
82570
82571 /* Bounds of module allocation, for speeding __module_address.
82572 * Protected by module_mutex. */
82573-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
82574+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
82575+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
82576
82577 int register_module_notifier(struct notifier_block * nb)
82578 {
82579@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
82580 return true;
82581
82582 list_for_each_entry_rcu(mod, &modules, list) {
82583- struct symsearch arr[] = {
82584+ struct symsearch modarr[] = {
82585 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
82586 NOT_GPL_ONLY, false },
82587 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
82588@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
82589 if (mod->state == MODULE_STATE_UNFORMED)
82590 continue;
82591
82592- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
82593+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
82594 return true;
82595 }
82596 return false;
82597@@ -485,7 +487,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
82598 static int percpu_modalloc(struct module *mod,
82599 unsigned long size, unsigned long align)
82600 {
82601- if (align > PAGE_SIZE) {
82602+ if (align-1 >= PAGE_SIZE) {
82603 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
82604 mod->name, align, PAGE_SIZE);
82605 align = PAGE_SIZE;
82606@@ -1089,7 +1091,7 @@ struct module_attribute module_uevent =
82607 static ssize_t show_coresize(struct module_attribute *mattr,
82608 struct module_kobject *mk, char *buffer)
82609 {
82610- return sprintf(buffer, "%u\n", mk->mod->core_size);
82611+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
82612 }
82613
82614 static struct module_attribute modinfo_coresize =
82615@@ -1098,7 +1100,7 @@ static struct module_attribute modinfo_coresize =
82616 static ssize_t show_initsize(struct module_attribute *mattr,
82617 struct module_kobject *mk, char *buffer)
82618 {
82619- return sprintf(buffer, "%u\n", mk->mod->init_size);
82620+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
82621 }
82622
82623 static struct module_attribute modinfo_initsize =
82624@@ -1313,7 +1315,7 @@ resolve_symbol_wait(struct module *mod,
82625 */
82626 #ifdef CONFIG_SYSFS
82627
82628-#ifdef CONFIG_KALLSYMS
82629+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
82630 static inline bool sect_empty(const Elf_Shdr *sect)
82631 {
82632 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
82633@@ -1453,7 +1455,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
82634 {
82635 unsigned int notes, loaded, i;
82636 struct module_notes_attrs *notes_attrs;
82637- struct bin_attribute *nattr;
82638+ bin_attribute_no_const *nattr;
82639
82640 /* failed to create section attributes, so can't create notes */
82641 if (!mod->sect_attrs)
82642@@ -1565,7 +1567,7 @@ static void del_usage_links(struct module *mod)
82643 static int module_add_modinfo_attrs(struct module *mod)
82644 {
82645 struct module_attribute *attr;
82646- struct module_attribute *temp_attr;
82647+ module_attribute_no_const *temp_attr;
82648 int error = 0;
82649 int i;
82650
82651@@ -1779,21 +1781,21 @@ static void set_section_ro_nx(void *base,
82652
82653 static void unset_module_core_ro_nx(struct module *mod)
82654 {
82655- set_page_attributes(mod->module_core + mod->core_text_size,
82656- mod->module_core + mod->core_size,
82657+ set_page_attributes(mod->module_core_rw,
82658+ mod->module_core_rw + mod->core_size_rw,
82659 set_memory_x);
82660- set_page_attributes(mod->module_core,
82661- mod->module_core + mod->core_ro_size,
82662+ set_page_attributes(mod->module_core_rx,
82663+ mod->module_core_rx + mod->core_size_rx,
82664 set_memory_rw);
82665 }
82666
82667 static void unset_module_init_ro_nx(struct module *mod)
82668 {
82669- set_page_attributes(mod->module_init + mod->init_text_size,
82670- mod->module_init + mod->init_size,
82671+ set_page_attributes(mod->module_init_rw,
82672+ mod->module_init_rw + mod->init_size_rw,
82673 set_memory_x);
82674- set_page_attributes(mod->module_init,
82675- mod->module_init + mod->init_ro_size,
82676+ set_page_attributes(mod->module_init_rx,
82677+ mod->module_init_rx + mod->init_size_rx,
82678 set_memory_rw);
82679 }
82680
82681@@ -1806,14 +1808,14 @@ void set_all_modules_text_rw(void)
82682 list_for_each_entry_rcu(mod, &modules, list) {
82683 if (mod->state == MODULE_STATE_UNFORMED)
82684 continue;
82685- if ((mod->module_core) && (mod->core_text_size)) {
82686- set_page_attributes(mod->module_core,
82687- mod->module_core + mod->core_text_size,
82688+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
82689+ set_page_attributes(mod->module_core_rx,
82690+ mod->module_core_rx + mod->core_size_rx,
82691 set_memory_rw);
82692 }
82693- if ((mod->module_init) && (mod->init_text_size)) {
82694- set_page_attributes(mod->module_init,
82695- mod->module_init + mod->init_text_size,
82696+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
82697+ set_page_attributes(mod->module_init_rx,
82698+ mod->module_init_rx + mod->init_size_rx,
82699 set_memory_rw);
82700 }
82701 }
82702@@ -1829,14 +1831,14 @@ void set_all_modules_text_ro(void)
82703 list_for_each_entry_rcu(mod, &modules, list) {
82704 if (mod->state == MODULE_STATE_UNFORMED)
82705 continue;
82706- if ((mod->module_core) && (mod->core_text_size)) {
82707- set_page_attributes(mod->module_core,
82708- mod->module_core + mod->core_text_size,
82709+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
82710+ set_page_attributes(mod->module_core_rx,
82711+ mod->module_core_rx + mod->core_size_rx,
82712 set_memory_ro);
82713 }
82714- if ((mod->module_init) && (mod->init_text_size)) {
82715- set_page_attributes(mod->module_init,
82716- mod->module_init + mod->init_text_size,
82717+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
82718+ set_page_attributes(mod->module_init_rx,
82719+ mod->module_init_rx + mod->init_size_rx,
82720 set_memory_ro);
82721 }
82722 }
82723@@ -1887,16 +1889,19 @@ static void free_module(struct module *mod)
82724
82725 /* This may be NULL, but that's OK */
82726 unset_module_init_ro_nx(mod);
82727- module_free(mod, mod->module_init);
82728+ module_free(mod, mod->module_init_rw);
82729+ module_free_exec(mod, mod->module_init_rx);
82730 kfree(mod->args);
82731 percpu_modfree(mod);
82732
82733 /* Free lock-classes: */
82734- lockdep_free_key_range(mod->module_core, mod->core_size);
82735+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
82736+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
82737
82738 /* Finally, free the core (containing the module structure) */
82739 unset_module_core_ro_nx(mod);
82740- module_free(mod, mod->module_core);
82741+ module_free_exec(mod, mod->module_core_rx);
82742+ module_free(mod, mod->module_core_rw);
82743
82744 #ifdef CONFIG_MPU
82745 update_protections(current->mm);
82746@@ -1966,9 +1971,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
82747 int ret = 0;
82748 const struct kernel_symbol *ksym;
82749
82750+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82751+ int is_fs_load = 0;
82752+ int register_filesystem_found = 0;
82753+ char *p;
82754+
82755+ p = strstr(mod->args, "grsec_modharden_fs");
82756+ if (p) {
82757+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
82758+ /* copy \0 as well */
82759+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
82760+ is_fs_load = 1;
82761+ }
82762+#endif
82763+
82764 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
82765 const char *name = info->strtab + sym[i].st_name;
82766
82767+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82768+ /* it's a real shame this will never get ripped and copied
82769+ upstream! ;(
82770+ */
82771+ if (is_fs_load && !strcmp(name, "register_filesystem"))
82772+ register_filesystem_found = 1;
82773+#endif
82774+
82775 switch (sym[i].st_shndx) {
82776 case SHN_COMMON:
82777 /* We compiled with -fno-common. These are not
82778@@ -1989,7 +2016,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
82779 ksym = resolve_symbol_wait(mod, info, name);
82780 /* Ok if resolved. */
82781 if (ksym && !IS_ERR(ksym)) {
82782+ pax_open_kernel();
82783 sym[i].st_value = ksym->value;
82784+ pax_close_kernel();
82785 break;
82786 }
82787
82788@@ -2008,11 +2037,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
82789 secbase = (unsigned long)mod_percpu(mod);
82790 else
82791 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
82792+ pax_open_kernel();
82793 sym[i].st_value += secbase;
82794+ pax_close_kernel();
82795 break;
82796 }
82797 }
82798
82799+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82800+ if (is_fs_load && !register_filesystem_found) {
82801+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
82802+ ret = -EPERM;
82803+ }
82804+#endif
82805+
82806 return ret;
82807 }
82808
82809@@ -2096,22 +2134,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
82810 || s->sh_entsize != ~0UL
82811 || strstarts(sname, ".init"))
82812 continue;
82813- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
82814+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
82815+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
82816+ else
82817+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
82818 pr_debug("\t%s\n", sname);
82819 }
82820- switch (m) {
82821- case 0: /* executable */
82822- mod->core_size = debug_align(mod->core_size);
82823- mod->core_text_size = mod->core_size;
82824- break;
82825- case 1: /* RO: text and ro-data */
82826- mod->core_size = debug_align(mod->core_size);
82827- mod->core_ro_size = mod->core_size;
82828- break;
82829- case 3: /* whole core */
82830- mod->core_size = debug_align(mod->core_size);
82831- break;
82832- }
82833 }
82834
82835 pr_debug("Init section allocation order:\n");
82836@@ -2125,23 +2153,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
82837 || s->sh_entsize != ~0UL
82838 || !strstarts(sname, ".init"))
82839 continue;
82840- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
82841- | INIT_OFFSET_MASK);
82842+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
82843+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
82844+ else
82845+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
82846+ s->sh_entsize |= INIT_OFFSET_MASK;
82847 pr_debug("\t%s\n", sname);
82848 }
82849- switch (m) {
82850- case 0: /* executable */
82851- mod->init_size = debug_align(mod->init_size);
82852- mod->init_text_size = mod->init_size;
82853- break;
82854- case 1: /* RO: text and ro-data */
82855- mod->init_size = debug_align(mod->init_size);
82856- mod->init_ro_size = mod->init_size;
82857- break;
82858- case 3: /* whole init */
82859- mod->init_size = debug_align(mod->init_size);
82860- break;
82861- }
82862 }
82863 }
82864
82865@@ -2314,7 +2332,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
82866
82867 /* Put symbol section at end of init part of module. */
82868 symsect->sh_flags |= SHF_ALLOC;
82869- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
82870+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
82871 info->index.sym) | INIT_OFFSET_MASK;
82872 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
82873
82874@@ -2331,13 +2349,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
82875 }
82876
82877 /* Append room for core symbols at end of core part. */
82878- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
82879- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
82880- mod->core_size += strtab_size;
82881+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
82882+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
82883+ mod->core_size_rx += strtab_size;
82884
82885 /* Put string table section at end of init part of module. */
82886 strsect->sh_flags |= SHF_ALLOC;
82887- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
82888+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
82889 info->index.str) | INIT_OFFSET_MASK;
82890 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
82891 }
82892@@ -2355,12 +2373,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
82893 /* Make sure we get permanent strtab: don't use info->strtab. */
82894 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
82895
82896+ pax_open_kernel();
82897+
82898 /* Set types up while we still have access to sections. */
82899 for (i = 0; i < mod->num_symtab; i++)
82900 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
82901
82902- mod->core_symtab = dst = mod->module_core + info->symoffs;
82903- mod->core_strtab = s = mod->module_core + info->stroffs;
82904+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
82905+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
82906 src = mod->symtab;
82907 for (ndst = i = 0; i < mod->num_symtab; i++) {
82908 if (i == 0 ||
82909@@ -2372,6 +2392,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
82910 }
82911 }
82912 mod->core_num_syms = ndst;
82913+
82914+ pax_close_kernel();
82915 }
82916 #else
82917 static inline void layout_symtab(struct module *mod, struct load_info *info)
82918@@ -2405,17 +2427,33 @@ void * __weak module_alloc(unsigned long size)
82919 return vmalloc_exec(size);
82920 }
82921
82922-static void *module_alloc_update_bounds(unsigned long size)
82923+static void *module_alloc_update_bounds_rw(unsigned long size)
82924 {
82925 void *ret = module_alloc(size);
82926
82927 if (ret) {
82928 mutex_lock(&module_mutex);
82929 /* Update module bounds. */
82930- if ((unsigned long)ret < module_addr_min)
82931- module_addr_min = (unsigned long)ret;
82932- if ((unsigned long)ret + size > module_addr_max)
82933- module_addr_max = (unsigned long)ret + size;
82934+ if ((unsigned long)ret < module_addr_min_rw)
82935+ module_addr_min_rw = (unsigned long)ret;
82936+ if ((unsigned long)ret + size > module_addr_max_rw)
82937+ module_addr_max_rw = (unsigned long)ret + size;
82938+ mutex_unlock(&module_mutex);
82939+ }
82940+ return ret;
82941+}
82942+
82943+static void *module_alloc_update_bounds_rx(unsigned long size)
82944+{
82945+ void *ret = module_alloc_exec(size);
82946+
82947+ if (ret) {
82948+ mutex_lock(&module_mutex);
82949+ /* Update module bounds. */
82950+ if ((unsigned long)ret < module_addr_min_rx)
82951+ module_addr_min_rx = (unsigned long)ret;
82952+ if ((unsigned long)ret + size > module_addr_max_rx)
82953+ module_addr_max_rx = (unsigned long)ret + size;
82954 mutex_unlock(&module_mutex);
82955 }
82956 return ret;
82957@@ -2691,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
82958 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
82959 {
82960 const char *modmagic = get_modinfo(info, "vermagic");
82961+ const char *license = get_modinfo(info, "license");
82962 int err;
82963
82964+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
82965+ if (!license || !license_is_gpl_compatible(license))
82966+ return -ENOEXEC;
82967+#endif
82968+
82969 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
82970 modmagic = NULL;
82971
82972@@ -2718,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
82973 }
82974
82975 /* Set up license info based on the info section */
82976- set_license(mod, get_modinfo(info, "license"));
82977+ set_license(mod, license);
82978
82979 return 0;
82980 }
82981@@ -2799,7 +2843,7 @@ static int move_module(struct module *mod, struct load_info *info)
82982 void *ptr;
82983
82984 /* Do the allocs. */
82985- ptr = module_alloc_update_bounds(mod->core_size);
82986+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
82987 /*
82988 * The pointer to this block is stored in the module structure
82989 * which is inside the block. Just mark it as not being a
82990@@ -2809,11 +2853,11 @@ static int move_module(struct module *mod, struct load_info *info)
82991 if (!ptr)
82992 return -ENOMEM;
82993
82994- memset(ptr, 0, mod->core_size);
82995- mod->module_core = ptr;
82996+ memset(ptr, 0, mod->core_size_rw);
82997+ mod->module_core_rw = ptr;
82998
82999- if (mod->init_size) {
83000- ptr = module_alloc_update_bounds(mod->init_size);
83001+ if (mod->init_size_rw) {
83002+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
83003 /*
83004 * The pointer to this block is stored in the module structure
83005 * which is inside the block. This block doesn't need to be
83006@@ -2822,13 +2866,45 @@ static int move_module(struct module *mod, struct load_info *info)
83007 */
83008 kmemleak_ignore(ptr);
83009 if (!ptr) {
83010- module_free(mod, mod->module_core);
83011+ module_free(mod, mod->module_core_rw);
83012 return -ENOMEM;
83013 }
83014- memset(ptr, 0, mod->init_size);
83015- mod->module_init = ptr;
83016+ memset(ptr, 0, mod->init_size_rw);
83017+ mod->module_init_rw = ptr;
83018 } else
83019- mod->module_init = NULL;
83020+ mod->module_init_rw = NULL;
83021+
83022+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
83023+ kmemleak_not_leak(ptr);
83024+ if (!ptr) {
83025+ if (mod->module_init_rw)
83026+ module_free(mod, mod->module_init_rw);
83027+ module_free(mod, mod->module_core_rw);
83028+ return -ENOMEM;
83029+ }
83030+
83031+ pax_open_kernel();
83032+ memset(ptr, 0, mod->core_size_rx);
83033+ pax_close_kernel();
83034+ mod->module_core_rx = ptr;
83035+
83036+ if (mod->init_size_rx) {
83037+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
83038+ kmemleak_ignore(ptr);
83039+ if (!ptr && mod->init_size_rx) {
83040+ module_free_exec(mod, mod->module_core_rx);
83041+ if (mod->module_init_rw)
83042+ module_free(mod, mod->module_init_rw);
83043+ module_free(mod, mod->module_core_rw);
83044+ return -ENOMEM;
83045+ }
83046+
83047+ pax_open_kernel();
83048+ memset(ptr, 0, mod->init_size_rx);
83049+ pax_close_kernel();
83050+ mod->module_init_rx = ptr;
83051+ } else
83052+ mod->module_init_rx = NULL;
83053
83054 /* Transfer each section which specifies SHF_ALLOC */
83055 pr_debug("final section addresses:\n");
83056@@ -2839,16 +2915,45 @@ static int move_module(struct module *mod, struct load_info *info)
83057 if (!(shdr->sh_flags & SHF_ALLOC))
83058 continue;
83059
83060- if (shdr->sh_entsize & INIT_OFFSET_MASK)
83061- dest = mod->module_init
83062- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
83063- else
83064- dest = mod->module_core + shdr->sh_entsize;
83065+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
83066+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
83067+ dest = mod->module_init_rw
83068+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
83069+ else
83070+ dest = mod->module_init_rx
83071+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
83072+ } else {
83073+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
83074+ dest = mod->module_core_rw + shdr->sh_entsize;
83075+ else
83076+ dest = mod->module_core_rx + shdr->sh_entsize;
83077+ }
83078+
83079+ if (shdr->sh_type != SHT_NOBITS) {
83080+
83081+#ifdef CONFIG_PAX_KERNEXEC
83082+#ifdef CONFIG_X86_64
83083+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
83084+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
83085+#endif
83086+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
83087+ pax_open_kernel();
83088+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
83089+ pax_close_kernel();
83090+ } else
83091+#endif
83092
83093- if (shdr->sh_type != SHT_NOBITS)
83094 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
83095+ }
83096 /* Update sh_addr to point to copy in image. */
83097- shdr->sh_addr = (unsigned long)dest;
83098+
83099+#ifdef CONFIG_PAX_KERNEXEC
83100+ if (shdr->sh_flags & SHF_EXECINSTR)
83101+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
83102+ else
83103+#endif
83104+
83105+ shdr->sh_addr = (unsigned long)dest;
83106 pr_debug("\t0x%lx %s\n",
83107 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
83108 }
83109@@ -2905,12 +3010,12 @@ static void flush_module_icache(const struct module *mod)
83110 * Do it before processing of module parameters, so the module
83111 * can provide parameter accessor functions of its own.
83112 */
83113- if (mod->module_init)
83114- flush_icache_range((unsigned long)mod->module_init,
83115- (unsigned long)mod->module_init
83116- + mod->init_size);
83117- flush_icache_range((unsigned long)mod->module_core,
83118- (unsigned long)mod->module_core + mod->core_size);
83119+ if (mod->module_init_rx)
83120+ flush_icache_range((unsigned long)mod->module_init_rx,
83121+ (unsigned long)mod->module_init_rx
83122+ + mod->init_size_rx);
83123+ flush_icache_range((unsigned long)mod->module_core_rx,
83124+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
83125
83126 set_fs(old_fs);
83127 }
83128@@ -2977,8 +3082,10 @@ static int alloc_module_percpu(struct module *mod, struct load_info *info)
83129 static void module_deallocate(struct module *mod, struct load_info *info)
83130 {
83131 percpu_modfree(mod);
83132- module_free(mod, mod->module_init);
83133- module_free(mod, mod->module_core);
83134+ module_free_exec(mod, mod->module_init_rx);
83135+ module_free_exec(mod, mod->module_core_rx);
83136+ module_free(mod, mod->module_init_rw);
83137+ module_free(mod, mod->module_core_rw);
83138 }
83139
83140 int __weak module_finalize(const Elf_Ehdr *hdr,
83141@@ -2991,7 +3098,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
83142 static int post_relocation(struct module *mod, const struct load_info *info)
83143 {
83144 /* Sort exception table now relocations are done. */
83145+ pax_open_kernel();
83146 sort_extable(mod->extable, mod->extable + mod->num_exentries);
83147+ pax_close_kernel();
83148
83149 /* Copy relocated percpu area over. */
83150 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
83151@@ -3045,16 +3154,16 @@ static int do_init_module(struct module *mod)
83152 MODULE_STATE_COMING, mod);
83153
83154 /* Set RO and NX regions for core */
83155- set_section_ro_nx(mod->module_core,
83156- mod->core_text_size,
83157- mod->core_ro_size,
83158- mod->core_size);
83159+ set_section_ro_nx(mod->module_core_rx,
83160+ mod->core_size_rx,
83161+ mod->core_size_rx,
83162+ mod->core_size_rx);
83163
83164 /* Set RO and NX regions for init */
83165- set_section_ro_nx(mod->module_init,
83166- mod->init_text_size,
83167- mod->init_ro_size,
83168- mod->init_size);
83169+ set_section_ro_nx(mod->module_init_rx,
83170+ mod->init_size_rx,
83171+ mod->init_size_rx,
83172+ mod->init_size_rx);
83173
83174 do_mod_ctors(mod);
83175 /* Start the module */
83176@@ -3116,11 +3225,12 @@ static int do_init_module(struct module *mod)
83177 mod->strtab = mod->core_strtab;
83178 #endif
83179 unset_module_init_ro_nx(mod);
83180- module_free(mod, mod->module_init);
83181- mod->module_init = NULL;
83182- mod->init_size = 0;
83183- mod->init_ro_size = 0;
83184- mod->init_text_size = 0;
83185+ module_free(mod, mod->module_init_rw);
83186+ module_free_exec(mod, mod->module_init_rx);
83187+ mod->module_init_rw = NULL;
83188+ mod->module_init_rx = NULL;
83189+ mod->init_size_rw = 0;
83190+ mod->init_size_rx = 0;
83191 mutex_unlock(&module_mutex);
83192 wake_up_all(&module_wq);
83193
83194@@ -3252,9 +3362,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
83195 if (err)
83196 goto free_unload;
83197
83198+ /* Now copy in args */
83199+ mod->args = strndup_user(uargs, ~0UL >> 1);
83200+ if (IS_ERR(mod->args)) {
83201+ err = PTR_ERR(mod->args);
83202+ goto free_unload;
83203+ }
83204+
83205 /* Set up MODINFO_ATTR fields */
83206 setup_modinfo(mod, info);
83207
83208+#ifdef CONFIG_GRKERNSEC_MODHARDEN
83209+ {
83210+ char *p, *p2;
83211+
83212+ if (strstr(mod->args, "grsec_modharden_netdev")) {
83213+ 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);
83214+ err = -EPERM;
83215+ goto free_modinfo;
83216+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
83217+ p += sizeof("grsec_modharden_normal") - 1;
83218+ p2 = strstr(p, "_");
83219+ if (p2) {
83220+ *p2 = '\0';
83221+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
83222+ *p2 = '_';
83223+ }
83224+ err = -EPERM;
83225+ goto free_modinfo;
83226+ }
83227+ }
83228+#endif
83229+
83230 /* Fix up syms, so that st_value is a pointer to location. */
83231 err = simplify_symbols(mod, info);
83232 if (err < 0)
83233@@ -3270,13 +3409,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
83234
83235 flush_module_icache(mod);
83236
83237- /* Now copy in args */
83238- mod->args = strndup_user(uargs, ~0UL >> 1);
83239- if (IS_ERR(mod->args)) {
83240- err = PTR_ERR(mod->args);
83241- goto free_arch_cleanup;
83242- }
83243-
83244 dynamic_debug_setup(info->debug, info->num_debug);
83245
83246 /* Finally it's fully formed, ready to start executing. */
83247@@ -3311,11 +3443,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
83248 ddebug_cleanup:
83249 dynamic_debug_remove(info->debug);
83250 synchronize_sched();
83251- kfree(mod->args);
83252- free_arch_cleanup:
83253 module_arch_cleanup(mod);
83254 free_modinfo:
83255 free_modinfo(mod);
83256+ kfree(mod->args);
83257 free_unload:
83258 module_unload_free(mod);
83259 unlink_mod:
83260@@ -3398,10 +3529,16 @@ static const char *get_ksymbol(struct module *mod,
83261 unsigned long nextval;
83262
83263 /* At worse, next value is at end of module */
83264- if (within_module_init(addr, mod))
83265- nextval = (unsigned long)mod->module_init+mod->init_text_size;
83266+ if (within_module_init_rx(addr, mod))
83267+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
83268+ else if (within_module_init_rw(addr, mod))
83269+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
83270+ else if (within_module_core_rx(addr, mod))
83271+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
83272+ else if (within_module_core_rw(addr, mod))
83273+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
83274 else
83275- nextval = (unsigned long)mod->module_core+mod->core_text_size;
83276+ return NULL;
83277
83278 /* Scan for closest preceding symbol, and next symbol. (ELF
83279 starts real symbols at 1). */
83280@@ -3654,7 +3791,7 @@ static int m_show(struct seq_file *m, void *p)
83281 return 0;
83282
83283 seq_printf(m, "%s %u",
83284- mod->name, mod->init_size + mod->core_size);
83285+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
83286 print_unload_info(m, mod);
83287
83288 /* Informative for users. */
83289@@ -3663,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
83290 mod->state == MODULE_STATE_COMING ? "Loading":
83291 "Live");
83292 /* Used by oprofile and other similar tools. */
83293- seq_printf(m, " 0x%pK", mod->module_core);
83294+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
83295
83296 /* Taints info */
83297 if (mod->taints)
83298@@ -3699,7 +3836,17 @@ static const struct file_operations proc_modules_operations = {
83299
83300 static int __init proc_modules_init(void)
83301 {
83302+#ifndef CONFIG_GRKERNSEC_HIDESYM
83303+#ifdef CONFIG_GRKERNSEC_PROC_USER
83304+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
83305+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83306+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
83307+#else
83308 proc_create("modules", 0, NULL, &proc_modules_operations);
83309+#endif
83310+#else
83311+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
83312+#endif
83313 return 0;
83314 }
83315 module_init(proc_modules_init);
83316@@ -3760,14 +3907,14 @@ struct module *__module_address(unsigned long addr)
83317 {
83318 struct module *mod;
83319
83320- if (addr < module_addr_min || addr > module_addr_max)
83321+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
83322+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
83323 return NULL;
83324
83325 list_for_each_entry_rcu(mod, &modules, list) {
83326 if (mod->state == MODULE_STATE_UNFORMED)
83327 continue;
83328- if (within_module_core(addr, mod)
83329- || within_module_init(addr, mod))
83330+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
83331 return mod;
83332 }
83333 return NULL;
83334@@ -3802,11 +3949,20 @@ bool is_module_text_address(unsigned long addr)
83335 */
83336 struct module *__module_text_address(unsigned long addr)
83337 {
83338- struct module *mod = __module_address(addr);
83339+ struct module *mod;
83340+
83341+#ifdef CONFIG_X86_32
83342+ addr = ktla_ktva(addr);
83343+#endif
83344+
83345+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
83346+ return NULL;
83347+
83348+ mod = __module_address(addr);
83349+
83350 if (mod) {
83351 /* Make sure it's within the text section. */
83352- if (!within(addr, mod->module_init, mod->init_text_size)
83353- && !within(addr, mod->module_core, mod->core_text_size))
83354+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
83355 mod = NULL;
83356 }
83357 return mod;
83358diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
83359index 7e3443f..b2a1e6b 100644
83360--- a/kernel/mutex-debug.c
83361+++ b/kernel/mutex-debug.c
83362@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
83363 }
83364
83365 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
83366- struct thread_info *ti)
83367+ struct task_struct *task)
83368 {
83369 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
83370
83371 /* Mark the current thread as blocked on the lock: */
83372- ti->task->blocked_on = waiter;
83373+ task->blocked_on = waiter;
83374 }
83375
83376 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
83377- struct thread_info *ti)
83378+ struct task_struct *task)
83379 {
83380 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
83381- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
83382- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
83383- ti->task->blocked_on = NULL;
83384+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
83385+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
83386+ task->blocked_on = NULL;
83387
83388 list_del_init(&waiter->list);
83389 waiter->task = NULL;
83390diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
83391index 0799fd3..d06ae3b 100644
83392--- a/kernel/mutex-debug.h
83393+++ b/kernel/mutex-debug.h
83394@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
83395 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
83396 extern void debug_mutex_add_waiter(struct mutex *lock,
83397 struct mutex_waiter *waiter,
83398- struct thread_info *ti);
83399+ struct task_struct *task);
83400 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
83401- struct thread_info *ti);
83402+ struct task_struct *task);
83403 extern void debug_mutex_unlock(struct mutex *lock);
83404 extern void debug_mutex_init(struct mutex *lock, const char *name,
83405 struct lock_class_key *key);
83406diff --git a/kernel/mutex.c b/kernel/mutex.c
83407index ad53a66..f1bf8bc 100644
83408--- a/kernel/mutex.c
83409+++ b/kernel/mutex.c
83410@@ -134,7 +134,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
83411 node->locked = 1;
83412 return;
83413 }
83414- ACCESS_ONCE(prev->next) = node;
83415+ ACCESS_ONCE_RW(prev->next) = node;
83416 smp_wmb();
83417 /* Wait until the lock holder passes the lock down */
83418 while (!ACCESS_ONCE(node->locked))
83419@@ -155,7 +155,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
83420 while (!(next = ACCESS_ONCE(node->next)))
83421 arch_mutex_cpu_relax();
83422 }
83423- ACCESS_ONCE(next->locked) = 1;
83424+ ACCESS_ONCE_RW(next->locked) = 1;
83425 smp_wmb();
83426 }
83427
83428@@ -341,7 +341,7 @@ slowpath:
83429 spin_lock_mutex(&lock->wait_lock, flags);
83430
83431 debug_mutex_lock_common(lock, &waiter);
83432- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
83433+ debug_mutex_add_waiter(lock, &waiter, task);
83434
83435 /* add waiting tasks to the end of the waitqueue (FIFO): */
83436 list_add_tail(&waiter.list, &lock->wait_list);
83437@@ -371,8 +371,7 @@ slowpath:
83438 * TASK_UNINTERRUPTIBLE case.)
83439 */
83440 if (unlikely(signal_pending_state(state, task))) {
83441- mutex_remove_waiter(lock, &waiter,
83442- task_thread_info(task));
83443+ mutex_remove_waiter(lock, &waiter, task);
83444 mutex_release(&lock->dep_map, 1, ip);
83445 spin_unlock_mutex(&lock->wait_lock, flags);
83446
83447@@ -391,7 +390,7 @@ slowpath:
83448 done:
83449 lock_acquired(&lock->dep_map, ip);
83450 /* got the lock - rejoice! */
83451- mutex_remove_waiter(lock, &waiter, current_thread_info());
83452+ mutex_remove_waiter(lock, &waiter, task);
83453 mutex_set_owner(lock);
83454
83455 /* set it to 0 if there are no waiters left: */
83456diff --git a/kernel/notifier.c b/kernel/notifier.c
83457index 2d5cc4c..d9ea600 100644
83458--- a/kernel/notifier.c
83459+++ b/kernel/notifier.c
83460@@ -5,6 +5,7 @@
83461 #include <linux/rcupdate.h>
83462 #include <linux/vmalloc.h>
83463 #include <linux/reboot.h>
83464+#include <linux/mm.h>
83465
83466 /*
83467 * Notifier list for kernel code which wants to be called
83468@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
83469 while ((*nl) != NULL) {
83470 if (n->priority > (*nl)->priority)
83471 break;
83472- nl = &((*nl)->next);
83473+ nl = (struct notifier_block **)&((*nl)->next);
83474 }
83475- n->next = *nl;
83476+ pax_open_kernel();
83477+ *(const void **)&n->next = *nl;
83478 rcu_assign_pointer(*nl, n);
83479+ pax_close_kernel();
83480 return 0;
83481 }
83482
83483@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
83484 return 0;
83485 if (n->priority > (*nl)->priority)
83486 break;
83487- nl = &((*nl)->next);
83488+ nl = (struct notifier_block **)&((*nl)->next);
83489 }
83490- n->next = *nl;
83491+ pax_open_kernel();
83492+ *(const void **)&n->next = *nl;
83493 rcu_assign_pointer(*nl, n);
83494+ pax_close_kernel();
83495 return 0;
83496 }
83497
83498@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
83499 {
83500 while ((*nl) != NULL) {
83501 if ((*nl) == n) {
83502+ pax_open_kernel();
83503 rcu_assign_pointer(*nl, n->next);
83504+ pax_close_kernel();
83505 return 0;
83506 }
83507- nl = &((*nl)->next);
83508+ nl = (struct notifier_block **)&((*nl)->next);
83509 }
83510 return -ENOENT;
83511 }
83512diff --git a/kernel/panic.c b/kernel/panic.c
83513index 167ec09..0dda5f9 100644
83514--- a/kernel/panic.c
83515+++ b/kernel/panic.c
83516@@ -400,7 +400,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
83517 unsigned taint, struct slowpath_args *args)
83518 {
83519 printk(KERN_WARNING "------------[ cut here ]------------\n");
83520- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
83521+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
83522
83523 if (args)
83524 vprintk(args->fmt, args->args);
83525@@ -453,7 +453,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
83526 */
83527 void __stack_chk_fail(void)
83528 {
83529- panic("stack-protector: Kernel stack is corrupted in: %p\n",
83530+ dump_stack();
83531+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
83532 __builtin_return_address(0));
83533 }
83534 EXPORT_SYMBOL(__stack_chk_fail);
83535diff --git a/kernel/pid.c b/kernel/pid.c
83536index 0db3e79..95b9dc2 100644
83537--- a/kernel/pid.c
83538+++ b/kernel/pid.c
83539@@ -33,6 +33,7 @@
83540 #include <linux/rculist.h>
83541 #include <linux/bootmem.h>
83542 #include <linux/hash.h>
83543+#include <linux/security.h>
83544 #include <linux/pid_namespace.h>
83545 #include <linux/init_task.h>
83546 #include <linux/syscalls.h>
83547@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
83548
83549 int pid_max = PID_MAX_DEFAULT;
83550
83551-#define RESERVED_PIDS 300
83552+#define RESERVED_PIDS 500
83553
83554 int pid_max_min = RESERVED_PIDS + 1;
83555 int pid_max_max = PID_MAX_LIMIT;
83556@@ -442,10 +443,18 @@ EXPORT_SYMBOL(pid_task);
83557 */
83558 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
83559 {
83560+ struct task_struct *task;
83561+
83562 rcu_lockdep_assert(rcu_read_lock_held(),
83563 "find_task_by_pid_ns() needs rcu_read_lock()"
83564 " protection");
83565- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
83566+
83567+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
83568+
83569+ if (gr_pid_is_chrooted(task))
83570+ return NULL;
83571+
83572+ return task;
83573 }
83574
83575 struct task_struct *find_task_by_vpid(pid_t vnr)
83576@@ -453,6 +462,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
83577 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
83578 }
83579
83580+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
83581+{
83582+ rcu_lockdep_assert(rcu_read_lock_held(),
83583+ "find_task_by_pid_ns() needs rcu_read_lock()"
83584+ " protection");
83585+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
83586+}
83587+
83588 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
83589 {
83590 struct pid *pid;
83591diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
83592index 6917e8e..9909aeb 100644
83593--- a/kernel/pid_namespace.c
83594+++ b/kernel/pid_namespace.c
83595@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
83596 void __user *buffer, size_t *lenp, loff_t *ppos)
83597 {
83598 struct pid_namespace *pid_ns = task_active_pid_ns(current);
83599- struct ctl_table tmp = *table;
83600+ ctl_table_no_const tmp = *table;
83601
83602 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
83603 return -EPERM;
83604diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
83605index 42670e9..8719c2f 100644
83606--- a/kernel/posix-cpu-timers.c
83607+++ b/kernel/posix-cpu-timers.c
83608@@ -1636,14 +1636,14 @@ struct k_clock clock_posix_cpu = {
83609
83610 static __init int init_posix_cpu_timers(void)
83611 {
83612- struct k_clock process = {
83613+ static struct k_clock process = {
83614 .clock_getres = process_cpu_clock_getres,
83615 .clock_get = process_cpu_clock_get,
83616 .timer_create = process_cpu_timer_create,
83617 .nsleep = process_cpu_nsleep,
83618 .nsleep_restart = process_cpu_nsleep_restart,
83619 };
83620- struct k_clock thread = {
83621+ static struct k_clock thread = {
83622 .clock_getres = thread_cpu_clock_getres,
83623 .clock_get = thread_cpu_clock_get,
83624 .timer_create = thread_cpu_timer_create,
83625diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
83626index 424c2d4..679242f 100644
83627--- a/kernel/posix-timers.c
83628+++ b/kernel/posix-timers.c
83629@@ -43,6 +43,7 @@
83630 #include <linux/hash.h>
83631 #include <linux/posix-clock.h>
83632 #include <linux/posix-timers.h>
83633+#include <linux/grsecurity.h>
83634 #include <linux/syscalls.h>
83635 #include <linux/wait.h>
83636 #include <linux/workqueue.h>
83637@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
83638 * which we beg off on and pass to do_sys_settimeofday().
83639 */
83640
83641-static struct k_clock posix_clocks[MAX_CLOCKS];
83642+static struct k_clock *posix_clocks[MAX_CLOCKS];
83643
83644 /*
83645 * These ones are defined below.
83646@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
83647 */
83648 static __init int init_posix_timers(void)
83649 {
83650- struct k_clock clock_realtime = {
83651+ static struct k_clock clock_realtime = {
83652 .clock_getres = hrtimer_get_res,
83653 .clock_get = posix_clock_realtime_get,
83654 .clock_set = posix_clock_realtime_set,
83655@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
83656 .timer_get = common_timer_get,
83657 .timer_del = common_timer_del,
83658 };
83659- struct k_clock clock_monotonic = {
83660+ static struct k_clock clock_monotonic = {
83661 .clock_getres = hrtimer_get_res,
83662 .clock_get = posix_ktime_get_ts,
83663 .nsleep = common_nsleep,
83664@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
83665 .timer_get = common_timer_get,
83666 .timer_del = common_timer_del,
83667 };
83668- struct k_clock clock_monotonic_raw = {
83669+ static struct k_clock clock_monotonic_raw = {
83670 .clock_getres = hrtimer_get_res,
83671 .clock_get = posix_get_monotonic_raw,
83672 };
83673- struct k_clock clock_realtime_coarse = {
83674+ static struct k_clock clock_realtime_coarse = {
83675 .clock_getres = posix_get_coarse_res,
83676 .clock_get = posix_get_realtime_coarse,
83677 };
83678- struct k_clock clock_monotonic_coarse = {
83679+ static struct k_clock clock_monotonic_coarse = {
83680 .clock_getres = posix_get_coarse_res,
83681 .clock_get = posix_get_monotonic_coarse,
83682 };
83683- struct k_clock clock_tai = {
83684+ static struct k_clock clock_tai = {
83685 .clock_getres = hrtimer_get_res,
83686 .clock_get = posix_get_tai,
83687 .nsleep = common_nsleep,
83688@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
83689 .timer_get = common_timer_get,
83690 .timer_del = common_timer_del,
83691 };
83692- struct k_clock clock_boottime = {
83693+ static struct k_clock clock_boottime = {
83694 .clock_getres = hrtimer_get_res,
83695 .clock_get = posix_get_boottime,
83696 .nsleep = common_nsleep,
83697@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
83698 return;
83699 }
83700
83701- posix_clocks[clock_id] = *new_clock;
83702+ posix_clocks[clock_id] = new_clock;
83703 }
83704 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
83705
83706@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
83707 return (id & CLOCKFD_MASK) == CLOCKFD ?
83708 &clock_posix_dynamic : &clock_posix_cpu;
83709
83710- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
83711+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
83712 return NULL;
83713- return &posix_clocks[id];
83714+ return posix_clocks[id];
83715 }
83716
83717 static int common_timer_create(struct k_itimer *new_timer)
83718@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
83719 struct k_clock *kc = clockid_to_kclock(which_clock);
83720 struct k_itimer *new_timer;
83721 int error, new_timer_id;
83722- sigevent_t event;
83723+ sigevent_t event = { };
83724 int it_id_set = IT_ID_NOT_SET;
83725
83726 if (!kc)
83727@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
83728 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
83729 return -EFAULT;
83730
83731+ /* only the CLOCK_REALTIME clock can be set, all other clocks
83732+ have their clock_set fptr set to a nosettime dummy function
83733+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
83734+ call common_clock_set, which calls do_sys_settimeofday, which
83735+ we hook
83736+ */
83737+
83738 return kc->clock_set(which_clock, &new_tp);
83739 }
83740
83741diff --git a/kernel/power/process.c b/kernel/power/process.c
83742index 98088e0..aaf95c0 100644
83743--- a/kernel/power/process.c
83744+++ b/kernel/power/process.c
83745@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
83746 u64 elapsed_csecs64;
83747 unsigned int elapsed_csecs;
83748 bool wakeup = false;
83749+ bool timedout = false;
83750
83751 do_gettimeofday(&start);
83752
83753@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
83754
83755 while (true) {
83756 todo = 0;
83757+ if (time_after(jiffies, end_time))
83758+ timedout = true;
83759 read_lock(&tasklist_lock);
83760 do_each_thread(g, p) {
83761 if (p == current || !freeze_task(p))
83762 continue;
83763
83764- if (!freezer_should_skip(p))
83765+ if (!freezer_should_skip(p)) {
83766 todo++;
83767+ if (timedout) {
83768+ printk(KERN_ERR "Task refusing to freeze:\n");
83769+ sched_show_task(p);
83770+ }
83771+ }
83772 } while_each_thread(g, p);
83773 read_unlock(&tasklist_lock);
83774
83775@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
83776 todo += wq_busy;
83777 }
83778
83779- if (!todo || time_after(jiffies, end_time))
83780+ if (!todo || timedout)
83781 break;
83782
83783 if (pm_wakeup_pending()) {
83784diff --git a/kernel/printk.c b/kernel/printk.c
83785index d37d45c..ab918b3 100644
83786--- a/kernel/printk.c
83787+++ b/kernel/printk.c
83788@@ -390,6 +390,11 @@ static int check_syslog_permissions(int type, bool from_file)
83789 if (from_file && type != SYSLOG_ACTION_OPEN)
83790 return 0;
83791
83792+#ifdef CONFIG_GRKERNSEC_DMESG
83793+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
83794+ return -EPERM;
83795+#endif
83796+
83797 if (syslog_action_restricted(type)) {
83798 if (capable(CAP_SYSLOG))
83799 return 0;
83800diff --git a/kernel/profile.c b/kernel/profile.c
83801index 0bf4007..6234708 100644
83802--- a/kernel/profile.c
83803+++ b/kernel/profile.c
83804@@ -37,7 +37,7 @@ struct profile_hit {
83805 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
83806 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
83807
83808-static atomic_t *prof_buffer;
83809+static atomic_unchecked_t *prof_buffer;
83810 static unsigned long prof_len, prof_shift;
83811
83812 int prof_on __read_mostly;
83813@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
83814 hits[i].pc = 0;
83815 continue;
83816 }
83817- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
83818+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
83819 hits[i].hits = hits[i].pc = 0;
83820 }
83821 }
83822@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
83823 * Add the current hit(s) and flush the write-queue out
83824 * to the global buffer:
83825 */
83826- atomic_add(nr_hits, &prof_buffer[pc]);
83827+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
83828 for (i = 0; i < NR_PROFILE_HIT; ++i) {
83829- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
83830+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
83831 hits[i].pc = hits[i].hits = 0;
83832 }
83833 out:
83834@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
83835 {
83836 unsigned long pc;
83837 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
83838- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
83839+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
83840 }
83841 #endif /* !CONFIG_SMP */
83842
83843@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
83844 return -EFAULT;
83845 buf++; p++; count--; read++;
83846 }
83847- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
83848+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
83849 if (copy_to_user(buf, (void *)pnt, count))
83850 return -EFAULT;
83851 read += count;
83852@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
83853 }
83854 #endif
83855 profile_discard_flip_buffers();
83856- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
83857+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
83858 return count;
83859 }
83860
83861diff --git a/kernel/ptrace.c b/kernel/ptrace.c
83862index 335a7ae..3bbbceb 100644
83863--- a/kernel/ptrace.c
83864+++ b/kernel/ptrace.c
83865@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
83866 if (seize)
83867 flags |= PT_SEIZED;
83868 rcu_read_lock();
83869- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
83870+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
83871 flags |= PT_PTRACE_CAP;
83872 rcu_read_unlock();
83873 task->ptrace = flags;
83874@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
83875 break;
83876 return -EIO;
83877 }
83878- if (copy_to_user(dst, buf, retval))
83879+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
83880 return -EFAULT;
83881 copied += retval;
83882 src += retval;
83883@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
83884 bool seized = child->ptrace & PT_SEIZED;
83885 int ret = -EIO;
83886 siginfo_t siginfo, *si;
83887- void __user *datavp = (void __user *) data;
83888+ void __user *datavp = (__force void __user *) data;
83889 unsigned long __user *datalp = datavp;
83890 unsigned long flags;
83891
83892@@ -1011,14 +1011,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
83893 goto out;
83894 }
83895
83896+ if (gr_handle_ptrace(child, request)) {
83897+ ret = -EPERM;
83898+ goto out_put_task_struct;
83899+ }
83900+
83901 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
83902 ret = ptrace_attach(child, request, addr, data);
83903 /*
83904 * Some architectures need to do book-keeping after
83905 * a ptrace attach.
83906 */
83907- if (!ret)
83908+ if (!ret) {
83909 arch_ptrace_attach(child);
83910+ gr_audit_ptrace(child);
83911+ }
83912 goto out_put_task_struct;
83913 }
83914
83915@@ -1046,7 +1053,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
83916 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
83917 if (copied != sizeof(tmp))
83918 return -EIO;
83919- return put_user(tmp, (unsigned long __user *)data);
83920+ return put_user(tmp, (__force unsigned long __user *)data);
83921 }
83922
83923 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
83924@@ -1140,7 +1147,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
83925 }
83926
83927 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
83928- compat_long_t addr, compat_long_t data)
83929+ compat_ulong_t addr, compat_ulong_t data)
83930 {
83931 struct task_struct *child;
83932 long ret;
83933@@ -1156,14 +1163,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
83934 goto out;
83935 }
83936
83937+ if (gr_handle_ptrace(child, request)) {
83938+ ret = -EPERM;
83939+ goto out_put_task_struct;
83940+ }
83941+
83942 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
83943 ret = ptrace_attach(child, request, addr, data);
83944 /*
83945 * Some architectures need to do book-keeping after
83946 * a ptrace attach.
83947 */
83948- if (!ret)
83949+ if (!ret) {
83950 arch_ptrace_attach(child);
83951+ gr_audit_ptrace(child);
83952+ }
83953 goto out_put_task_struct;
83954 }
83955
83956diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
83957index 48ab703..07561d4 100644
83958--- a/kernel/rcupdate.c
83959+++ b/kernel/rcupdate.c
83960@@ -439,10 +439,10 @@ int rcu_jiffies_till_stall_check(void)
83961 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
83962 */
83963 if (till_stall_check < 3) {
83964- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
83965+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
83966 till_stall_check = 3;
83967 } else if (till_stall_check > 300) {
83968- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
83969+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
83970 till_stall_check = 300;
83971 }
83972 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
83973diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
83974index a0714a5..2ab5e34 100644
83975--- a/kernel/rcutiny.c
83976+++ b/kernel/rcutiny.c
83977@@ -46,7 +46,7 @@
83978 struct rcu_ctrlblk;
83979 static void invoke_rcu_callbacks(void);
83980 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
83981-static void rcu_process_callbacks(struct softirq_action *unused);
83982+static void rcu_process_callbacks(void);
83983 static void __call_rcu(struct rcu_head *head,
83984 void (*func)(struct rcu_head *rcu),
83985 struct rcu_ctrlblk *rcp);
83986@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
83987 rcu_is_callbacks_kthread()));
83988 }
83989
83990-static void rcu_process_callbacks(struct softirq_action *unused)
83991+static void rcu_process_callbacks(void)
83992 {
83993 __rcu_process_callbacks(&rcu_sched_ctrlblk);
83994 __rcu_process_callbacks(&rcu_bh_ctrlblk);
83995diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
83996index 8a23300..4255818 100644
83997--- a/kernel/rcutiny_plugin.h
83998+++ b/kernel/rcutiny_plugin.h
83999@@ -945,7 +945,7 @@ static int rcu_kthread(void *arg)
84000 have_rcu_kthread_work = morework;
84001 local_irq_restore(flags);
84002 if (work)
84003- rcu_process_callbacks(NULL);
84004+ rcu_process_callbacks();
84005 schedule_timeout_interruptible(1); /* Leave CPU for others. */
84006 }
84007
84008diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
84009index e1f3a8c..42c94a2 100644
84010--- a/kernel/rcutorture.c
84011+++ b/kernel/rcutorture.c
84012@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
84013 { 0 };
84014 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
84015 { 0 };
84016-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
84017-static atomic_t n_rcu_torture_alloc;
84018-static atomic_t n_rcu_torture_alloc_fail;
84019-static atomic_t n_rcu_torture_free;
84020-static atomic_t n_rcu_torture_mberror;
84021-static atomic_t n_rcu_torture_error;
84022+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
84023+static atomic_unchecked_t n_rcu_torture_alloc;
84024+static atomic_unchecked_t n_rcu_torture_alloc_fail;
84025+static atomic_unchecked_t n_rcu_torture_free;
84026+static atomic_unchecked_t n_rcu_torture_mberror;
84027+static atomic_unchecked_t n_rcu_torture_error;
84028 static long n_rcu_torture_barrier_error;
84029 static long n_rcu_torture_boost_ktrerror;
84030 static long n_rcu_torture_boost_rterror;
84031@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
84032
84033 spin_lock_bh(&rcu_torture_lock);
84034 if (list_empty(&rcu_torture_freelist)) {
84035- atomic_inc(&n_rcu_torture_alloc_fail);
84036+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
84037 spin_unlock_bh(&rcu_torture_lock);
84038 return NULL;
84039 }
84040- atomic_inc(&n_rcu_torture_alloc);
84041+ atomic_inc_unchecked(&n_rcu_torture_alloc);
84042 p = rcu_torture_freelist.next;
84043 list_del_init(p);
84044 spin_unlock_bh(&rcu_torture_lock);
84045@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
84046 static void
84047 rcu_torture_free(struct rcu_torture *p)
84048 {
84049- atomic_inc(&n_rcu_torture_free);
84050+ atomic_inc_unchecked(&n_rcu_torture_free);
84051 spin_lock_bh(&rcu_torture_lock);
84052 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
84053 spin_unlock_bh(&rcu_torture_lock);
84054@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
84055 i = rp->rtort_pipe_count;
84056 if (i > RCU_TORTURE_PIPE_LEN)
84057 i = RCU_TORTURE_PIPE_LEN;
84058- atomic_inc(&rcu_torture_wcount[i]);
84059+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
84060 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
84061 rp->rtort_mbtest = 0;
84062 rcu_torture_free(rp);
84063@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
84064 i = rp->rtort_pipe_count;
84065 if (i > RCU_TORTURE_PIPE_LEN)
84066 i = RCU_TORTURE_PIPE_LEN;
84067- atomic_inc(&rcu_torture_wcount[i]);
84068+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
84069 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
84070 rp->rtort_mbtest = 0;
84071 list_del(&rp->rtort_free);
84072@@ -990,7 +990,7 @@ rcu_torture_writer(void *arg)
84073 i = old_rp->rtort_pipe_count;
84074 if (i > RCU_TORTURE_PIPE_LEN)
84075 i = RCU_TORTURE_PIPE_LEN;
84076- atomic_inc(&rcu_torture_wcount[i]);
84077+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
84078 old_rp->rtort_pipe_count++;
84079 cur_ops->deferred_free(old_rp);
84080 }
84081@@ -1076,7 +1076,7 @@ static void rcu_torture_timer(unsigned long unused)
84082 return;
84083 }
84084 if (p->rtort_mbtest == 0)
84085- atomic_inc(&n_rcu_torture_mberror);
84086+ atomic_inc_unchecked(&n_rcu_torture_mberror);
84087 spin_lock(&rand_lock);
84088 cur_ops->read_delay(&rand);
84089 n_rcu_torture_timers++;
84090@@ -1146,7 +1146,7 @@ rcu_torture_reader(void *arg)
84091 continue;
84092 }
84093 if (p->rtort_mbtest == 0)
84094- atomic_inc(&n_rcu_torture_mberror);
84095+ atomic_inc_unchecked(&n_rcu_torture_mberror);
84096 cur_ops->read_delay(&rand);
84097 preempt_disable();
84098 pipe_count = p->rtort_pipe_count;
84099@@ -1209,11 +1209,11 @@ rcu_torture_printk(char *page)
84100 rcu_torture_current,
84101 rcu_torture_current_version,
84102 list_empty(&rcu_torture_freelist),
84103- atomic_read(&n_rcu_torture_alloc),
84104- atomic_read(&n_rcu_torture_alloc_fail),
84105- atomic_read(&n_rcu_torture_free));
84106+ atomic_read_unchecked(&n_rcu_torture_alloc),
84107+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
84108+ atomic_read_unchecked(&n_rcu_torture_free));
84109 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
84110- atomic_read(&n_rcu_torture_mberror),
84111+ atomic_read_unchecked(&n_rcu_torture_mberror),
84112 n_rcu_torture_boost_ktrerror,
84113 n_rcu_torture_boost_rterror);
84114 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
84115@@ -1232,14 +1232,14 @@ rcu_torture_printk(char *page)
84116 n_barrier_attempts,
84117 n_rcu_torture_barrier_error);
84118 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
84119- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
84120+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
84121 n_rcu_torture_barrier_error != 0 ||
84122 n_rcu_torture_boost_ktrerror != 0 ||
84123 n_rcu_torture_boost_rterror != 0 ||
84124 n_rcu_torture_boost_failure != 0 ||
84125 i > 1) {
84126 cnt += sprintf(&page[cnt], "!!! ");
84127- atomic_inc(&n_rcu_torture_error);
84128+ atomic_inc_unchecked(&n_rcu_torture_error);
84129 WARN_ON_ONCE(1);
84130 }
84131 cnt += sprintf(&page[cnt], "Reader Pipe: ");
84132@@ -1253,7 +1253,7 @@ rcu_torture_printk(char *page)
84133 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
84134 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
84135 cnt += sprintf(&page[cnt], " %d",
84136- atomic_read(&rcu_torture_wcount[i]));
84137+ atomic_read_unchecked(&rcu_torture_wcount[i]));
84138 }
84139 cnt += sprintf(&page[cnt], "\n");
84140 if (cur_ops->stats)
84141@@ -1962,7 +1962,7 @@ rcu_torture_cleanup(void)
84142
84143 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
84144
84145- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
84146+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
84147 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
84148 else if (n_online_successes != n_online_attempts ||
84149 n_offline_successes != n_offline_attempts)
84150@@ -2031,18 +2031,18 @@ rcu_torture_init(void)
84151
84152 rcu_torture_current = NULL;
84153 rcu_torture_current_version = 0;
84154- atomic_set(&n_rcu_torture_alloc, 0);
84155- atomic_set(&n_rcu_torture_alloc_fail, 0);
84156- atomic_set(&n_rcu_torture_free, 0);
84157- atomic_set(&n_rcu_torture_mberror, 0);
84158- atomic_set(&n_rcu_torture_error, 0);
84159+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
84160+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
84161+ atomic_set_unchecked(&n_rcu_torture_free, 0);
84162+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
84163+ atomic_set_unchecked(&n_rcu_torture_error, 0);
84164 n_rcu_torture_barrier_error = 0;
84165 n_rcu_torture_boost_ktrerror = 0;
84166 n_rcu_torture_boost_rterror = 0;
84167 n_rcu_torture_boost_failure = 0;
84168 n_rcu_torture_boosts = 0;
84169 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
84170- atomic_set(&rcu_torture_wcount[i], 0);
84171+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
84172 for_each_possible_cpu(cpu) {
84173 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
84174 per_cpu(rcu_torture_count, cpu)[i] = 0;
84175diff --git a/kernel/rcutree.c b/kernel/rcutree.c
84176index 3538001..e379e0b 100644
84177--- a/kernel/rcutree.c
84178+++ b/kernel/rcutree.c
84179@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
84180 rcu_prepare_for_idle(smp_processor_id());
84181 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
84182 smp_mb__before_atomic_inc(); /* See above. */
84183- atomic_inc(&rdtp->dynticks);
84184+ atomic_inc_unchecked(&rdtp->dynticks);
84185 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
84186- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
84187+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
84188
84189 /*
84190 * It is illegal to enter an extended quiescent state while
84191@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
84192 int user)
84193 {
84194 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
84195- atomic_inc(&rdtp->dynticks);
84196+ atomic_inc_unchecked(&rdtp->dynticks);
84197 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
84198 smp_mb__after_atomic_inc(); /* See above. */
84199- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
84200+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
84201 rcu_cleanup_after_idle(smp_processor_id());
84202 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
84203 if (!user && !is_idle_task(current)) {
84204@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
84205 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
84206
84207 if (rdtp->dynticks_nmi_nesting == 0 &&
84208- (atomic_read(&rdtp->dynticks) & 0x1))
84209+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
84210 return;
84211 rdtp->dynticks_nmi_nesting++;
84212 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
84213- atomic_inc(&rdtp->dynticks);
84214+ atomic_inc_unchecked(&rdtp->dynticks);
84215 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
84216 smp_mb__after_atomic_inc(); /* See above. */
84217- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
84218+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
84219 }
84220
84221 /**
84222@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
84223 return;
84224 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
84225 smp_mb__before_atomic_inc(); /* See above. */
84226- atomic_inc(&rdtp->dynticks);
84227+ atomic_inc_unchecked(&rdtp->dynticks);
84228 smp_mb__after_atomic_inc(); /* Force delay to next write. */
84229- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
84230+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
84231 }
84232
84233 /**
84234@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
84235 int ret;
84236
84237 preempt_disable();
84238- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
84239+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
84240 preempt_enable();
84241 return ret;
84242 }
84243@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
84244 */
84245 static int dyntick_save_progress_counter(struct rcu_data *rdp)
84246 {
84247- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
84248+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
84249 return (rdp->dynticks_snap & 0x1) == 0;
84250 }
84251
84252@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
84253 unsigned int curr;
84254 unsigned int snap;
84255
84256- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
84257+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
84258 snap = (unsigned int)rdp->dynticks_snap;
84259
84260 /*
84261@@ -1440,9 +1440,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
84262 rdp = this_cpu_ptr(rsp->rda);
84263 rcu_preempt_check_blocked_tasks(rnp);
84264 rnp->qsmask = rnp->qsmaskinit;
84265- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
84266+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
84267 WARN_ON_ONCE(rnp->completed != rsp->completed);
84268- ACCESS_ONCE(rnp->completed) = rsp->completed;
84269+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
84270 if (rnp == rdp->mynode)
84271 rcu_start_gp_per_cpu(rsp, rnp, rdp);
84272 rcu_preempt_boost_start_gp(rnp);
84273@@ -1524,7 +1524,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
84274 */
84275 rcu_for_each_node_breadth_first(rsp, rnp) {
84276 raw_spin_lock_irq(&rnp->lock);
84277- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
84278+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
84279 rdp = this_cpu_ptr(rsp->rda);
84280 if (rnp == rdp->mynode)
84281 __rcu_process_gp_end(rsp, rnp, rdp);
84282@@ -1855,7 +1855,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
84283 rsp->qlen += rdp->qlen;
84284 rdp->n_cbs_orphaned += rdp->qlen;
84285 rdp->qlen_lazy = 0;
84286- ACCESS_ONCE(rdp->qlen) = 0;
84287+ ACCESS_ONCE_RW(rdp->qlen) = 0;
84288 }
84289
84290 /*
84291@@ -2101,7 +2101,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
84292 }
84293 smp_mb(); /* List handling before counting for rcu_barrier(). */
84294 rdp->qlen_lazy -= count_lazy;
84295- ACCESS_ONCE(rdp->qlen) -= count;
84296+ ACCESS_ONCE_RW(rdp->qlen) -= count;
84297 rdp->n_cbs_invoked += count;
84298
84299 /* Reinstate batch limit if we have worked down the excess. */
84300@@ -2295,7 +2295,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
84301 /*
84302 * Do RCU core processing for the current CPU.
84303 */
84304-static void rcu_process_callbacks(struct softirq_action *unused)
84305+static void rcu_process_callbacks(void)
84306 {
84307 struct rcu_state *rsp;
84308
84309@@ -2419,7 +2419,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
84310 local_irq_restore(flags);
84311 return;
84312 }
84313- ACCESS_ONCE(rdp->qlen)++;
84314+ ACCESS_ONCE_RW(rdp->qlen)++;
84315 if (lazy)
84316 rdp->qlen_lazy++;
84317 else
84318@@ -2628,11 +2628,11 @@ void synchronize_sched_expedited(void)
84319 * counter wrap on a 32-bit system. Quite a few more CPUs would of
84320 * course be required on a 64-bit system.
84321 */
84322- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
84323+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
84324 (ulong)atomic_long_read(&rsp->expedited_done) +
84325 ULONG_MAX / 8)) {
84326 synchronize_sched();
84327- atomic_long_inc(&rsp->expedited_wrap);
84328+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
84329 return;
84330 }
84331
84332@@ -2640,7 +2640,7 @@ void synchronize_sched_expedited(void)
84333 * Take a ticket. Note that atomic_inc_return() implies a
84334 * full memory barrier.
84335 */
84336- snap = atomic_long_inc_return(&rsp->expedited_start);
84337+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
84338 firstsnap = snap;
84339 get_online_cpus();
84340 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
84341@@ -2653,14 +2653,14 @@ void synchronize_sched_expedited(void)
84342 synchronize_sched_expedited_cpu_stop,
84343 NULL) == -EAGAIN) {
84344 put_online_cpus();
84345- atomic_long_inc(&rsp->expedited_tryfail);
84346+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
84347
84348 /* Check to see if someone else did our work for us. */
84349 s = atomic_long_read(&rsp->expedited_done);
84350 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
84351 /* ensure test happens before caller kfree */
84352 smp_mb__before_atomic_inc(); /* ^^^ */
84353- atomic_long_inc(&rsp->expedited_workdone1);
84354+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
84355 return;
84356 }
84357
84358@@ -2669,7 +2669,7 @@ void synchronize_sched_expedited(void)
84359 udelay(trycount * num_online_cpus());
84360 } else {
84361 wait_rcu_gp(call_rcu_sched);
84362- atomic_long_inc(&rsp->expedited_normal);
84363+ atomic_long_inc_unchecked(&rsp->expedited_normal);
84364 return;
84365 }
84366
84367@@ -2678,7 +2678,7 @@ void synchronize_sched_expedited(void)
84368 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
84369 /* ensure test happens before caller kfree */
84370 smp_mb__before_atomic_inc(); /* ^^^ */
84371- atomic_long_inc(&rsp->expedited_workdone2);
84372+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
84373 return;
84374 }
84375
84376@@ -2690,10 +2690,10 @@ void synchronize_sched_expedited(void)
84377 * period works for us.
84378 */
84379 get_online_cpus();
84380- snap = atomic_long_read(&rsp->expedited_start);
84381+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
84382 smp_mb(); /* ensure read is before try_stop_cpus(). */
84383 }
84384- atomic_long_inc(&rsp->expedited_stoppedcpus);
84385+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
84386
84387 /*
84388 * Everyone up to our most recent fetch is covered by our grace
84389@@ -2702,16 +2702,16 @@ void synchronize_sched_expedited(void)
84390 * than we did already did their update.
84391 */
84392 do {
84393- atomic_long_inc(&rsp->expedited_done_tries);
84394+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
84395 s = atomic_long_read(&rsp->expedited_done);
84396 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
84397 /* ensure test happens before caller kfree */
84398 smp_mb__before_atomic_inc(); /* ^^^ */
84399- atomic_long_inc(&rsp->expedited_done_lost);
84400+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
84401 break;
84402 }
84403 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
84404- atomic_long_inc(&rsp->expedited_done_exit);
84405+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
84406
84407 put_online_cpus();
84408 }
84409@@ -2893,7 +2893,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
84410 * ACCESS_ONCE() to prevent the compiler from speculating
84411 * the increment to precede the early-exit check.
84412 */
84413- ACCESS_ONCE(rsp->n_barrier_done)++;
84414+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
84415 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
84416 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
84417 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
84418@@ -2943,7 +2943,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
84419
84420 /* Increment ->n_barrier_done to prevent duplicate work. */
84421 smp_mb(); /* Keep increment after above mechanism. */
84422- ACCESS_ONCE(rsp->n_barrier_done)++;
84423+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
84424 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
84425 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
84426 smp_mb(); /* Keep increment before caller's subsequent code. */
84427@@ -2988,10 +2988,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
84428 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
84429 init_callback_list(rdp);
84430 rdp->qlen_lazy = 0;
84431- ACCESS_ONCE(rdp->qlen) = 0;
84432+ ACCESS_ONCE_RW(rdp->qlen) = 0;
84433 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
84434 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
84435- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
84436+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
84437 rdp->cpu = cpu;
84438 rdp->rsp = rsp;
84439 rcu_boot_init_nocb_percpu_data(rdp);
84440@@ -3024,8 +3024,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
84441 rdp->blimit = blimit;
84442 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
84443 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
84444- atomic_set(&rdp->dynticks->dynticks,
84445- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
84446+ atomic_set_unchecked(&rdp->dynticks->dynticks,
84447+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
84448 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
84449
84450 /* Add CPU to rcu_node bitmasks. */
84451@@ -3120,7 +3120,7 @@ static int __init rcu_spawn_gp_kthread(void)
84452 struct task_struct *t;
84453
84454 for_each_rcu_flavor(rsp) {
84455- t = kthread_run(rcu_gp_kthread, rsp, rsp->name);
84456+ t = kthread_run(rcu_gp_kthread, rsp, "%s", rsp->name);
84457 BUG_ON(IS_ERR(t));
84458 rnp = rcu_get_root(rsp);
84459 raw_spin_lock_irqsave(&rnp->lock, flags);
84460diff --git a/kernel/rcutree.h b/kernel/rcutree.h
84461index 4df5034..5ee93f2 100644
84462--- a/kernel/rcutree.h
84463+++ b/kernel/rcutree.h
84464@@ -87,7 +87,7 @@ struct rcu_dynticks {
84465 long long dynticks_nesting; /* Track irq/process nesting level. */
84466 /* Process level is worth LLONG_MAX/2. */
84467 int dynticks_nmi_nesting; /* Track NMI nesting level. */
84468- atomic_t dynticks; /* Even value for idle, else odd. */
84469+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
84470 #ifdef CONFIG_RCU_FAST_NO_HZ
84471 bool all_lazy; /* Are all CPU's CBs lazy? */
84472 unsigned long nonlazy_posted;
84473@@ -414,17 +414,17 @@ struct rcu_state {
84474 /* _rcu_barrier(). */
84475 /* End of fields guarded by barrier_mutex. */
84476
84477- atomic_long_t expedited_start; /* Starting ticket. */
84478- atomic_long_t expedited_done; /* Done ticket. */
84479- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
84480- atomic_long_t expedited_tryfail; /* # acquisition failures. */
84481- atomic_long_t expedited_workdone1; /* # done by others #1. */
84482- atomic_long_t expedited_workdone2; /* # done by others #2. */
84483- atomic_long_t expedited_normal; /* # fallbacks to normal. */
84484- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
84485- atomic_long_t expedited_done_tries; /* # tries to update _done. */
84486- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
84487- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
84488+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
84489+ atomic_long_t expedited_done; /* Done ticket. */
84490+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
84491+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
84492+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
84493+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
84494+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
84495+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
84496+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
84497+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
84498+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
84499
84500 unsigned long jiffies_force_qs; /* Time at which to invoke */
84501 /* force_quiescent_state(). */
84502diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
84503index 3db5a37..b395fb35 100644
84504--- a/kernel/rcutree_plugin.h
84505+++ b/kernel/rcutree_plugin.h
84506@@ -903,7 +903,7 @@ void synchronize_rcu_expedited(void)
84507
84508 /* Clean up and exit. */
84509 smp_mb(); /* ensure expedited GP seen before counter increment. */
84510- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
84511+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
84512 unlock_mb_ret:
84513 mutex_unlock(&sync_rcu_preempt_exp_mutex);
84514 mb_ret:
84515@@ -1451,7 +1451,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
84516 free_cpumask_var(cm);
84517 }
84518
84519-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
84520+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
84521 .store = &rcu_cpu_kthread_task,
84522 .thread_should_run = rcu_cpu_kthread_should_run,
84523 .thread_fn = rcu_cpu_kthread,
84524@@ -1916,7 +1916,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
84525 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
84526 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
84527 cpu, ticks_value, ticks_title,
84528- atomic_read(&rdtp->dynticks) & 0xfff,
84529+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
84530 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
84531 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
84532 fast_no_hz);
84533@@ -2079,7 +2079,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
84534
84535 /* Enqueue the callback on the nocb list and update counts. */
84536 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
84537- ACCESS_ONCE(*old_rhpp) = rhp;
84538+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
84539 atomic_long_add(rhcount, &rdp->nocb_q_count);
84540 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
84541
84542@@ -2219,12 +2219,12 @@ static int rcu_nocb_kthread(void *arg)
84543 * Extract queued callbacks, update counts, and wait
84544 * for a grace period to elapse.
84545 */
84546- ACCESS_ONCE(rdp->nocb_head) = NULL;
84547+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
84548 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
84549 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
84550 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
84551- ACCESS_ONCE(rdp->nocb_p_count) += c;
84552- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
84553+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
84554+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
84555 rcu_nocb_wait_gp(rdp);
84556
84557 /* Each pass through the following loop invokes a callback. */
84558@@ -2246,8 +2246,8 @@ static int rcu_nocb_kthread(void *arg)
84559 list = next;
84560 }
84561 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
84562- ACCESS_ONCE(rdp->nocb_p_count) -= c;
84563- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
84564+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
84565+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
84566 rdp->n_nocbs_invoked += c;
84567 }
84568 return 0;
84569@@ -2274,7 +2274,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
84570 t = kthread_run(rcu_nocb_kthread, rdp,
84571 "rcuo%c/%d", rsp->abbr, cpu);
84572 BUG_ON(IS_ERR(t));
84573- ACCESS_ONCE(rdp->nocb_kthread) = t;
84574+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
84575 }
84576 }
84577
84578diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
84579index cf6c174..a8f4b50 100644
84580--- a/kernel/rcutree_trace.c
84581+++ b/kernel/rcutree_trace.c
84582@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
84583 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
84584 rdp->passed_quiesce, rdp->qs_pending);
84585 seq_printf(m, " dt=%d/%llx/%d df=%lu",
84586- atomic_read(&rdp->dynticks->dynticks),
84587+ atomic_read_unchecked(&rdp->dynticks->dynticks),
84588 rdp->dynticks->dynticks_nesting,
84589 rdp->dynticks->dynticks_nmi_nesting,
84590 rdp->dynticks_fqs);
84591@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
84592 struct rcu_state *rsp = (struct rcu_state *)m->private;
84593
84594 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",
84595- atomic_long_read(&rsp->expedited_start),
84596+ atomic_long_read_unchecked(&rsp->expedited_start),
84597 atomic_long_read(&rsp->expedited_done),
84598- atomic_long_read(&rsp->expedited_wrap),
84599- atomic_long_read(&rsp->expedited_tryfail),
84600- atomic_long_read(&rsp->expedited_workdone1),
84601- atomic_long_read(&rsp->expedited_workdone2),
84602- atomic_long_read(&rsp->expedited_normal),
84603- atomic_long_read(&rsp->expedited_stoppedcpus),
84604- atomic_long_read(&rsp->expedited_done_tries),
84605- atomic_long_read(&rsp->expedited_done_lost),
84606- atomic_long_read(&rsp->expedited_done_exit));
84607+ atomic_long_read_unchecked(&rsp->expedited_wrap),
84608+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
84609+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
84610+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
84611+ atomic_long_read_unchecked(&rsp->expedited_normal),
84612+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
84613+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
84614+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
84615+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
84616 return 0;
84617 }
84618
84619diff --git a/kernel/resource.c b/kernel/resource.c
84620index d738698..5f8e60a 100644
84621--- a/kernel/resource.c
84622+++ b/kernel/resource.c
84623@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
84624
84625 static int __init ioresources_init(void)
84626 {
84627+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84628+#ifdef CONFIG_GRKERNSEC_PROC_USER
84629+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
84630+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
84631+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84632+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
84633+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
84634+#endif
84635+#else
84636 proc_create("ioports", 0, NULL, &proc_ioports_operations);
84637 proc_create("iomem", 0, NULL, &proc_iomem_operations);
84638+#endif
84639 return 0;
84640 }
84641 __initcall(ioresources_init);
84642diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
84643index 1d96dd0..994ff19 100644
84644--- a/kernel/rtmutex-tester.c
84645+++ b/kernel/rtmutex-tester.c
84646@@ -22,7 +22,7 @@
84647 #define MAX_RT_TEST_MUTEXES 8
84648
84649 static spinlock_t rttest_lock;
84650-static atomic_t rttest_event;
84651+static atomic_unchecked_t rttest_event;
84652
84653 struct test_thread_data {
84654 int opcode;
84655@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84656
84657 case RTTEST_LOCKCONT:
84658 td->mutexes[td->opdata] = 1;
84659- td->event = atomic_add_return(1, &rttest_event);
84660+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84661 return 0;
84662
84663 case RTTEST_RESET:
84664@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84665 return 0;
84666
84667 case RTTEST_RESETEVENT:
84668- atomic_set(&rttest_event, 0);
84669+ atomic_set_unchecked(&rttest_event, 0);
84670 return 0;
84671
84672 default:
84673@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84674 return ret;
84675
84676 td->mutexes[id] = 1;
84677- td->event = atomic_add_return(1, &rttest_event);
84678+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84679 rt_mutex_lock(&mutexes[id]);
84680- td->event = atomic_add_return(1, &rttest_event);
84681+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84682 td->mutexes[id] = 4;
84683 return 0;
84684
84685@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84686 return ret;
84687
84688 td->mutexes[id] = 1;
84689- td->event = atomic_add_return(1, &rttest_event);
84690+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84691 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
84692- td->event = atomic_add_return(1, &rttest_event);
84693+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84694 td->mutexes[id] = ret ? 0 : 4;
84695 return ret ? -EINTR : 0;
84696
84697@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84698 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
84699 return ret;
84700
84701- td->event = atomic_add_return(1, &rttest_event);
84702+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84703 rt_mutex_unlock(&mutexes[id]);
84704- td->event = atomic_add_return(1, &rttest_event);
84705+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84706 td->mutexes[id] = 0;
84707 return 0;
84708
84709@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
84710 break;
84711
84712 td->mutexes[dat] = 2;
84713- td->event = atomic_add_return(1, &rttest_event);
84714+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84715 break;
84716
84717 default:
84718@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
84719 return;
84720
84721 td->mutexes[dat] = 3;
84722- td->event = atomic_add_return(1, &rttest_event);
84723+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84724 break;
84725
84726 case RTTEST_LOCKNOWAIT:
84727@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
84728 return;
84729
84730 td->mutexes[dat] = 1;
84731- td->event = atomic_add_return(1, &rttest_event);
84732+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84733 return;
84734
84735 default:
84736diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
84737index 64de5f8..7735e12 100644
84738--- a/kernel/sched/auto_group.c
84739+++ b/kernel/sched/auto_group.c
84740@@ -11,7 +11,7 @@
84741
84742 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
84743 static struct autogroup autogroup_default;
84744-static atomic_t autogroup_seq_nr;
84745+static atomic_unchecked_t autogroup_seq_nr;
84746
84747 void __init autogroup_init(struct task_struct *init_task)
84748 {
84749@@ -81,7 +81,7 @@ static inline struct autogroup *autogroup_create(void)
84750
84751 kref_init(&ag->kref);
84752 init_rwsem(&ag->lock);
84753- ag->id = atomic_inc_return(&autogroup_seq_nr);
84754+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
84755 ag->tg = tg;
84756 #ifdef CONFIG_RT_GROUP_SCHED
84757 /*
84758diff --git a/kernel/sched/core.c b/kernel/sched/core.c
84759index e8b3350..d83d44e 100644
84760--- a/kernel/sched/core.c
84761+++ b/kernel/sched/core.c
84762@@ -3440,7 +3440,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
84763 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
84764 * positive (at least 1, or number of jiffies left till timeout) if completed.
84765 */
84766-long __sched
84767+long __sched __intentional_overflow(-1)
84768 wait_for_completion_interruptible_timeout(struct completion *x,
84769 unsigned long timeout)
84770 {
84771@@ -3457,7 +3457,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
84772 *
84773 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
84774 */
84775-int __sched wait_for_completion_killable(struct completion *x)
84776+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
84777 {
84778 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
84779 if (t == -ERESTARTSYS)
84780@@ -3478,7 +3478,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
84781 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
84782 * positive (at least 1, or number of jiffies left till timeout) if completed.
84783 */
84784-long __sched
84785+long __sched __intentional_overflow(-1)
84786 wait_for_completion_killable_timeout(struct completion *x,
84787 unsigned long timeout)
84788 {
84789@@ -3704,6 +3704,8 @@ int can_nice(const struct task_struct *p, const int nice)
84790 /* convert nice value [19,-20] to rlimit style value [1,40] */
84791 int nice_rlim = 20 - nice;
84792
84793+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
84794+
84795 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
84796 capable(CAP_SYS_NICE));
84797 }
84798@@ -3737,7 +3739,8 @@ SYSCALL_DEFINE1(nice, int, increment)
84799 if (nice > 19)
84800 nice = 19;
84801
84802- if (increment < 0 && !can_nice(current, nice))
84803+ if (increment < 0 && (!can_nice(current, nice) ||
84804+ gr_handle_chroot_nice()))
84805 return -EPERM;
84806
84807 retval = security_task_setnice(current, nice);
84808@@ -3891,6 +3894,7 @@ recheck:
84809 unsigned long rlim_rtprio =
84810 task_rlimit(p, RLIMIT_RTPRIO);
84811
84812+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
84813 /* can't set/change the rt policy */
84814 if (policy != p->policy && !rlim_rtprio)
84815 return -EPERM;
84816@@ -4988,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
84817
84818 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
84819
84820-static struct ctl_table sd_ctl_dir[] = {
84821+static ctl_table_no_const sd_ctl_dir[] __read_only = {
84822 {
84823 .procname = "sched_domain",
84824 .mode = 0555,
84825@@ -5005,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
84826 {}
84827 };
84828
84829-static struct ctl_table *sd_alloc_ctl_entry(int n)
84830+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
84831 {
84832- struct ctl_table *entry =
84833+ ctl_table_no_const *entry =
84834 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
84835
84836 return entry;
84837 }
84838
84839-static void sd_free_ctl_entry(struct ctl_table **tablep)
84840+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
84841 {
84842- struct ctl_table *entry;
84843+ ctl_table_no_const *entry;
84844
84845 /*
84846 * In the intermediate directories, both the child directory and
84847@@ -5023,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
84848 * will always be set. In the lowest directory the names are
84849 * static strings and all have proc handlers.
84850 */
84851- for (entry = *tablep; entry->mode; entry++) {
84852- if (entry->child)
84853- sd_free_ctl_entry(&entry->child);
84854+ for (entry = tablep; entry->mode; entry++) {
84855+ if (entry->child) {
84856+ sd_free_ctl_entry(entry->child);
84857+ pax_open_kernel();
84858+ entry->child = NULL;
84859+ pax_close_kernel();
84860+ }
84861 if (entry->proc_handler == NULL)
84862 kfree(entry->procname);
84863 }
84864
84865- kfree(*tablep);
84866- *tablep = NULL;
84867+ kfree(tablep);
84868 }
84869
84870 static int min_load_idx = 0;
84871 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
84872
84873 static void
84874-set_table_entry(struct ctl_table *entry,
84875+set_table_entry(ctl_table_no_const *entry,
84876 const char *procname, void *data, int maxlen,
84877 umode_t mode, proc_handler *proc_handler,
84878 bool load_idx)
84879@@ -5058,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
84880 static struct ctl_table *
84881 sd_alloc_ctl_domain_table(struct sched_domain *sd)
84882 {
84883- struct ctl_table *table = sd_alloc_ctl_entry(13);
84884+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
84885
84886 if (table == NULL)
84887 return NULL;
84888@@ -5093,9 +5100,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
84889 return table;
84890 }
84891
84892-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
84893+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
84894 {
84895- struct ctl_table *entry, *table;
84896+ ctl_table_no_const *entry, *table;
84897 struct sched_domain *sd;
84898 int domain_num = 0, i;
84899 char buf[32];
84900@@ -5122,11 +5129,13 @@ static struct ctl_table_header *sd_sysctl_header;
84901 static void register_sched_domain_sysctl(void)
84902 {
84903 int i, cpu_num = num_possible_cpus();
84904- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
84905+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
84906 char buf[32];
84907
84908 WARN_ON(sd_ctl_dir[0].child);
84909+ pax_open_kernel();
84910 sd_ctl_dir[0].child = entry;
84911+ pax_close_kernel();
84912
84913 if (entry == NULL)
84914 return;
84915@@ -5149,8 +5158,12 @@ static void unregister_sched_domain_sysctl(void)
84916 if (sd_sysctl_header)
84917 unregister_sysctl_table(sd_sysctl_header);
84918 sd_sysctl_header = NULL;
84919- if (sd_ctl_dir[0].child)
84920- sd_free_ctl_entry(&sd_ctl_dir[0].child);
84921+ if (sd_ctl_dir[0].child) {
84922+ sd_free_ctl_entry(sd_ctl_dir[0].child);
84923+ pax_open_kernel();
84924+ sd_ctl_dir[0].child = NULL;
84925+ pax_close_kernel();
84926+ }
84927 }
84928 #else
84929 static void register_sched_domain_sysctl(void)
84930@@ -5249,7 +5262,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
84931 * happens before everything else. This has to be lower priority than
84932 * the notifier in the perf_event subsystem, though.
84933 */
84934-static struct notifier_block __cpuinitdata migration_notifier = {
84935+static struct notifier_block migration_notifier = {
84936 .notifier_call = migration_call,
84937 .priority = CPU_PRI_MIGRATION,
84938 };
84939diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
84940index 03b73be..9422b9f 100644
84941--- a/kernel/sched/fair.c
84942+++ b/kernel/sched/fair.c
84943@@ -831,7 +831,7 @@ void task_numa_fault(int node, int pages, bool migrated)
84944
84945 static void reset_ptenuma_scan(struct task_struct *p)
84946 {
84947- ACCESS_ONCE(p->mm->numa_scan_seq)++;
84948+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
84949 p->mm->numa_scan_offset = 0;
84950 }
84951
84952@@ -5687,7 +5687,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
84953 * run_rebalance_domains is triggered when needed from the scheduler tick.
84954 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
84955 */
84956-static void run_rebalance_domains(struct softirq_action *h)
84957+static void run_rebalance_domains(void)
84958 {
84959 int this_cpu = smp_processor_id();
84960 struct rq *this_rq = cpu_rq(this_cpu);
84961diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
84962index ce39224d..0e09343 100644
84963--- a/kernel/sched/sched.h
84964+++ b/kernel/sched/sched.h
84965@@ -1009,7 +1009,7 @@ struct sched_class {
84966 #ifdef CONFIG_FAIR_GROUP_SCHED
84967 void (*task_move_group) (struct task_struct *p, int on_rq);
84968 #endif
84969-};
84970+} __do_const;
84971
84972 #define sched_class_highest (&stop_sched_class)
84973 #define for_each_class(class) \
84974diff --git a/kernel/signal.c b/kernel/signal.c
84975index 113411b..20d0a99 100644
84976--- a/kernel/signal.c
84977+++ b/kernel/signal.c
84978@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
84979
84980 int print_fatal_signals __read_mostly;
84981
84982-static void __user *sig_handler(struct task_struct *t, int sig)
84983+static __sighandler_t sig_handler(struct task_struct *t, int sig)
84984 {
84985 return t->sighand->action[sig - 1].sa.sa_handler;
84986 }
84987
84988-static int sig_handler_ignored(void __user *handler, int sig)
84989+static int sig_handler_ignored(__sighandler_t handler, int sig)
84990 {
84991 /* Is it explicitly or implicitly ignored? */
84992 return handler == SIG_IGN ||
84993@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
84994
84995 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
84996 {
84997- void __user *handler;
84998+ __sighandler_t handler;
84999
85000 handler = sig_handler(t, sig);
85001
85002@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
85003 atomic_inc(&user->sigpending);
85004 rcu_read_unlock();
85005
85006+ if (!override_rlimit)
85007+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
85008+
85009 if (override_rlimit ||
85010 atomic_read(&user->sigpending) <=
85011 task_rlimit(t, RLIMIT_SIGPENDING)) {
85012@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
85013
85014 int unhandled_signal(struct task_struct *tsk, int sig)
85015 {
85016- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
85017+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
85018 if (is_global_init(tsk))
85019 return 1;
85020 if (handler != SIG_IGN && handler != SIG_DFL)
85021@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
85022 }
85023 }
85024
85025+ /* allow glibc communication via tgkill to other threads in our
85026+ thread group */
85027+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
85028+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
85029+ && gr_handle_signal(t, sig))
85030+ return -EPERM;
85031+
85032 return security_task_kill(t, info, sig, 0);
85033 }
85034
85035@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
85036 return send_signal(sig, info, p, 1);
85037 }
85038
85039-static int
85040+int
85041 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
85042 {
85043 return send_signal(sig, info, t, 0);
85044@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
85045 unsigned long int flags;
85046 int ret, blocked, ignored;
85047 struct k_sigaction *action;
85048+ int is_unhandled = 0;
85049
85050 spin_lock_irqsave(&t->sighand->siglock, flags);
85051 action = &t->sighand->action[sig-1];
85052@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
85053 }
85054 if (action->sa.sa_handler == SIG_DFL)
85055 t->signal->flags &= ~SIGNAL_UNKILLABLE;
85056+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
85057+ is_unhandled = 1;
85058 ret = specific_send_sig_info(sig, info, t);
85059 spin_unlock_irqrestore(&t->sighand->siglock, flags);
85060
85061+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
85062+ normal operation */
85063+ if (is_unhandled) {
85064+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
85065+ gr_handle_crash(t, sig);
85066+ }
85067+
85068 return ret;
85069 }
85070
85071@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
85072 ret = check_kill_permission(sig, info, p);
85073 rcu_read_unlock();
85074
85075- if (!ret && sig)
85076+ if (!ret && sig) {
85077 ret = do_send_sig_info(sig, info, p, true);
85078+ if (!ret)
85079+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
85080+ }
85081
85082 return ret;
85083 }
85084@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
85085 int error = -ESRCH;
85086
85087 rcu_read_lock();
85088- p = find_task_by_vpid(pid);
85089+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
85090+ /* allow glibc communication via tgkill to other threads in our
85091+ thread group */
85092+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
85093+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
85094+ p = find_task_by_vpid_unrestricted(pid);
85095+ else
85096+#endif
85097+ p = find_task_by_vpid(pid);
85098 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
85099 error = check_kill_permission(sig, info, p);
85100 /*
85101@@ -3219,6 +3250,16 @@ int __save_altstack(stack_t __user *uss, unsigned long sp)
85102 __put_user(t->sas_ss_size, &uss->ss_size);
85103 }
85104
85105+#ifdef CONFIG_X86
85106+void __save_altstack_ex(stack_t __user *uss, unsigned long sp)
85107+{
85108+ struct task_struct *t = current;
85109+ put_user_ex((void __user *)t->sas_ss_sp, &uss->ss_sp);
85110+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
85111+ put_user_ex(t->sas_ss_size, &uss->ss_size);
85112+}
85113+#endif
85114+
85115 #ifdef CONFIG_COMPAT
85116 COMPAT_SYSCALL_DEFINE2(sigaltstack,
85117 const compat_stack_t __user *, uss_ptr,
85118@@ -3240,8 +3281,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
85119 }
85120 seg = get_fs();
85121 set_fs(KERNEL_DS);
85122- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
85123- (stack_t __force __user *) &uoss,
85124+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
85125+ (stack_t __force_user *) &uoss,
85126 compat_user_stack_pointer());
85127 set_fs(seg);
85128 if (ret >= 0 && uoss_ptr) {
85129@@ -3268,6 +3309,16 @@ int __compat_save_altstack(compat_stack_t __user *uss, unsigned long sp)
85130 __put_user(sas_ss_flags(sp), &uss->ss_flags) |
85131 __put_user(t->sas_ss_size, &uss->ss_size);
85132 }
85133+
85134+#ifdef CONFIG_X86
85135+void __compat_save_altstack_ex(compat_stack_t __user *uss, unsigned long sp)
85136+{
85137+ struct task_struct *t = current;
85138+ put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &uss->ss_sp);
85139+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
85140+ put_user_ex(t->sas_ss_size, &uss->ss_size);
85141+}
85142+#endif
85143 #endif
85144
85145 #ifdef __ARCH_WANT_SYS_SIGPENDING
85146diff --git a/kernel/smp.c b/kernel/smp.c
85147index 4dba0f7..fe9f773 100644
85148--- a/kernel/smp.c
85149+++ b/kernel/smp.c
85150@@ -73,7 +73,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
85151 return NOTIFY_OK;
85152 }
85153
85154-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
85155+static struct notifier_block hotplug_cfd_notifier = {
85156 .notifier_call = hotplug_cfd,
85157 };
85158
85159diff --git a/kernel/smpboot.c b/kernel/smpboot.c
85160index 02fc5c9..e54c335 100644
85161--- a/kernel/smpboot.c
85162+++ b/kernel/smpboot.c
85163@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
85164 }
85165 smpboot_unpark_thread(plug_thread, cpu);
85166 }
85167- list_add(&plug_thread->list, &hotplug_threads);
85168+ pax_list_add(&plug_thread->list, &hotplug_threads);
85169 out:
85170 mutex_unlock(&smpboot_threads_lock);
85171 return ret;
85172@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
85173 {
85174 get_online_cpus();
85175 mutex_lock(&smpboot_threads_lock);
85176- list_del(&plug_thread->list);
85177+ pax_list_del(&plug_thread->list);
85178 smpboot_destroy_threads(plug_thread);
85179 mutex_unlock(&smpboot_threads_lock);
85180 put_online_cpus();
85181diff --git a/kernel/softirq.c b/kernel/softirq.c
85182index 3d6833f..da6d93d 100644
85183--- a/kernel/softirq.c
85184+++ b/kernel/softirq.c
85185@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
85186 EXPORT_SYMBOL(irq_stat);
85187 #endif
85188
85189-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
85190+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
85191
85192 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
85193
85194-char *softirq_to_name[NR_SOFTIRQS] = {
85195+const char * const softirq_to_name[NR_SOFTIRQS] = {
85196 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
85197 "TASKLET", "SCHED", "HRTIMER", "RCU"
85198 };
85199@@ -250,7 +250,7 @@ restart:
85200 kstat_incr_softirqs_this_cpu(vec_nr);
85201
85202 trace_softirq_entry(vec_nr);
85203- h->action(h);
85204+ h->action();
85205 trace_softirq_exit(vec_nr);
85206 if (unlikely(prev_count != preempt_count())) {
85207 printk(KERN_ERR "huh, entered softirq %u %s %p"
85208@@ -405,7 +405,7 @@ void __raise_softirq_irqoff(unsigned int nr)
85209 or_softirq_pending(1UL << nr);
85210 }
85211
85212-void open_softirq(int nr, void (*action)(struct softirq_action *))
85213+void __init open_softirq(int nr, void (*action)(void))
85214 {
85215 softirq_vec[nr].action = action;
85216 }
85217@@ -461,7 +461,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
85218
85219 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
85220
85221-static void tasklet_action(struct softirq_action *a)
85222+static void tasklet_action(void)
85223 {
85224 struct tasklet_struct *list;
85225
85226@@ -496,7 +496,7 @@ static void tasklet_action(struct softirq_action *a)
85227 }
85228 }
85229
85230-static void tasklet_hi_action(struct softirq_action *a)
85231+static void tasklet_hi_action(void)
85232 {
85233 struct tasklet_struct *list;
85234
85235@@ -730,7 +730,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
85236 return NOTIFY_OK;
85237 }
85238
85239-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
85240+static struct notifier_block remote_softirq_cpu_notifier = {
85241 .notifier_call = remote_softirq_cpu_notify,
85242 };
85243
85244@@ -847,11 +847,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
85245 return NOTIFY_OK;
85246 }
85247
85248-static struct notifier_block __cpuinitdata cpu_nfb = {
85249+static struct notifier_block cpu_nfb = {
85250 .notifier_call = cpu_callback
85251 };
85252
85253-static struct smp_hotplug_thread softirq_threads = {
85254+static struct smp_hotplug_thread softirq_threads __read_only = {
85255 .store = &ksoftirqd,
85256 .thread_should_run = ksoftirqd_should_run,
85257 .thread_fn = run_ksoftirqd,
85258diff --git a/kernel/srcu.c b/kernel/srcu.c
85259index 01d5ccb..cdcbee6 100644
85260--- a/kernel/srcu.c
85261+++ b/kernel/srcu.c
85262@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
85263
85264 idx = ACCESS_ONCE(sp->completed) & 0x1;
85265 preempt_disable();
85266- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
85267+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
85268 smp_mb(); /* B */ /* Avoid leaking the critical section. */
85269- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
85270+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
85271 preempt_enable();
85272 return idx;
85273 }
85274diff --git a/kernel/sys.c b/kernel/sys.c
85275index 2bbd9a7..0875671 100644
85276--- a/kernel/sys.c
85277+++ b/kernel/sys.c
85278@@ -163,6 +163,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
85279 error = -EACCES;
85280 goto out;
85281 }
85282+
85283+ if (gr_handle_chroot_setpriority(p, niceval)) {
85284+ error = -EACCES;
85285+ goto out;
85286+ }
85287+
85288 no_nice = security_task_setnice(p, niceval);
85289 if (no_nice) {
85290 error = no_nice;
85291@@ -626,6 +632,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
85292 goto error;
85293 }
85294
85295+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
85296+ goto error;
85297+
85298 if (rgid != (gid_t) -1 ||
85299 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
85300 new->sgid = new->egid;
85301@@ -661,6 +670,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
85302 old = current_cred();
85303
85304 retval = -EPERM;
85305+
85306+ if (gr_check_group_change(kgid, kgid, kgid))
85307+ goto error;
85308+
85309 if (nsown_capable(CAP_SETGID))
85310 new->gid = new->egid = new->sgid = new->fsgid = kgid;
85311 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
85312@@ -678,7 +691,7 @@ error:
85313 /*
85314 * change the user struct in a credentials set to match the new UID
85315 */
85316-static int set_user(struct cred *new)
85317+int set_user(struct cred *new)
85318 {
85319 struct user_struct *new_user;
85320
85321@@ -758,6 +771,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
85322 goto error;
85323 }
85324
85325+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
85326+ goto error;
85327+
85328 if (!uid_eq(new->uid, old->uid)) {
85329 retval = set_user(new);
85330 if (retval < 0)
85331@@ -808,6 +824,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
85332 old = current_cred();
85333
85334 retval = -EPERM;
85335+
85336+ if (gr_check_crash_uid(kuid))
85337+ goto error;
85338+ if (gr_check_user_change(kuid, kuid, kuid))
85339+ goto error;
85340+
85341 if (nsown_capable(CAP_SETUID)) {
85342 new->suid = new->uid = kuid;
85343 if (!uid_eq(kuid, old->uid)) {
85344@@ -877,6 +899,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
85345 goto error;
85346 }
85347
85348+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
85349+ goto error;
85350+
85351 if (ruid != (uid_t) -1) {
85352 new->uid = kruid;
85353 if (!uid_eq(kruid, old->uid)) {
85354@@ -959,6 +984,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
85355 goto error;
85356 }
85357
85358+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
85359+ goto error;
85360+
85361 if (rgid != (gid_t) -1)
85362 new->gid = krgid;
85363 if (egid != (gid_t) -1)
85364@@ -1020,12 +1048,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
85365 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
85366 nsown_capable(CAP_SETUID)) {
85367 if (!uid_eq(kuid, old->fsuid)) {
85368+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
85369+ goto error;
85370+
85371 new->fsuid = kuid;
85372 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
85373 goto change_okay;
85374 }
85375 }
85376
85377+error:
85378 abort_creds(new);
85379 return old_fsuid;
85380
85381@@ -1058,12 +1090,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
85382 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
85383 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
85384 nsown_capable(CAP_SETGID)) {
85385+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
85386+ goto error;
85387+
85388 if (!gid_eq(kgid, old->fsgid)) {
85389 new->fsgid = kgid;
85390 goto change_okay;
85391 }
85392 }
85393
85394+error:
85395 abort_creds(new);
85396 return old_fsgid;
85397
85398@@ -1432,19 +1468,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
85399 return -EFAULT;
85400
85401 down_read(&uts_sem);
85402- error = __copy_to_user(&name->sysname, &utsname()->sysname,
85403+ error = __copy_to_user(name->sysname, &utsname()->sysname,
85404 __OLD_UTS_LEN);
85405 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
85406- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
85407+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
85408 __OLD_UTS_LEN);
85409 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
85410- error |= __copy_to_user(&name->release, &utsname()->release,
85411+ error |= __copy_to_user(name->release, &utsname()->release,
85412 __OLD_UTS_LEN);
85413 error |= __put_user(0, name->release + __OLD_UTS_LEN);
85414- error |= __copy_to_user(&name->version, &utsname()->version,
85415+ error |= __copy_to_user(name->version, &utsname()->version,
85416 __OLD_UTS_LEN);
85417 error |= __put_user(0, name->version + __OLD_UTS_LEN);
85418- error |= __copy_to_user(&name->machine, &utsname()->machine,
85419+ error |= __copy_to_user(name->machine, &utsname()->machine,
85420 __OLD_UTS_LEN);
85421 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
85422 up_read(&uts_sem);
85423@@ -1646,6 +1682,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
85424 */
85425 new_rlim->rlim_cur = 1;
85426 }
85427+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
85428+ is changed to a lower value. Since tasks can be created by the same
85429+ user in between this limit change and an execve by this task, force
85430+ a recheck only for this task by setting PF_NPROC_EXCEEDED
85431+ */
85432+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
85433+ tsk->flags |= PF_NPROC_EXCEEDED;
85434 }
85435 if (!retval) {
85436 if (old_rlim)
85437diff --git a/kernel/sysctl.c b/kernel/sysctl.c
85438index 9edcf45..713c960 100644
85439--- a/kernel/sysctl.c
85440+++ b/kernel/sysctl.c
85441@@ -93,7 +93,6 @@
85442
85443
85444 #if defined(CONFIG_SYSCTL)
85445-
85446 /* External variables not in a header file. */
85447 extern int sysctl_overcommit_memory;
85448 extern int sysctl_overcommit_ratio;
85449@@ -119,18 +118,18 @@ extern int blk_iopoll_enabled;
85450
85451 /* Constants used for minimum and maximum */
85452 #ifdef CONFIG_LOCKUP_DETECTOR
85453-static int sixty = 60;
85454-static int neg_one = -1;
85455+static int sixty __read_only = 60;
85456 #endif
85457
85458-static int zero;
85459-static int __maybe_unused one = 1;
85460-static int __maybe_unused two = 2;
85461-static int __maybe_unused three = 3;
85462-static unsigned long one_ul = 1;
85463-static int one_hundred = 100;
85464+static int neg_one __read_only = -1;
85465+static int zero __read_only = 0;
85466+static int __maybe_unused one __read_only = 1;
85467+static int __maybe_unused two __read_only = 2;
85468+static int __maybe_unused three __read_only = 3;
85469+static unsigned long one_ul __read_only = 1;
85470+static int one_hundred __read_only = 100;
85471 #ifdef CONFIG_PRINTK
85472-static int ten_thousand = 10000;
85473+static int ten_thousand __read_only = 10000;
85474 #endif
85475
85476 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
85477@@ -177,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
85478 void __user *buffer, size_t *lenp, loff_t *ppos);
85479 #endif
85480
85481-#ifdef CONFIG_PRINTK
85482 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
85483 void __user *buffer, size_t *lenp, loff_t *ppos);
85484-#endif
85485
85486 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
85487 void __user *buffer, size_t *lenp, loff_t *ppos);
85488@@ -211,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
85489
85490 #endif
85491
85492+extern struct ctl_table grsecurity_table[];
85493+
85494 static struct ctl_table kern_table[];
85495 static struct ctl_table vm_table[];
85496 static struct ctl_table fs_table[];
85497@@ -225,6 +224,20 @@ extern struct ctl_table epoll_table[];
85498 int sysctl_legacy_va_layout;
85499 #endif
85500
85501+#ifdef CONFIG_PAX_SOFTMODE
85502+static ctl_table pax_table[] = {
85503+ {
85504+ .procname = "softmode",
85505+ .data = &pax_softmode,
85506+ .maxlen = sizeof(unsigned int),
85507+ .mode = 0600,
85508+ .proc_handler = &proc_dointvec,
85509+ },
85510+
85511+ { }
85512+};
85513+#endif
85514+
85515 /* The default sysctl tables: */
85516
85517 static struct ctl_table sysctl_base_table[] = {
85518@@ -273,6 +286,22 @@ static int max_extfrag_threshold = 1000;
85519 #endif
85520
85521 static struct ctl_table kern_table[] = {
85522+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
85523+ {
85524+ .procname = "grsecurity",
85525+ .mode = 0500,
85526+ .child = grsecurity_table,
85527+ },
85528+#endif
85529+
85530+#ifdef CONFIG_PAX_SOFTMODE
85531+ {
85532+ .procname = "pax",
85533+ .mode = 0500,
85534+ .child = pax_table,
85535+ },
85536+#endif
85537+
85538 {
85539 .procname = "sched_child_runs_first",
85540 .data = &sysctl_sched_child_runs_first,
85541@@ -607,7 +636,7 @@ static struct ctl_table kern_table[] = {
85542 .data = &modprobe_path,
85543 .maxlen = KMOD_PATH_LEN,
85544 .mode = 0644,
85545- .proc_handler = proc_dostring,
85546+ .proc_handler = proc_dostring_modpriv,
85547 },
85548 {
85549 .procname = "modules_disabled",
85550@@ -774,16 +803,20 @@ static struct ctl_table kern_table[] = {
85551 .extra1 = &zero,
85552 .extra2 = &one,
85553 },
85554+#endif
85555 {
85556 .procname = "kptr_restrict",
85557 .data = &kptr_restrict,
85558 .maxlen = sizeof(int),
85559 .mode = 0644,
85560 .proc_handler = proc_dointvec_minmax_sysadmin,
85561+#ifdef CONFIG_GRKERNSEC_HIDESYM
85562+ .extra1 = &two,
85563+#else
85564 .extra1 = &zero,
85565+#endif
85566 .extra2 = &two,
85567 },
85568-#endif
85569 {
85570 .procname = "ngroups_max",
85571 .data = &ngroups_max,
85572@@ -1025,10 +1058,17 @@ static struct ctl_table kern_table[] = {
85573 */
85574 {
85575 .procname = "perf_event_paranoid",
85576- .data = &sysctl_perf_event_paranoid,
85577- .maxlen = sizeof(sysctl_perf_event_paranoid),
85578+ .data = &sysctl_perf_event_legitimately_concerned,
85579+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
85580 .mode = 0644,
85581- .proc_handler = proc_dointvec,
85582+ /* go ahead, be a hero */
85583+ .proc_handler = proc_dointvec_minmax_sysadmin,
85584+ .extra1 = &neg_one,
85585+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85586+ .extra2 = &three,
85587+#else
85588+ .extra2 = &two,
85589+#endif
85590 },
85591 {
85592 .procname = "perf_event_mlock_kb",
85593@@ -1282,6 +1322,13 @@ static struct ctl_table vm_table[] = {
85594 .proc_handler = proc_dointvec_minmax,
85595 .extra1 = &zero,
85596 },
85597+ {
85598+ .procname = "heap_stack_gap",
85599+ .data = &sysctl_heap_stack_gap,
85600+ .maxlen = sizeof(sysctl_heap_stack_gap),
85601+ .mode = 0644,
85602+ .proc_handler = proc_doulongvec_minmax,
85603+ },
85604 #else
85605 {
85606 .procname = "nr_trim_pages",
85607@@ -1746,6 +1793,16 @@ int proc_dostring(struct ctl_table *table, int write,
85608 buffer, lenp, ppos);
85609 }
85610
85611+int proc_dostring_modpriv(struct ctl_table *table, int write,
85612+ void __user *buffer, size_t *lenp, loff_t *ppos)
85613+{
85614+ if (write && !capable(CAP_SYS_MODULE))
85615+ return -EPERM;
85616+
85617+ return _proc_do_string(table->data, table->maxlen, write,
85618+ buffer, lenp, ppos);
85619+}
85620+
85621 static size_t proc_skip_spaces(char **buf)
85622 {
85623 size_t ret;
85624@@ -1851,6 +1908,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
85625 len = strlen(tmp);
85626 if (len > *size)
85627 len = *size;
85628+ if (len > sizeof(tmp))
85629+ len = sizeof(tmp);
85630 if (copy_to_user(*buf, tmp, len))
85631 return -EFAULT;
85632 *size -= len;
85633@@ -2015,7 +2074,7 @@ int proc_dointvec(struct ctl_table *table, int write,
85634 static int proc_taint(struct ctl_table *table, int write,
85635 void __user *buffer, size_t *lenp, loff_t *ppos)
85636 {
85637- struct ctl_table t;
85638+ ctl_table_no_const t;
85639 unsigned long tmptaint = get_taint();
85640 int err;
85641
85642@@ -2043,7 +2102,6 @@ static int proc_taint(struct ctl_table *table, int write,
85643 return err;
85644 }
85645
85646-#ifdef CONFIG_PRINTK
85647 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
85648 void __user *buffer, size_t *lenp, loff_t *ppos)
85649 {
85650@@ -2052,7 +2110,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
85651
85652 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
85653 }
85654-#endif
85655
85656 struct do_proc_dointvec_minmax_conv_param {
85657 int *min;
85658@@ -2199,8 +2256,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
85659 *i = val;
85660 } else {
85661 val = convdiv * (*i) / convmul;
85662- if (!first)
85663+ if (!first) {
85664 err = proc_put_char(&buffer, &left, '\t');
85665+ if (err)
85666+ break;
85667+ }
85668 err = proc_put_long(&buffer, &left, val, false);
85669 if (err)
85670 break;
85671@@ -2592,6 +2652,12 @@ int proc_dostring(struct ctl_table *table, int write,
85672 return -ENOSYS;
85673 }
85674
85675+int proc_dostring_modpriv(struct ctl_table *table, int write,
85676+ void __user *buffer, size_t *lenp, loff_t *ppos)
85677+{
85678+ return -ENOSYS;
85679+}
85680+
85681 int proc_dointvec(struct ctl_table *table, int write,
85682 void __user *buffer, size_t *lenp, loff_t *ppos)
85683 {
85684@@ -2648,5 +2714,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
85685 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
85686 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
85687 EXPORT_SYMBOL(proc_dostring);
85688+EXPORT_SYMBOL(proc_dostring_modpriv);
85689 EXPORT_SYMBOL(proc_doulongvec_minmax);
85690 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
85691diff --git a/kernel/taskstats.c b/kernel/taskstats.c
85692index 145bb4d..b2aa969 100644
85693--- a/kernel/taskstats.c
85694+++ b/kernel/taskstats.c
85695@@ -28,9 +28,12 @@
85696 #include <linux/fs.h>
85697 #include <linux/file.h>
85698 #include <linux/pid_namespace.h>
85699+#include <linux/grsecurity.h>
85700 #include <net/genetlink.h>
85701 #include <linux/atomic.h>
85702
85703+extern int gr_is_taskstats_denied(int pid);
85704+
85705 /*
85706 * Maximum length of a cpumask that can be specified in
85707 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
85708@@ -570,6 +573,9 @@ err:
85709
85710 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
85711 {
85712+ if (gr_is_taskstats_denied(current->pid))
85713+ return -EACCES;
85714+
85715 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
85716 return cmd_attr_register_cpumask(info);
85717 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
85718diff --git a/kernel/time.c b/kernel/time.c
85719index d3617db..c98bbe9 100644
85720--- a/kernel/time.c
85721+++ b/kernel/time.c
85722@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
85723 return error;
85724
85725 if (tz) {
85726+ /* we log in do_settimeofday called below, so don't log twice
85727+ */
85728+ if (!tv)
85729+ gr_log_timechange();
85730+
85731 sys_tz = *tz;
85732 update_vsyscall_tz();
85733 if (firsttime) {
85734@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
85735 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
85736 * value to a scaled second value.
85737 */
85738-unsigned long
85739+unsigned long __intentional_overflow(-1)
85740 timespec_to_jiffies(const struct timespec *value)
85741 {
85742 unsigned long sec = value->tv_sec;
85743diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
85744index f11d83b..d016d91 100644
85745--- a/kernel/time/alarmtimer.c
85746+++ b/kernel/time/alarmtimer.c
85747@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
85748 struct platform_device *pdev;
85749 int error = 0;
85750 int i;
85751- struct k_clock alarm_clock = {
85752+ static struct k_clock alarm_clock = {
85753 .clock_getres = alarm_clock_getres,
85754 .clock_get = alarm_clock_get,
85755 .timer_create = alarm_timer_create,
85756diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
85757index baeeb5c..c22704a 100644
85758--- a/kernel/time/timekeeping.c
85759+++ b/kernel/time/timekeeping.c
85760@@ -15,6 +15,7 @@
85761 #include <linux/init.h>
85762 #include <linux/mm.h>
85763 #include <linux/sched.h>
85764+#include <linux/grsecurity.h>
85765 #include <linux/syscore_ops.h>
85766 #include <linux/clocksource.h>
85767 #include <linux/jiffies.h>
85768@@ -495,6 +496,8 @@ int do_settimeofday(const struct timespec *tv)
85769 if (!timespec_valid_strict(tv))
85770 return -EINVAL;
85771
85772+ gr_log_timechange();
85773+
85774 raw_spin_lock_irqsave(&timekeeper_lock, flags);
85775 write_seqcount_begin(&timekeeper_seq);
85776
85777diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
85778index 61ed862..3b52c65 100644
85779--- a/kernel/time/timer_list.c
85780+++ b/kernel/time/timer_list.c
85781@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
85782
85783 static void print_name_offset(struct seq_file *m, void *sym)
85784 {
85785+#ifdef CONFIG_GRKERNSEC_HIDESYM
85786+ SEQ_printf(m, "<%p>", NULL);
85787+#else
85788 char symname[KSYM_NAME_LEN];
85789
85790 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
85791 SEQ_printf(m, "<%pK>", sym);
85792 else
85793 SEQ_printf(m, "%s", symname);
85794+#endif
85795 }
85796
85797 static void
85798@@ -119,7 +123,11 @@ next_one:
85799 static void
85800 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
85801 {
85802+#ifdef CONFIG_GRKERNSEC_HIDESYM
85803+ SEQ_printf(m, " .base: %p\n", NULL);
85804+#else
85805 SEQ_printf(m, " .base: %pK\n", base);
85806+#endif
85807 SEQ_printf(m, " .index: %d\n",
85808 base->index);
85809 SEQ_printf(m, " .resolution: %Lu nsecs\n",
85810@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
85811 {
85812 struct proc_dir_entry *pe;
85813
85814+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85815+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
85816+#else
85817 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
85818+#endif
85819 if (!pe)
85820 return -ENOMEM;
85821 return 0;
85822diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
85823index 0b537f2..40d6c20 100644
85824--- a/kernel/time/timer_stats.c
85825+++ b/kernel/time/timer_stats.c
85826@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
85827 static unsigned long nr_entries;
85828 static struct entry entries[MAX_ENTRIES];
85829
85830-static atomic_t overflow_count;
85831+static atomic_unchecked_t overflow_count;
85832
85833 /*
85834 * The entries are in a hash-table, for fast lookup:
85835@@ -140,7 +140,7 @@ static void reset_entries(void)
85836 nr_entries = 0;
85837 memset(entries, 0, sizeof(entries));
85838 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
85839- atomic_set(&overflow_count, 0);
85840+ atomic_set_unchecked(&overflow_count, 0);
85841 }
85842
85843 static struct entry *alloc_entry(void)
85844@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
85845 if (likely(entry))
85846 entry->count++;
85847 else
85848- atomic_inc(&overflow_count);
85849+ atomic_inc_unchecked(&overflow_count);
85850
85851 out_unlock:
85852 raw_spin_unlock_irqrestore(lock, flags);
85853@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
85854
85855 static void print_name_offset(struct seq_file *m, unsigned long addr)
85856 {
85857+#ifdef CONFIG_GRKERNSEC_HIDESYM
85858+ seq_printf(m, "<%p>", NULL);
85859+#else
85860 char symname[KSYM_NAME_LEN];
85861
85862 if (lookup_symbol_name(addr, symname) < 0)
85863- seq_printf(m, "<%p>", (void *)addr);
85864+ seq_printf(m, "<%pK>", (void *)addr);
85865 else
85866 seq_printf(m, "%s", symname);
85867+#endif
85868 }
85869
85870 static int tstats_show(struct seq_file *m, void *v)
85871@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
85872
85873 seq_puts(m, "Timer Stats Version: v0.2\n");
85874 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
85875- if (atomic_read(&overflow_count))
85876+ if (atomic_read_unchecked(&overflow_count))
85877 seq_printf(m, "Overflow: %d entries\n",
85878- atomic_read(&overflow_count));
85879+ atomic_read_unchecked(&overflow_count));
85880
85881 for (i = 0; i < nr_entries; i++) {
85882 entry = entries + i;
85883@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
85884 {
85885 struct proc_dir_entry *pe;
85886
85887+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85888+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
85889+#else
85890 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
85891+#endif
85892 if (!pe)
85893 return -ENOMEM;
85894 return 0;
85895diff --git a/kernel/timer.c b/kernel/timer.c
85896index 15bc1b4..32da49c 100644
85897--- a/kernel/timer.c
85898+++ b/kernel/timer.c
85899@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
85900 /*
85901 * This function runs timers and the timer-tq in bottom half context.
85902 */
85903-static void run_timer_softirq(struct softirq_action *h)
85904+static void run_timer_softirq(void)
85905 {
85906 struct tvec_base *base = __this_cpu_read(tvec_bases);
85907
85908@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
85909 *
85910 * In all cases the return value is guaranteed to be non-negative.
85911 */
85912-signed long __sched schedule_timeout(signed long timeout)
85913+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
85914 {
85915 struct timer_list timer;
85916 unsigned long expire;
85917@@ -1635,7 +1635,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
85918 return NOTIFY_OK;
85919 }
85920
85921-static struct notifier_block __cpuinitdata timers_nb = {
85922+static struct notifier_block timers_nb = {
85923 .notifier_call = timer_cpu_notify,
85924 };
85925
85926diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
85927index b8b8560..75b1a09 100644
85928--- a/kernel/trace/blktrace.c
85929+++ b/kernel/trace/blktrace.c
85930@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
85931 struct blk_trace *bt = filp->private_data;
85932 char buf[16];
85933
85934- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
85935+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
85936
85937 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
85938 }
85939@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
85940 return 1;
85941
85942 bt = buf->chan->private_data;
85943- atomic_inc(&bt->dropped);
85944+ atomic_inc_unchecked(&bt->dropped);
85945 return 0;
85946 }
85947
85948@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
85949
85950 bt->dir = dir;
85951 bt->dev = dev;
85952- atomic_set(&bt->dropped, 0);
85953+ atomic_set_unchecked(&bt->dropped, 0);
85954
85955 ret = -EIO;
85956 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
85957diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
85958index f23449d..b8cc3a1 100644
85959--- a/kernel/trace/ftrace.c
85960+++ b/kernel/trace/ftrace.c
85961@@ -1925,12 +1925,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
85962 if (unlikely(ftrace_disabled))
85963 return 0;
85964
85965+ ret = ftrace_arch_code_modify_prepare();
85966+ FTRACE_WARN_ON(ret);
85967+ if (ret)
85968+ return 0;
85969+
85970 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
85971+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
85972 if (ret) {
85973 ftrace_bug(ret, ip);
85974- return 0;
85975 }
85976- return 1;
85977+ return ret ? 0 : 1;
85978 }
85979
85980 /*
85981@@ -3994,8 +3999,10 @@ static int ftrace_process_locs(struct module *mod,
85982 if (!count)
85983 return 0;
85984
85985+ pax_open_kernel();
85986 sort(start, count, sizeof(*start),
85987 ftrace_cmp_ips, ftrace_swap_ips);
85988+ pax_close_kernel();
85989
85990 start_pg = ftrace_allocate_pages(count);
85991 if (!start_pg)
85992@@ -4718,8 +4725,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
85993 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
85994
85995 static int ftrace_graph_active;
85996-static struct notifier_block ftrace_suspend_notifier;
85997-
85998 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
85999 {
86000 return 0;
86001@@ -4863,6 +4868,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
86002 return NOTIFY_DONE;
86003 }
86004
86005+static struct notifier_block ftrace_suspend_notifier = {
86006+ .notifier_call = ftrace_suspend_notifier_call
86007+};
86008+
86009 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
86010 trace_func_graph_ent_t entryfunc)
86011 {
86012@@ -4876,7 +4885,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
86013 goto out;
86014 }
86015
86016- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
86017 register_pm_notifier(&ftrace_suspend_notifier);
86018
86019 ftrace_graph_active++;
86020diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
86021index e444ff8..438b8f4 100644
86022--- a/kernel/trace/ring_buffer.c
86023+++ b/kernel/trace/ring_buffer.c
86024@@ -352,9 +352,9 @@ struct buffer_data_page {
86025 */
86026 struct buffer_page {
86027 struct list_head list; /* list of buffer pages */
86028- local_t write; /* index for next write */
86029+ local_unchecked_t write; /* index for next write */
86030 unsigned read; /* index for next read */
86031- local_t entries; /* entries on this page */
86032+ local_unchecked_t entries; /* entries on this page */
86033 unsigned long real_end; /* real end of data */
86034 struct buffer_data_page *page; /* Actual data page */
86035 };
86036@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
86037 unsigned long last_overrun;
86038 local_t entries_bytes;
86039 local_t entries;
86040- local_t overrun;
86041- local_t commit_overrun;
86042+ local_unchecked_t overrun;
86043+ local_unchecked_t commit_overrun;
86044 local_t dropped_events;
86045 local_t committing;
86046 local_t commits;
86047@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
86048 *
86049 * We add a counter to the write field to denote this.
86050 */
86051- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
86052- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
86053+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
86054+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
86055
86056 /*
86057 * Just make sure we have seen our old_write and synchronize
86058@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
86059 * cmpxchg to only update if an interrupt did not already
86060 * do it for us. If the cmpxchg fails, we don't care.
86061 */
86062- (void)local_cmpxchg(&next_page->write, old_write, val);
86063- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
86064+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
86065+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
86066
86067 /*
86068 * No need to worry about races with clearing out the commit.
86069@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
86070
86071 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
86072 {
86073- return local_read(&bpage->entries) & RB_WRITE_MASK;
86074+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
86075 }
86076
86077 static inline unsigned long rb_page_write(struct buffer_page *bpage)
86078 {
86079- return local_read(&bpage->write) & RB_WRITE_MASK;
86080+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
86081 }
86082
86083 static int
86084@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
86085 * bytes consumed in ring buffer from here.
86086 * Increment overrun to account for the lost events.
86087 */
86088- local_add(page_entries, &cpu_buffer->overrun);
86089+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
86090 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
86091 }
86092
86093@@ -2063,7 +2063,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
86094 * it is our responsibility to update
86095 * the counters.
86096 */
86097- local_add(entries, &cpu_buffer->overrun);
86098+ local_add_unchecked(entries, &cpu_buffer->overrun);
86099 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
86100
86101 /*
86102@@ -2213,7 +2213,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
86103 if (tail == BUF_PAGE_SIZE)
86104 tail_page->real_end = 0;
86105
86106- local_sub(length, &tail_page->write);
86107+ local_sub_unchecked(length, &tail_page->write);
86108 return;
86109 }
86110
86111@@ -2248,7 +2248,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
86112 rb_event_set_padding(event);
86113
86114 /* Set the write back to the previous setting */
86115- local_sub(length, &tail_page->write);
86116+ local_sub_unchecked(length, &tail_page->write);
86117 return;
86118 }
86119
86120@@ -2260,7 +2260,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
86121
86122 /* Set write to end of buffer */
86123 length = (tail + length) - BUF_PAGE_SIZE;
86124- local_sub(length, &tail_page->write);
86125+ local_sub_unchecked(length, &tail_page->write);
86126 }
86127
86128 /*
86129@@ -2286,7 +2286,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
86130 * about it.
86131 */
86132 if (unlikely(next_page == commit_page)) {
86133- local_inc(&cpu_buffer->commit_overrun);
86134+ local_inc_unchecked(&cpu_buffer->commit_overrun);
86135 goto out_reset;
86136 }
86137
86138@@ -2342,7 +2342,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
86139 cpu_buffer->tail_page) &&
86140 (cpu_buffer->commit_page ==
86141 cpu_buffer->reader_page))) {
86142- local_inc(&cpu_buffer->commit_overrun);
86143+ local_inc_unchecked(&cpu_buffer->commit_overrun);
86144 goto out_reset;
86145 }
86146 }
86147@@ -2390,7 +2390,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
86148 length += RB_LEN_TIME_EXTEND;
86149
86150 tail_page = cpu_buffer->tail_page;
86151- write = local_add_return(length, &tail_page->write);
86152+ write = local_add_return_unchecked(length, &tail_page->write);
86153
86154 /* set write to only the index of the write */
86155 write &= RB_WRITE_MASK;
86156@@ -2407,7 +2407,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
86157 kmemcheck_annotate_bitfield(event, bitfield);
86158 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
86159
86160- local_inc(&tail_page->entries);
86161+ local_inc_unchecked(&tail_page->entries);
86162
86163 /*
86164 * If this is the first commit on the page, then update
86165@@ -2440,7 +2440,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
86166
86167 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
86168 unsigned long write_mask =
86169- local_read(&bpage->write) & ~RB_WRITE_MASK;
86170+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
86171 unsigned long event_length = rb_event_length(event);
86172 /*
86173 * This is on the tail page. It is possible that
86174@@ -2450,7 +2450,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
86175 */
86176 old_index += write_mask;
86177 new_index += write_mask;
86178- index = local_cmpxchg(&bpage->write, old_index, new_index);
86179+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
86180 if (index == old_index) {
86181 /* update counters */
86182 local_sub(event_length, &cpu_buffer->entries_bytes);
86183@@ -2842,7 +2842,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
86184
86185 /* Do the likely case first */
86186 if (likely(bpage->page == (void *)addr)) {
86187- local_dec(&bpage->entries);
86188+ local_dec_unchecked(&bpage->entries);
86189 return;
86190 }
86191
86192@@ -2854,7 +2854,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
86193 start = bpage;
86194 do {
86195 if (bpage->page == (void *)addr) {
86196- local_dec(&bpage->entries);
86197+ local_dec_unchecked(&bpage->entries);
86198 return;
86199 }
86200 rb_inc_page(cpu_buffer, &bpage);
86201@@ -3138,7 +3138,7 @@ static inline unsigned long
86202 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
86203 {
86204 return local_read(&cpu_buffer->entries) -
86205- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
86206+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
86207 }
86208
86209 /**
86210@@ -3227,7 +3227,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
86211 return 0;
86212
86213 cpu_buffer = buffer->buffers[cpu];
86214- ret = local_read(&cpu_buffer->overrun);
86215+ ret = local_read_unchecked(&cpu_buffer->overrun);
86216
86217 return ret;
86218 }
86219@@ -3250,7 +3250,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
86220 return 0;
86221
86222 cpu_buffer = buffer->buffers[cpu];
86223- ret = local_read(&cpu_buffer->commit_overrun);
86224+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
86225
86226 return ret;
86227 }
86228@@ -3335,7 +3335,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
86229 /* if you care about this being correct, lock the buffer */
86230 for_each_buffer_cpu(buffer, cpu) {
86231 cpu_buffer = buffer->buffers[cpu];
86232- overruns += local_read(&cpu_buffer->overrun);
86233+ overruns += local_read_unchecked(&cpu_buffer->overrun);
86234 }
86235
86236 return overruns;
86237@@ -3511,8 +3511,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
86238 /*
86239 * Reset the reader page to size zero.
86240 */
86241- local_set(&cpu_buffer->reader_page->write, 0);
86242- local_set(&cpu_buffer->reader_page->entries, 0);
86243+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
86244+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
86245 local_set(&cpu_buffer->reader_page->page->commit, 0);
86246 cpu_buffer->reader_page->real_end = 0;
86247
86248@@ -3546,7 +3546,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
86249 * want to compare with the last_overrun.
86250 */
86251 smp_mb();
86252- overwrite = local_read(&(cpu_buffer->overrun));
86253+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
86254
86255 /*
86256 * Here's the tricky part.
86257@@ -4116,8 +4116,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
86258
86259 cpu_buffer->head_page
86260 = list_entry(cpu_buffer->pages, struct buffer_page, list);
86261- local_set(&cpu_buffer->head_page->write, 0);
86262- local_set(&cpu_buffer->head_page->entries, 0);
86263+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
86264+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
86265 local_set(&cpu_buffer->head_page->page->commit, 0);
86266
86267 cpu_buffer->head_page->read = 0;
86268@@ -4127,14 +4127,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
86269
86270 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
86271 INIT_LIST_HEAD(&cpu_buffer->new_pages);
86272- local_set(&cpu_buffer->reader_page->write, 0);
86273- local_set(&cpu_buffer->reader_page->entries, 0);
86274+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
86275+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
86276 local_set(&cpu_buffer->reader_page->page->commit, 0);
86277 cpu_buffer->reader_page->read = 0;
86278
86279 local_set(&cpu_buffer->entries_bytes, 0);
86280- local_set(&cpu_buffer->overrun, 0);
86281- local_set(&cpu_buffer->commit_overrun, 0);
86282+ local_set_unchecked(&cpu_buffer->overrun, 0);
86283+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
86284 local_set(&cpu_buffer->dropped_events, 0);
86285 local_set(&cpu_buffer->entries, 0);
86286 local_set(&cpu_buffer->committing, 0);
86287@@ -4538,8 +4538,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
86288 rb_init_page(bpage);
86289 bpage = reader->page;
86290 reader->page = *data_page;
86291- local_set(&reader->write, 0);
86292- local_set(&reader->entries, 0);
86293+ local_set_unchecked(&reader->write, 0);
86294+ local_set_unchecked(&reader->entries, 0);
86295 reader->read = 0;
86296 *data_page = bpage;
86297
86298diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
86299index 0582a01..310bed1 100644
86300--- a/kernel/trace/trace.c
86301+++ b/kernel/trace/trace.c
86302@@ -3327,7 +3327,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
86303 return 0;
86304 }
86305
86306-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
86307+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
86308 {
86309 /* do nothing if flag is already set */
86310 if (!!(trace_flags & mask) == !!enabled)
86311diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
86312index 51b4448..7be601f 100644
86313--- a/kernel/trace/trace.h
86314+++ b/kernel/trace/trace.h
86315@@ -1035,7 +1035,7 @@ extern const char *__stop___trace_bprintk_fmt[];
86316 void trace_printk_init_buffers(void);
86317 void trace_printk_start_comm(void);
86318 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
86319-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
86320+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
86321
86322 /*
86323 * Normal trace_printk() and friends allocates special buffers
86324diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
86325index 26dc348..8708ca7 100644
86326--- a/kernel/trace/trace_clock.c
86327+++ b/kernel/trace/trace_clock.c
86328@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
86329 return now;
86330 }
86331
86332-static atomic64_t trace_counter;
86333+static atomic64_unchecked_t trace_counter;
86334
86335 /*
86336 * trace_clock_counter(): simply an atomic counter.
86337@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
86338 */
86339 u64 notrace trace_clock_counter(void)
86340 {
86341- return atomic64_add_return(1, &trace_counter);
86342+ return atomic64_inc_return_unchecked(&trace_counter);
86343 }
86344diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
86345index 3d18aad..d1be0eb 100644
86346--- a/kernel/trace/trace_events.c
86347+++ b/kernel/trace/trace_events.c
86348@@ -1794,10 +1794,6 @@ static LIST_HEAD(ftrace_module_file_list);
86349 struct ftrace_module_file_ops {
86350 struct list_head list;
86351 struct module *mod;
86352- struct file_operations id;
86353- struct file_operations enable;
86354- struct file_operations format;
86355- struct file_operations filter;
86356 };
86357
86358 static struct ftrace_module_file_ops *
86359@@ -1838,17 +1834,12 @@ trace_create_file_ops(struct module *mod)
86360
86361 file_ops->mod = mod;
86362
86363- file_ops->id = ftrace_event_id_fops;
86364- file_ops->id.owner = mod;
86365-
86366- file_ops->enable = ftrace_enable_fops;
86367- file_ops->enable.owner = mod;
86368-
86369- file_ops->filter = ftrace_event_filter_fops;
86370- file_ops->filter.owner = mod;
86371-
86372- file_ops->format = ftrace_event_format_fops;
86373- file_ops->format.owner = mod;
86374+ pax_open_kernel();
86375+ mod->trace_id.owner = mod;
86376+ mod->trace_enable.owner = mod;
86377+ mod->trace_filter.owner = mod;
86378+ mod->trace_format.owner = mod;
86379+ pax_close_kernel();
86380
86381 list_add(&file_ops->list, &ftrace_module_file_list);
86382
86383@@ -1941,8 +1932,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
86384 struct ftrace_module_file_ops *file_ops)
86385 {
86386 return __trace_add_new_event(call, tr,
86387- &file_ops->id, &file_ops->enable,
86388- &file_ops->filter, &file_ops->format);
86389+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
86390+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
86391 }
86392
86393 #else
86394diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
86395index a5e8f48..a9690d2 100644
86396--- a/kernel/trace/trace_mmiotrace.c
86397+++ b/kernel/trace/trace_mmiotrace.c
86398@@ -24,7 +24,7 @@ struct header_iter {
86399 static struct trace_array *mmio_trace_array;
86400 static bool overrun_detected;
86401 static unsigned long prev_overruns;
86402-static atomic_t dropped_count;
86403+static atomic_unchecked_t dropped_count;
86404
86405 static void mmio_reset_data(struct trace_array *tr)
86406 {
86407@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
86408
86409 static unsigned long count_overruns(struct trace_iterator *iter)
86410 {
86411- unsigned long cnt = atomic_xchg(&dropped_count, 0);
86412+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
86413 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
86414
86415 if (over > prev_overruns)
86416@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
86417 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
86418 sizeof(*entry), 0, pc);
86419 if (!event) {
86420- atomic_inc(&dropped_count);
86421+ atomic_inc_unchecked(&dropped_count);
86422 return;
86423 }
86424 entry = ring_buffer_event_data(event);
86425@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
86426 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
86427 sizeof(*entry), 0, pc);
86428 if (!event) {
86429- atomic_inc(&dropped_count);
86430+ atomic_inc_unchecked(&dropped_count);
86431 return;
86432 }
86433 entry = ring_buffer_event_data(event);
86434diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
86435index bb922d9..2a54a257 100644
86436--- a/kernel/trace/trace_output.c
86437+++ b/kernel/trace/trace_output.c
86438@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
86439
86440 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
86441 if (!IS_ERR(p)) {
86442- p = mangle_path(s->buffer + s->len, p, "\n");
86443+ p = mangle_path(s->buffer + s->len, p, "\n\\");
86444 if (p) {
86445 s->len = p - s->buffer;
86446 return 1;
86447@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
86448 goto out;
86449 }
86450
86451+ pax_open_kernel();
86452 if (event->funcs->trace == NULL)
86453- event->funcs->trace = trace_nop_print;
86454+ *(void **)&event->funcs->trace = trace_nop_print;
86455 if (event->funcs->raw == NULL)
86456- event->funcs->raw = trace_nop_print;
86457+ *(void **)&event->funcs->raw = trace_nop_print;
86458 if (event->funcs->hex == NULL)
86459- event->funcs->hex = trace_nop_print;
86460+ *(void **)&event->funcs->hex = trace_nop_print;
86461 if (event->funcs->binary == NULL)
86462- event->funcs->binary = trace_nop_print;
86463+ *(void **)&event->funcs->binary = trace_nop_print;
86464+ pax_close_kernel();
86465
86466 key = event->type & (EVENT_HASHSIZE - 1);
86467
86468diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
86469index b20428c..4845a10 100644
86470--- a/kernel/trace/trace_stack.c
86471+++ b/kernel/trace/trace_stack.c
86472@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
86473 return;
86474
86475 /* we do not handle interrupt stacks yet */
86476- if (!object_is_on_stack(stack))
86477+ if (!object_starts_on_stack(stack))
86478 return;
86479
86480 local_irq_save(flags);
86481diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
86482index 9064b91..1f5d2f8 100644
86483--- a/kernel/user_namespace.c
86484+++ b/kernel/user_namespace.c
86485@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
86486 !kgid_has_mapping(parent_ns, group))
86487 return -EPERM;
86488
86489+#ifdef CONFIG_GRKERNSEC
86490+ /*
86491+ * This doesn't really inspire confidence:
86492+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
86493+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
86494+ * Increases kernel attack surface in areas developers
86495+ * previously cared little about ("low importance due
86496+ * to requiring "root" capability")
86497+ * To be removed when this code receives *proper* review
86498+ */
86499+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
86500+ !capable(CAP_SETGID))
86501+ return -EPERM;
86502+#endif
86503+
86504 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
86505 if (!ns)
86506 return -ENOMEM;
86507@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
86508 if (atomic_read(&current->mm->mm_users) > 1)
86509 return -EINVAL;
86510
86511- if (current->fs->users != 1)
86512+ if (atomic_read(&current->fs->users) != 1)
86513 return -EINVAL;
86514
86515 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
86516diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
86517index 4f69f9a..7c6f8f8 100644
86518--- a/kernel/utsname_sysctl.c
86519+++ b/kernel/utsname_sysctl.c
86520@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
86521 static int proc_do_uts_string(ctl_table *table, int write,
86522 void __user *buffer, size_t *lenp, loff_t *ppos)
86523 {
86524- struct ctl_table uts_table;
86525+ ctl_table_no_const uts_table;
86526 int r;
86527 memcpy(&uts_table, table, sizeof(uts_table));
86528 uts_table.data = get_uts(table, write);
86529diff --git a/kernel/watchdog.c b/kernel/watchdog.c
86530index 05039e3..17490c7 100644
86531--- a/kernel/watchdog.c
86532+++ b/kernel/watchdog.c
86533@@ -531,7 +531,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
86534 }
86535 #endif /* CONFIG_SYSCTL */
86536
86537-static struct smp_hotplug_thread watchdog_threads = {
86538+static struct smp_hotplug_thread watchdog_threads __read_only = {
86539 .store = &softlockup_watchdog,
86540 .thread_should_run = watchdog_should_run,
86541 .thread_fn = watchdog,
86542diff --git a/kernel/workqueue.c b/kernel/workqueue.c
86543index e52d002..576b367 100644
86544--- a/kernel/workqueue.c
86545+++ b/kernel/workqueue.c
86546@@ -4605,7 +4605,7 @@ static void rebind_workers(struct worker_pool *pool)
86547 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
86548 worker_flags |= WORKER_REBOUND;
86549 worker_flags &= ~WORKER_UNBOUND;
86550- ACCESS_ONCE(worker->flags) = worker_flags;
86551+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
86552 }
86553
86554 spin_unlock_irq(&pool->lock);
86555diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
86556index 74fdc5c..3310593 100644
86557--- a/lib/Kconfig.debug
86558+++ b/lib/Kconfig.debug
86559@@ -549,7 +549,7 @@ config DEBUG_MUTEXES
86560
86561 config DEBUG_LOCK_ALLOC
86562 bool "Lock debugging: detect incorrect freeing of live locks"
86563- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86564+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86565 select DEBUG_SPINLOCK
86566 select DEBUG_MUTEXES
86567 select LOCKDEP
86568@@ -563,7 +563,7 @@ config DEBUG_LOCK_ALLOC
86569
86570 config PROVE_LOCKING
86571 bool "Lock debugging: prove locking correctness"
86572- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86573+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86574 select LOCKDEP
86575 select DEBUG_SPINLOCK
86576 select DEBUG_MUTEXES
86577@@ -614,7 +614,7 @@ config LOCKDEP
86578
86579 config LOCK_STAT
86580 bool "Lock usage statistics"
86581- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86582+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86583 select LOCKDEP
86584 select DEBUG_SPINLOCK
86585 select DEBUG_MUTEXES
86586@@ -1282,6 +1282,7 @@ config LATENCYTOP
86587 depends on DEBUG_KERNEL
86588 depends on STACKTRACE_SUPPORT
86589 depends on PROC_FS
86590+ depends on !GRKERNSEC_HIDESYM
86591 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
86592 select KALLSYMS
86593 select KALLSYMS_ALL
86594@@ -1298,7 +1299,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
86595 config DEBUG_STRICT_USER_COPY_CHECKS
86596 bool "Strict user copy size checks"
86597 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
86598- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
86599+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
86600 help
86601 Enabling this option turns a certain set of sanity checks for user
86602 copy operations into compile time failures.
86603@@ -1328,7 +1329,7 @@ config INTERVAL_TREE_TEST
86604
86605 config PROVIDE_OHCI1394_DMA_INIT
86606 bool "Remote debugging over FireWire early on boot"
86607- depends on PCI && X86
86608+ depends on PCI && X86 && !GRKERNSEC
86609 help
86610 If you want to debug problems which hang or crash the kernel early
86611 on boot and the crashing machine has a FireWire port, you can use
86612@@ -1357,7 +1358,7 @@ config PROVIDE_OHCI1394_DMA_INIT
86613
86614 config FIREWIRE_OHCI_REMOTE_DMA
86615 bool "Remote debugging over FireWire with firewire-ohci"
86616- depends on FIREWIRE_OHCI
86617+ depends on FIREWIRE_OHCI && !GRKERNSEC
86618 help
86619 This option lets you use the FireWire bus for remote debugging
86620 with help of the firewire-ohci driver. It enables unfiltered
86621diff --git a/lib/Makefile b/lib/Makefile
86622index c55a037..fb46e3b 100644
86623--- a/lib/Makefile
86624+++ b/lib/Makefile
86625@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
86626
86627 obj-$(CONFIG_BTREE) += btree.o
86628 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
86629-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
86630+obj-y += list_debug.o
86631 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
86632
86633 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
86634diff --git a/lib/bitmap.c b/lib/bitmap.c
86635index 06f7e4f..f3cf2b0 100644
86636--- a/lib/bitmap.c
86637+++ b/lib/bitmap.c
86638@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
86639 {
86640 int c, old_c, totaldigits, ndigits, nchunks, nbits;
86641 u32 chunk;
86642- const char __user __force *ubuf = (const char __user __force *)buf;
86643+ const char __user *ubuf = (const char __force_user *)buf;
86644
86645 bitmap_zero(maskp, nmaskbits);
86646
86647@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
86648 {
86649 if (!access_ok(VERIFY_READ, ubuf, ulen))
86650 return -EFAULT;
86651- return __bitmap_parse((const char __force *)ubuf,
86652+ return __bitmap_parse((const char __force_kernel *)ubuf,
86653 ulen, 1, maskp, nmaskbits);
86654
86655 }
86656@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
86657 {
86658 unsigned a, b;
86659 int c, old_c, totaldigits;
86660- const char __user __force *ubuf = (const char __user __force *)buf;
86661+ const char __user *ubuf = (const char __force_user *)buf;
86662 int exp_digit, in_range;
86663
86664 totaldigits = c = 0;
86665@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
86666 {
86667 if (!access_ok(VERIFY_READ, ubuf, ulen))
86668 return -EFAULT;
86669- return __bitmap_parselist((const char __force *)ubuf,
86670+ return __bitmap_parselist((const char __force_kernel *)ubuf,
86671 ulen, 1, maskp, nmaskbits);
86672 }
86673 EXPORT_SYMBOL(bitmap_parselist_user);
86674diff --git a/lib/bug.c b/lib/bug.c
86675index 1686034..a9c00c8 100644
86676--- a/lib/bug.c
86677+++ b/lib/bug.c
86678@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
86679 return BUG_TRAP_TYPE_NONE;
86680
86681 bug = find_bug(bugaddr);
86682+ if (!bug)
86683+ return BUG_TRAP_TYPE_NONE;
86684
86685 file = NULL;
86686 line = 0;
86687diff --git a/lib/debugobjects.c b/lib/debugobjects.c
86688index 37061ed..da83f48 100644
86689--- a/lib/debugobjects.c
86690+++ b/lib/debugobjects.c
86691@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
86692 if (limit > 4)
86693 return;
86694
86695- is_on_stack = object_is_on_stack(addr);
86696+ is_on_stack = object_starts_on_stack(addr);
86697 if (is_on_stack == onstack)
86698 return;
86699
86700diff --git a/lib/devres.c b/lib/devres.c
86701index 8235331..5881053 100644
86702--- a/lib/devres.c
86703+++ b/lib/devres.c
86704@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
86705 void devm_iounmap(struct device *dev, void __iomem *addr)
86706 {
86707 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
86708- (void *)addr));
86709+ (void __force *)addr));
86710 iounmap(addr);
86711 }
86712 EXPORT_SYMBOL(devm_iounmap);
86713@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
86714 {
86715 ioport_unmap(addr);
86716 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
86717- devm_ioport_map_match, (void *)addr));
86718+ devm_ioport_map_match, (void __force *)addr));
86719 }
86720 EXPORT_SYMBOL(devm_ioport_unmap);
86721 #endif /* CONFIG_HAS_IOPORT */
86722diff --git a/lib/div64.c b/lib/div64.c
86723index a163b6c..9618fa5 100644
86724--- a/lib/div64.c
86725+++ b/lib/div64.c
86726@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
86727 EXPORT_SYMBOL(__div64_32);
86728
86729 #ifndef div_s64_rem
86730-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
86731+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
86732 {
86733 u64 quotient;
86734
86735@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
86736 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
86737 */
86738 #ifndef div64_u64
86739-u64 div64_u64(u64 dividend, u64 divisor)
86740+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
86741 {
86742 u32 high = divisor >> 32;
86743 u64 quot;
86744diff --git a/lib/dma-debug.c b/lib/dma-debug.c
86745index d87a17a..ac0d79a 100644
86746--- a/lib/dma-debug.c
86747+++ b/lib/dma-debug.c
86748@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
86749
86750 void dma_debug_add_bus(struct bus_type *bus)
86751 {
86752- struct notifier_block *nb;
86753+ notifier_block_no_const *nb;
86754
86755 if (global_disable)
86756 return;
86757@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
86758
86759 static void check_for_stack(struct device *dev, void *addr)
86760 {
86761- if (object_is_on_stack(addr))
86762+ if (object_starts_on_stack(addr))
86763 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
86764 "stack [addr=%p]\n", addr);
86765 }
86766diff --git a/lib/inflate.c b/lib/inflate.c
86767index 013a761..c28f3fc 100644
86768--- a/lib/inflate.c
86769+++ b/lib/inflate.c
86770@@ -269,7 +269,7 @@ static void free(void *where)
86771 malloc_ptr = free_mem_ptr;
86772 }
86773 #else
86774-#define malloc(a) kmalloc(a, GFP_KERNEL)
86775+#define malloc(a) kmalloc((a), GFP_KERNEL)
86776 #define free(a) kfree(a)
86777 #endif
86778
86779diff --git a/lib/ioremap.c b/lib/ioremap.c
86780index 0c9216c..863bd89 100644
86781--- a/lib/ioremap.c
86782+++ b/lib/ioremap.c
86783@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
86784 unsigned long next;
86785
86786 phys_addr -= addr;
86787- pmd = pmd_alloc(&init_mm, pud, addr);
86788+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
86789 if (!pmd)
86790 return -ENOMEM;
86791 do {
86792@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
86793 unsigned long next;
86794
86795 phys_addr -= addr;
86796- pud = pud_alloc(&init_mm, pgd, addr);
86797+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
86798 if (!pud)
86799 return -ENOMEM;
86800 do {
86801diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
86802index bd2bea9..6b3c95e 100644
86803--- a/lib/is_single_threaded.c
86804+++ b/lib/is_single_threaded.c
86805@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
86806 struct task_struct *p, *t;
86807 bool ret;
86808
86809+ if (!mm)
86810+ return true;
86811+
86812 if (atomic_read(&task->signal->live) != 1)
86813 return false;
86814
86815diff --git a/lib/kobject.c b/lib/kobject.c
86816index b7e29a6..2f3ca75 100644
86817--- a/lib/kobject.c
86818+++ b/lib/kobject.c
86819@@ -805,7 +805,7 @@ static struct kset *kset_create(const char *name,
86820 kset = kzalloc(sizeof(*kset), GFP_KERNEL);
86821 if (!kset)
86822 return NULL;
86823- retval = kobject_set_name(&kset->kobj, name);
86824+ retval = kobject_set_name(&kset->kobj, "%s", name);
86825 if (retval) {
86826 kfree(kset);
86827 return NULL;
86828@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
86829
86830
86831 static DEFINE_SPINLOCK(kobj_ns_type_lock);
86832-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
86833+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
86834
86835-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
86836+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
86837 {
86838 enum kobj_ns_type type = ops->type;
86839 int error;
86840diff --git a/lib/list_debug.c b/lib/list_debug.c
86841index c24c2f7..06e070b 100644
86842--- a/lib/list_debug.c
86843+++ b/lib/list_debug.c
86844@@ -11,7 +11,9 @@
86845 #include <linux/bug.h>
86846 #include <linux/kernel.h>
86847 #include <linux/rculist.h>
86848+#include <linux/mm.h>
86849
86850+#ifdef CONFIG_DEBUG_LIST
86851 /*
86852 * Insert a new entry between two known consecutive entries.
86853 *
86854@@ -19,21 +21,32 @@
86855 * the prev/next entries already!
86856 */
86857
86858-void __list_add(struct list_head *new,
86859- struct list_head *prev,
86860- struct list_head *next)
86861+static bool __list_add_debug(struct list_head *new,
86862+ struct list_head *prev,
86863+ struct list_head *next)
86864 {
86865- WARN(next->prev != prev,
86866+ if (WARN(next->prev != prev,
86867 "list_add corruption. next->prev should be "
86868 "prev (%p), but was %p. (next=%p).\n",
86869- prev, next->prev, next);
86870- WARN(prev->next != next,
86871+ prev, next->prev, next) ||
86872+ WARN(prev->next != next,
86873 "list_add corruption. prev->next should be "
86874 "next (%p), but was %p. (prev=%p).\n",
86875- next, prev->next, prev);
86876- WARN(new == prev || new == next,
86877- "list_add double add: new=%p, prev=%p, next=%p.\n",
86878- new, prev, next);
86879+ next, prev->next, prev) ||
86880+ WARN(new == prev || new == next,
86881+ "list_add double add: new=%p, prev=%p, next=%p.\n",
86882+ new, prev, next))
86883+ return false;
86884+ return true;
86885+}
86886+
86887+void __list_add(struct list_head *new,
86888+ struct list_head *prev,
86889+ struct list_head *next)
86890+{
86891+ if (!__list_add_debug(new, prev, next))
86892+ return;
86893+
86894 next->prev = new;
86895 new->next = next;
86896 new->prev = prev;
86897@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
86898 }
86899 EXPORT_SYMBOL(__list_add);
86900
86901-void __list_del_entry(struct list_head *entry)
86902+static bool __list_del_entry_debug(struct list_head *entry)
86903 {
86904 struct list_head *prev, *next;
86905
86906@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
86907 WARN(next->prev != entry,
86908 "list_del corruption. next->prev should be %p, "
86909 "but was %p\n", entry, next->prev))
86910+ return false;
86911+ return true;
86912+}
86913+
86914+void __list_del_entry(struct list_head *entry)
86915+{
86916+ if (!__list_del_entry_debug(entry))
86917 return;
86918
86919- __list_del(prev, next);
86920+ __list_del(entry->prev, entry->next);
86921 }
86922 EXPORT_SYMBOL(__list_del_entry);
86923
86924@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
86925 void __list_add_rcu(struct list_head *new,
86926 struct list_head *prev, struct list_head *next)
86927 {
86928- WARN(next->prev != prev,
86929- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
86930- prev, next->prev, next);
86931- WARN(prev->next != next,
86932- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
86933- next, prev->next, prev);
86934+ if (!__list_add_debug(new, prev, next))
86935+ return;
86936+
86937 new->next = next;
86938 new->prev = prev;
86939 rcu_assign_pointer(list_next_rcu(prev), new);
86940 next->prev = new;
86941 }
86942 EXPORT_SYMBOL(__list_add_rcu);
86943+#endif
86944+
86945+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
86946+{
86947+#ifdef CONFIG_DEBUG_LIST
86948+ if (!__list_add_debug(new, prev, next))
86949+ return;
86950+#endif
86951+
86952+ pax_open_kernel();
86953+ next->prev = new;
86954+ new->next = next;
86955+ new->prev = prev;
86956+ prev->next = new;
86957+ pax_close_kernel();
86958+}
86959+EXPORT_SYMBOL(__pax_list_add);
86960+
86961+void pax_list_del(struct list_head *entry)
86962+{
86963+#ifdef CONFIG_DEBUG_LIST
86964+ if (!__list_del_entry_debug(entry))
86965+ return;
86966+#endif
86967+
86968+ pax_open_kernel();
86969+ __list_del(entry->prev, entry->next);
86970+ entry->next = LIST_POISON1;
86971+ entry->prev = LIST_POISON2;
86972+ pax_close_kernel();
86973+}
86974+EXPORT_SYMBOL(pax_list_del);
86975+
86976+void pax_list_del_init(struct list_head *entry)
86977+{
86978+ pax_open_kernel();
86979+ __list_del(entry->prev, entry->next);
86980+ INIT_LIST_HEAD(entry);
86981+ pax_close_kernel();
86982+}
86983+EXPORT_SYMBOL(pax_list_del_init);
86984+
86985+void __pax_list_add_rcu(struct list_head *new,
86986+ struct list_head *prev, struct list_head *next)
86987+{
86988+#ifdef CONFIG_DEBUG_LIST
86989+ if (!__list_add_debug(new, prev, next))
86990+ return;
86991+#endif
86992+
86993+ pax_open_kernel();
86994+ new->next = next;
86995+ new->prev = prev;
86996+ rcu_assign_pointer(list_next_rcu(prev), new);
86997+ next->prev = new;
86998+ pax_close_kernel();
86999+}
87000+EXPORT_SYMBOL(__pax_list_add_rcu);
87001+
87002+void pax_list_del_rcu(struct list_head *entry)
87003+{
87004+#ifdef CONFIG_DEBUG_LIST
87005+ if (!__list_del_entry_debug(entry))
87006+ return;
87007+#endif
87008+
87009+ pax_open_kernel();
87010+ __list_del(entry->prev, entry->next);
87011+ entry->next = LIST_POISON1;
87012+ entry->prev = LIST_POISON2;
87013+ pax_close_kernel();
87014+}
87015+EXPORT_SYMBOL(pax_list_del_rcu);
87016diff --git a/lib/radix-tree.c b/lib/radix-tree.c
87017index e796429..6e38f9f 100644
87018--- a/lib/radix-tree.c
87019+++ b/lib/radix-tree.c
87020@@ -92,7 +92,7 @@ struct radix_tree_preload {
87021 int nr;
87022 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
87023 };
87024-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
87025+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
87026
87027 static inline void *ptr_to_indirect(void *ptr)
87028 {
87029diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
87030index bb2b201..46abaf9 100644
87031--- a/lib/strncpy_from_user.c
87032+++ b/lib/strncpy_from_user.c
87033@@ -21,7 +21,7 @@
87034 */
87035 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
87036 {
87037- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87038+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87039 long res = 0;
87040
87041 /*
87042diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
87043index a28df52..3d55877 100644
87044--- a/lib/strnlen_user.c
87045+++ b/lib/strnlen_user.c
87046@@ -26,7 +26,7 @@
87047 */
87048 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
87049 {
87050- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87051+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87052 long align, res = 0;
87053 unsigned long c;
87054
87055diff --git a/lib/swiotlb.c b/lib/swiotlb.c
87056index d23762e..e21eab2 100644
87057--- a/lib/swiotlb.c
87058+++ b/lib/swiotlb.c
87059@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
87060
87061 void
87062 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
87063- dma_addr_t dev_addr)
87064+ dma_addr_t dev_addr, struct dma_attrs *attrs)
87065 {
87066 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
87067
87068diff --git a/lib/usercopy.c b/lib/usercopy.c
87069index 4f5b1dd..7cab418 100644
87070--- a/lib/usercopy.c
87071+++ b/lib/usercopy.c
87072@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
87073 WARN(1, "Buffer overflow detected!\n");
87074 }
87075 EXPORT_SYMBOL(copy_from_user_overflow);
87076+
87077+void copy_to_user_overflow(void)
87078+{
87079+ WARN(1, "Buffer overflow detected!\n");
87080+}
87081+EXPORT_SYMBOL(copy_to_user_overflow);
87082diff --git a/lib/vsprintf.c b/lib/vsprintf.c
87083index e149c64..24aa71a 100644
87084--- a/lib/vsprintf.c
87085+++ b/lib/vsprintf.c
87086@@ -16,6 +16,9 @@
87087 * - scnprintf and vscnprintf
87088 */
87089
87090+#ifdef CONFIG_GRKERNSEC_HIDESYM
87091+#define __INCLUDED_BY_HIDESYM 1
87092+#endif
87093 #include <stdarg.h>
87094 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
87095 #include <linux/types.h>
87096@@ -981,7 +984,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
87097 return number(buf, end, *(const netdev_features_t *)addr, spec);
87098 }
87099
87100+#ifdef CONFIG_GRKERNSEC_HIDESYM
87101+int kptr_restrict __read_mostly = 2;
87102+#else
87103 int kptr_restrict __read_mostly;
87104+#endif
87105
87106 /*
87107 * Show a '%p' thing. A kernel extension is that the '%p' is followed
87108@@ -994,6 +1001,7 @@ int kptr_restrict __read_mostly;
87109 * - 'f' For simple symbolic function names without offset
87110 * - 'S' For symbolic direct pointers with offset
87111 * - 's' For symbolic direct pointers without offset
87112+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
87113 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
87114 * - 'B' For backtraced symbolic direct pointers with offset
87115 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
87116@@ -1052,12 +1060,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87117
87118 if (!ptr && *fmt != 'K') {
87119 /*
87120- * Print (null) with the same width as a pointer so it makes
87121+ * Print (nil) with the same width as a pointer so it makes
87122 * tabular output look nice.
87123 */
87124 if (spec.field_width == -1)
87125 spec.field_width = default_width;
87126- return string(buf, end, "(null)", spec);
87127+ return string(buf, end, "(nil)", spec);
87128 }
87129
87130 switch (*fmt) {
87131@@ -1067,6 +1075,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87132 /* Fallthrough */
87133 case 'S':
87134 case 's':
87135+#ifdef CONFIG_GRKERNSEC_HIDESYM
87136+ break;
87137+#else
87138+ return symbol_string(buf, end, ptr, spec, fmt);
87139+#endif
87140+ case 'A':
87141 case 'B':
87142 return symbol_string(buf, end, ptr, spec, fmt);
87143 case 'R':
87144@@ -1107,6 +1121,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87145 va_end(va);
87146 return buf;
87147 }
87148+ case 'P':
87149+ break;
87150 case 'K':
87151 /*
87152 * %pK cannot be used in IRQ context because its test
87153@@ -1136,6 +1152,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87154 return number(buf, end,
87155 (unsigned long long) *((phys_addr_t *)ptr), spec);
87156 }
87157+
87158+#ifdef CONFIG_GRKERNSEC_HIDESYM
87159+ /* 'P' = approved pointers to copy to userland,
87160+ as in the /proc/kallsyms case, as we make it display nothing
87161+ for non-root users, and the real contents for root users
87162+ Also ignore 'K' pointers, since we force their NULLing for non-root users
87163+ above
87164+ */
87165+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
87166+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
87167+ dump_stack();
87168+ ptr = NULL;
87169+ }
87170+#endif
87171+
87172 spec.flags |= SMALL;
87173 if (spec.field_width == -1) {
87174 spec.field_width = default_width;
87175@@ -1857,11 +1888,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
87176 typeof(type) value; \
87177 if (sizeof(type) == 8) { \
87178 args = PTR_ALIGN(args, sizeof(u32)); \
87179- *(u32 *)&value = *(u32 *)args; \
87180- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
87181+ *(u32 *)&value = *(const u32 *)args; \
87182+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
87183 } else { \
87184 args = PTR_ALIGN(args, sizeof(type)); \
87185- value = *(typeof(type) *)args; \
87186+ value = *(const typeof(type) *)args; \
87187 } \
87188 args += sizeof(type); \
87189 value; \
87190@@ -1924,7 +1955,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
87191 case FORMAT_TYPE_STR: {
87192 const char *str_arg = args;
87193 args += strlen(str_arg) + 1;
87194- str = string(str, end, (char *)str_arg, spec);
87195+ str = string(str, end, str_arg, spec);
87196 break;
87197 }
87198
87199diff --git a/localversion-grsec b/localversion-grsec
87200new file mode 100644
87201index 0000000..7cd6065
87202--- /dev/null
87203+++ b/localversion-grsec
87204@@ -0,0 +1 @@
87205+-grsec
87206diff --git a/mm/Kconfig b/mm/Kconfig
87207index e742d06..c56fdd8 100644
87208--- a/mm/Kconfig
87209+++ b/mm/Kconfig
87210@@ -317,10 +317,10 @@ config KSM
87211 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
87212
87213 config DEFAULT_MMAP_MIN_ADDR
87214- int "Low address space to protect from user allocation"
87215+ int "Low address space to protect from user allocation"
87216 depends on MMU
87217- default 4096
87218- help
87219+ default 65536
87220+ help
87221 This is the portion of low virtual memory which should be protected
87222 from userspace allocation. Keeping a user from writing to low pages
87223 can help reduce the impact of kernel NULL pointer bugs.
87224@@ -351,7 +351,7 @@ config MEMORY_FAILURE
87225
87226 config HWPOISON_INJECT
87227 tristate "HWPoison pages injector"
87228- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
87229+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
87230 select PROC_PAGE_MONITOR
87231
87232 config NOMMU_INITIAL_TRIM_EXCESS
87233diff --git a/mm/backing-dev.c b/mm/backing-dev.c
87234index 5025174..9d67dcd 100644
87235--- a/mm/backing-dev.c
87236+++ b/mm/backing-dev.c
87237@@ -12,7 +12,7 @@
87238 #include <linux/device.h>
87239 #include <trace/events/writeback.h>
87240
87241-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
87242+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
87243
87244 struct backing_dev_info default_backing_dev_info = {
87245 .name = "default",
87246@@ -515,7 +515,6 @@ EXPORT_SYMBOL(bdi_destroy);
87247 int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
87248 unsigned int cap)
87249 {
87250- char tmp[32];
87251 int err;
87252
87253 bdi->name = name;
87254@@ -524,8 +523,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
87255 if (err)
87256 return err;
87257
87258- sprintf(tmp, "%.28s%s", name, "-%d");
87259- err = bdi_register(bdi, NULL, tmp, atomic_long_inc_return(&bdi_seq));
87260+ err = bdi_register(bdi, NULL, "%.28s-%ld", name, atomic_long_inc_return_unchecked(&bdi_seq));
87261 if (err) {
87262 bdi_destroy(bdi);
87263 return err;
87264diff --git a/mm/filemap.c b/mm/filemap.c
87265index 7905fe7..f59502b 100644
87266--- a/mm/filemap.c
87267+++ b/mm/filemap.c
87268@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
87269 struct address_space *mapping = file->f_mapping;
87270
87271 if (!mapping->a_ops->readpage)
87272- return -ENOEXEC;
87273+ return -ENODEV;
87274 file_accessed(file);
87275 vma->vm_ops = &generic_file_vm_ops;
87276 return 0;
87277@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
87278
87279 while (bytes) {
87280 char __user *buf = iov->iov_base + base;
87281- int copy = min(bytes, iov->iov_len - base);
87282+ size_t copy = min(bytes, iov->iov_len - base);
87283
87284 base = 0;
87285 left = __copy_from_user_inatomic(vaddr, buf, copy);
87286@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
87287 BUG_ON(!in_atomic());
87288 kaddr = kmap_atomic(page);
87289 if (likely(i->nr_segs == 1)) {
87290- int left;
87291+ size_t left;
87292 char __user *buf = i->iov->iov_base + i->iov_offset;
87293 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
87294 copied = bytes - left;
87295@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
87296
87297 kaddr = kmap(page);
87298 if (likely(i->nr_segs == 1)) {
87299- int left;
87300+ size_t left;
87301 char __user *buf = i->iov->iov_base + i->iov_offset;
87302 left = __copy_from_user(kaddr + offset, buf, bytes);
87303 copied = bytes - left;
87304@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
87305 * zero-length segments (without overruning the iovec).
87306 */
87307 while (bytes || unlikely(i->count && !iov->iov_len)) {
87308- int copy;
87309+ size_t copy;
87310
87311 copy = min(bytes, iov->iov_len - base);
87312 BUG_ON(!i->count || i->count < copy);
87313@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
87314 *pos = i_size_read(inode);
87315
87316 if (limit != RLIM_INFINITY) {
87317+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
87318 if (*pos >= limit) {
87319 send_sig(SIGXFSZ, current, 0);
87320 return -EFBIG;
87321diff --git a/mm/fremap.c b/mm/fremap.c
87322index 87da359..3f41cb1 100644
87323--- a/mm/fremap.c
87324+++ b/mm/fremap.c
87325@@ -158,6 +158,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
87326 retry:
87327 vma = find_vma(mm, start);
87328
87329+#ifdef CONFIG_PAX_SEGMEXEC
87330+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
87331+ goto out;
87332+#endif
87333+
87334 /*
87335 * Make sure the vma is shared, that it supports prefaulting,
87336 * and that the remapped range is valid and fully within
87337diff --git a/mm/highmem.c b/mm/highmem.c
87338index b32b70c..e512eb0 100644
87339--- a/mm/highmem.c
87340+++ b/mm/highmem.c
87341@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
87342 * So no dangers, even with speculative execution.
87343 */
87344 page = pte_page(pkmap_page_table[i]);
87345+ pax_open_kernel();
87346 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
87347-
87348+ pax_close_kernel();
87349 set_page_address(page, NULL);
87350 need_flush = 1;
87351 }
87352@@ -198,9 +199,11 @@ start:
87353 }
87354 }
87355 vaddr = PKMAP_ADDR(last_pkmap_nr);
87356+
87357+ pax_open_kernel();
87358 set_pte_at(&init_mm, vaddr,
87359 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
87360-
87361+ pax_close_kernel();
87362 pkmap_count[last_pkmap_nr] = 1;
87363 set_page_address(page, (void *)vaddr);
87364
87365diff --git a/mm/hugetlb.c b/mm/hugetlb.c
87366index 7c5eb85..5c01c2f 100644
87367--- a/mm/hugetlb.c
87368+++ b/mm/hugetlb.c
87369@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
87370 struct hstate *h = &default_hstate;
87371 unsigned long tmp;
87372 int ret;
87373+ ctl_table_no_const hugetlb_table;
87374
87375 tmp = h->max_huge_pages;
87376
87377 if (write && h->order >= MAX_ORDER)
87378 return -EINVAL;
87379
87380- table->data = &tmp;
87381- table->maxlen = sizeof(unsigned long);
87382- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
87383+ hugetlb_table = *table;
87384+ hugetlb_table.data = &tmp;
87385+ hugetlb_table.maxlen = sizeof(unsigned long);
87386+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
87387 if (ret)
87388 goto out;
87389
87390@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
87391 struct hstate *h = &default_hstate;
87392 unsigned long tmp;
87393 int ret;
87394+ ctl_table_no_const hugetlb_table;
87395
87396 tmp = h->nr_overcommit_huge_pages;
87397
87398 if (write && h->order >= MAX_ORDER)
87399 return -EINVAL;
87400
87401- table->data = &tmp;
87402- table->maxlen = sizeof(unsigned long);
87403- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
87404+ hugetlb_table = *table;
87405+ hugetlb_table.data = &tmp;
87406+ hugetlb_table.maxlen = sizeof(unsigned long);
87407+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
87408 if (ret)
87409 goto out;
87410
87411@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
87412 return 1;
87413 }
87414
87415+#ifdef CONFIG_PAX_SEGMEXEC
87416+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
87417+{
87418+ struct mm_struct *mm = vma->vm_mm;
87419+ struct vm_area_struct *vma_m;
87420+ unsigned long address_m;
87421+ pte_t *ptep_m;
87422+
87423+ vma_m = pax_find_mirror_vma(vma);
87424+ if (!vma_m)
87425+ return;
87426+
87427+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87428+ address_m = address + SEGMEXEC_TASK_SIZE;
87429+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
87430+ get_page(page_m);
87431+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
87432+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
87433+}
87434+#endif
87435+
87436 /*
87437 * Hugetlb_cow() should be called with page lock of the original hugepage held.
87438 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
87439@@ -2663,6 +2688,11 @@ retry_avoidcopy:
87440 make_huge_pte(vma, new_page, 1));
87441 page_remove_rmap(old_page);
87442 hugepage_add_new_anon_rmap(new_page, vma, address);
87443+
87444+#ifdef CONFIG_PAX_SEGMEXEC
87445+ pax_mirror_huge_pte(vma, address, new_page);
87446+#endif
87447+
87448 /* Make the old page be freed below */
87449 new_page = old_page;
87450 }
87451@@ -2821,6 +2851,10 @@ retry:
87452 && (vma->vm_flags & VM_SHARED)));
87453 set_huge_pte_at(mm, address, ptep, new_pte);
87454
87455+#ifdef CONFIG_PAX_SEGMEXEC
87456+ pax_mirror_huge_pte(vma, address, page);
87457+#endif
87458+
87459 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
87460 /* Optimization, do the COW without a second fault */
87461 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
87462@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87463 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
87464 struct hstate *h = hstate_vma(vma);
87465
87466+#ifdef CONFIG_PAX_SEGMEXEC
87467+ struct vm_area_struct *vma_m;
87468+#endif
87469+
87470 address &= huge_page_mask(h);
87471
87472 ptep = huge_pte_offset(mm, address);
87473@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87474 VM_FAULT_SET_HINDEX(hstate_index(h));
87475 }
87476
87477+#ifdef CONFIG_PAX_SEGMEXEC
87478+ vma_m = pax_find_mirror_vma(vma);
87479+ if (vma_m) {
87480+ unsigned long address_m;
87481+
87482+ if (vma->vm_start > vma_m->vm_start) {
87483+ address_m = address;
87484+ address -= SEGMEXEC_TASK_SIZE;
87485+ vma = vma_m;
87486+ h = hstate_vma(vma);
87487+ } else
87488+ address_m = address + SEGMEXEC_TASK_SIZE;
87489+
87490+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
87491+ return VM_FAULT_OOM;
87492+ address_m &= HPAGE_MASK;
87493+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
87494+ }
87495+#endif
87496+
87497 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
87498 if (!ptep)
87499 return VM_FAULT_OOM;
87500diff --git a/mm/internal.h b/mm/internal.h
87501index 8562de0..92b2073 100644
87502--- a/mm/internal.h
87503+++ b/mm/internal.h
87504@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
87505 * in mm/page_alloc.c
87506 */
87507 extern void __free_pages_bootmem(struct page *page, unsigned int order);
87508+extern void free_compound_page(struct page *page);
87509 extern void prep_compound_page(struct page *page, unsigned long order);
87510 #ifdef CONFIG_MEMORY_FAILURE
87511 extern bool is_free_buddy_page(struct page *page);
87512@@ -355,7 +356,7 @@ extern u32 hwpoison_filter_enable;
87513
87514 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
87515 unsigned long, unsigned long,
87516- unsigned long, unsigned long);
87517+ unsigned long, unsigned long) __intentional_overflow(-1);
87518
87519 extern void set_pageblock_order(void);
87520 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
87521diff --git a/mm/kmemleak.c b/mm/kmemleak.c
87522index c8d7f31..2dbeffd 100644
87523--- a/mm/kmemleak.c
87524+++ b/mm/kmemleak.c
87525@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
87526
87527 for (i = 0; i < object->trace_len; i++) {
87528 void *ptr = (void *)object->trace[i];
87529- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
87530+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
87531 }
87532 }
87533
87534@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
87535 return -ENOMEM;
87536 }
87537
87538- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
87539+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
87540 &kmemleak_fops);
87541 if (!dentry)
87542 pr_warning("Failed to create the debugfs kmemleak file\n");
87543diff --git a/mm/maccess.c b/mm/maccess.c
87544index d53adf9..03a24bf 100644
87545--- a/mm/maccess.c
87546+++ b/mm/maccess.c
87547@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
87548 set_fs(KERNEL_DS);
87549 pagefault_disable();
87550 ret = __copy_from_user_inatomic(dst,
87551- (__force const void __user *)src, size);
87552+ (const void __force_user *)src, size);
87553 pagefault_enable();
87554 set_fs(old_fs);
87555
87556@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
87557
87558 set_fs(KERNEL_DS);
87559 pagefault_disable();
87560- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
87561+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
87562 pagefault_enable();
87563 set_fs(old_fs);
87564
87565diff --git a/mm/madvise.c b/mm/madvise.c
87566index 7055883..aafb1ed 100644
87567--- a/mm/madvise.c
87568+++ b/mm/madvise.c
87569@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
87570 pgoff_t pgoff;
87571 unsigned long new_flags = vma->vm_flags;
87572
87573+#ifdef CONFIG_PAX_SEGMEXEC
87574+ struct vm_area_struct *vma_m;
87575+#endif
87576+
87577 switch (behavior) {
87578 case MADV_NORMAL:
87579 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
87580@@ -126,6 +130,13 @@ success:
87581 /*
87582 * vm_flags is protected by the mmap_sem held in write mode.
87583 */
87584+
87585+#ifdef CONFIG_PAX_SEGMEXEC
87586+ vma_m = pax_find_mirror_vma(vma);
87587+ if (vma_m)
87588+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
87589+#endif
87590+
87591 vma->vm_flags = new_flags;
87592
87593 out:
87594@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
87595 struct vm_area_struct ** prev,
87596 unsigned long start, unsigned long end)
87597 {
87598+
87599+#ifdef CONFIG_PAX_SEGMEXEC
87600+ struct vm_area_struct *vma_m;
87601+#endif
87602+
87603 *prev = vma;
87604 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
87605 return -EINVAL;
87606@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
87607 zap_page_range(vma, start, end - start, &details);
87608 } else
87609 zap_page_range(vma, start, end - start, NULL);
87610+
87611+#ifdef CONFIG_PAX_SEGMEXEC
87612+ vma_m = pax_find_mirror_vma(vma);
87613+ if (vma_m) {
87614+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
87615+ struct zap_details details = {
87616+ .nonlinear_vma = vma_m,
87617+ .last_index = ULONG_MAX,
87618+ };
87619+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
87620+ } else
87621+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
87622+ }
87623+#endif
87624+
87625 return 0;
87626 }
87627
87628@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
87629 if (end < start)
87630 return error;
87631
87632+#ifdef CONFIG_PAX_SEGMEXEC
87633+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
87634+ if (end > SEGMEXEC_TASK_SIZE)
87635+ return error;
87636+ } else
87637+#endif
87638+
87639+ if (end > TASK_SIZE)
87640+ return error;
87641+
87642 error = 0;
87643 if (end == start)
87644 return error;
87645diff --git a/mm/memory-failure.c b/mm/memory-failure.c
87646index ceb0c7f..b2b8e94 100644
87647--- a/mm/memory-failure.c
87648+++ b/mm/memory-failure.c
87649@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
87650
87651 int sysctl_memory_failure_recovery __read_mostly = 1;
87652
87653-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
87654+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
87655
87656 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
87657
87658@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
87659 pfn, t->comm, t->pid);
87660 si.si_signo = SIGBUS;
87661 si.si_errno = 0;
87662- si.si_addr = (void *)addr;
87663+ si.si_addr = (void __user *)addr;
87664 #ifdef __ARCH_SI_TRAPNO
87665 si.si_trapno = trapno;
87666 #endif
87667@@ -760,7 +760,7 @@ static struct page_state {
87668 unsigned long res;
87669 char *msg;
87670 int (*action)(struct page *p, unsigned long pfn);
87671-} error_states[] = {
87672+} __do_const error_states[] = {
87673 { reserved, reserved, "reserved kernel", me_kernel },
87674 /*
87675 * free pages are specially detected outside this table:
87676@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
87677 nr_pages = 1 << compound_order(hpage);
87678 else /* normal page or thp */
87679 nr_pages = 1;
87680- atomic_long_add(nr_pages, &num_poisoned_pages);
87681+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
87682
87683 /*
87684 * We need/can do nothing about count=0 pages.
87685@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
87686 if (!PageHWPoison(hpage)
87687 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
87688 || (p != hpage && TestSetPageHWPoison(hpage))) {
87689- atomic_long_sub(nr_pages, &num_poisoned_pages);
87690+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87691 return 0;
87692 }
87693 set_page_hwpoison_huge_page(hpage);
87694@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
87695 }
87696 if (hwpoison_filter(p)) {
87697 if (TestClearPageHWPoison(p))
87698- atomic_long_sub(nr_pages, &num_poisoned_pages);
87699+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87700 unlock_page(hpage);
87701 put_page(hpage);
87702 return 0;
87703@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
87704 return 0;
87705 }
87706 if (TestClearPageHWPoison(p))
87707- atomic_long_sub(nr_pages, &num_poisoned_pages);
87708+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87709 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
87710 return 0;
87711 }
87712@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
87713 */
87714 if (TestClearPageHWPoison(page)) {
87715 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
87716- atomic_long_sub(nr_pages, &num_poisoned_pages);
87717+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87718 freeit = 1;
87719 if (PageHuge(page))
87720 clear_page_hwpoison_huge_page(page);
87721@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
87722 } else {
87723 set_page_hwpoison_huge_page(hpage);
87724 dequeue_hwpoisoned_huge_page(hpage);
87725- atomic_long_add(1 << compound_trans_order(hpage),
87726+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
87727 &num_poisoned_pages);
87728 }
87729 /* keep elevated page count for bad page */
87730@@ -1552,11 +1552,11 @@ int soft_offline_page(struct page *page, int flags)
87731 if (PageHuge(page)) {
87732 set_page_hwpoison_huge_page(hpage);
87733 dequeue_hwpoisoned_huge_page(hpage);
87734- atomic_long_add(1 << compound_trans_order(hpage),
87735+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
87736 &num_poisoned_pages);
87737 } else {
87738 SetPageHWPoison(page);
87739- atomic_long_inc(&num_poisoned_pages);
87740+ atomic_long_inc_unchecked(&num_poisoned_pages);
87741 }
87742 }
87743 /* keep elevated page count for bad page */
87744@@ -1596,7 +1596,7 @@ static int __soft_offline_page(struct page *page, int flags)
87745 put_page(page);
87746 pr_info("soft_offline: %#lx: invalidated\n", pfn);
87747 SetPageHWPoison(page);
87748- atomic_long_inc(&num_poisoned_pages);
87749+ atomic_long_inc_unchecked(&num_poisoned_pages);
87750 return 0;
87751 }
87752
87753@@ -1626,7 +1626,7 @@ static int __soft_offline_page(struct page *page, int flags)
87754 ret = -EIO;
87755 } else {
87756 SetPageHWPoison(page);
87757- atomic_long_inc(&num_poisoned_pages);
87758+ atomic_long_inc_unchecked(&num_poisoned_pages);
87759 }
87760 } else {
87761 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
87762diff --git a/mm/memory.c b/mm/memory.c
87763index 5a35443..7c0340f 100644
87764--- a/mm/memory.c
87765+++ b/mm/memory.c
87766@@ -428,6 +428,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
87767 free_pte_range(tlb, pmd, addr);
87768 } while (pmd++, addr = next, addr != end);
87769
87770+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
87771 start &= PUD_MASK;
87772 if (start < floor)
87773 return;
87774@@ -442,6 +443,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
87775 pmd = pmd_offset(pud, start);
87776 pud_clear(pud);
87777 pmd_free_tlb(tlb, pmd, start);
87778+#endif
87779+
87780 }
87781
87782 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
87783@@ -461,6 +464,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
87784 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
87785 } while (pud++, addr = next, addr != end);
87786
87787+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
87788 start &= PGDIR_MASK;
87789 if (start < floor)
87790 return;
87791@@ -475,6 +479,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
87792 pud = pud_offset(pgd, start);
87793 pgd_clear(pgd);
87794 pud_free_tlb(tlb, pud, start);
87795+#endif
87796+
87797 }
87798
87799 /*
87800@@ -1644,12 +1650,6 @@ no_page_table:
87801 return page;
87802 }
87803
87804-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
87805-{
87806- return stack_guard_page_start(vma, addr) ||
87807- stack_guard_page_end(vma, addr+PAGE_SIZE);
87808-}
87809-
87810 /**
87811 * __get_user_pages() - pin user pages in memory
87812 * @tsk: task_struct of target task
87813@@ -1736,10 +1736,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
87814
87815 i = 0;
87816
87817- do {
87818+ while (nr_pages) {
87819 struct vm_area_struct *vma;
87820
87821- vma = find_extend_vma(mm, start);
87822+ vma = find_vma(mm, start);
87823 if (!vma && in_gate_area(mm, start)) {
87824 unsigned long pg = start & PAGE_MASK;
87825 pgd_t *pgd;
87826@@ -1788,7 +1788,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
87827 goto next_page;
87828 }
87829
87830- if (!vma ||
87831+ if (!vma || start < vma->vm_start ||
87832 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
87833 !(vm_flags & vma->vm_flags))
87834 return i ? : -EFAULT;
87835@@ -1817,11 +1817,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
87836 int ret;
87837 unsigned int fault_flags = 0;
87838
87839- /* For mlock, just skip the stack guard page. */
87840- if (foll_flags & FOLL_MLOCK) {
87841- if (stack_guard_page(vma, start))
87842- goto next_page;
87843- }
87844 if (foll_flags & FOLL_WRITE)
87845 fault_flags |= FAULT_FLAG_WRITE;
87846 if (nonblocking)
87847@@ -1901,7 +1896,7 @@ next_page:
87848 start += page_increm * PAGE_SIZE;
87849 nr_pages -= page_increm;
87850 } while (nr_pages && start < vma->vm_end);
87851- } while (nr_pages);
87852+ }
87853 return i;
87854 }
87855 EXPORT_SYMBOL(__get_user_pages);
87856@@ -2108,6 +2103,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
87857 page_add_file_rmap(page);
87858 set_pte_at(mm, addr, pte, mk_pte(page, prot));
87859
87860+#ifdef CONFIG_PAX_SEGMEXEC
87861+ pax_mirror_file_pte(vma, addr, page, ptl);
87862+#endif
87863+
87864 retval = 0;
87865 pte_unmap_unlock(pte, ptl);
87866 return retval;
87867@@ -2152,9 +2151,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
87868 if (!page_count(page))
87869 return -EINVAL;
87870 if (!(vma->vm_flags & VM_MIXEDMAP)) {
87871+
87872+#ifdef CONFIG_PAX_SEGMEXEC
87873+ struct vm_area_struct *vma_m;
87874+#endif
87875+
87876 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
87877 BUG_ON(vma->vm_flags & VM_PFNMAP);
87878 vma->vm_flags |= VM_MIXEDMAP;
87879+
87880+#ifdef CONFIG_PAX_SEGMEXEC
87881+ vma_m = pax_find_mirror_vma(vma);
87882+ if (vma_m)
87883+ vma_m->vm_flags |= VM_MIXEDMAP;
87884+#endif
87885+
87886 }
87887 return insert_page(vma, addr, page, vma->vm_page_prot);
87888 }
87889@@ -2237,6 +2248,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
87890 unsigned long pfn)
87891 {
87892 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
87893+ BUG_ON(vma->vm_mirror);
87894
87895 if (addr < vma->vm_start || addr >= vma->vm_end)
87896 return -EFAULT;
87897@@ -2484,7 +2496,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
87898
87899 BUG_ON(pud_huge(*pud));
87900
87901- pmd = pmd_alloc(mm, pud, addr);
87902+ pmd = (mm == &init_mm) ?
87903+ pmd_alloc_kernel(mm, pud, addr) :
87904+ pmd_alloc(mm, pud, addr);
87905 if (!pmd)
87906 return -ENOMEM;
87907 do {
87908@@ -2504,7 +2518,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
87909 unsigned long next;
87910 int err;
87911
87912- pud = pud_alloc(mm, pgd, addr);
87913+ pud = (mm == &init_mm) ?
87914+ pud_alloc_kernel(mm, pgd, addr) :
87915+ pud_alloc(mm, pgd, addr);
87916 if (!pud)
87917 return -ENOMEM;
87918 do {
87919@@ -2592,6 +2608,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
87920 copy_user_highpage(dst, src, va, vma);
87921 }
87922
87923+#ifdef CONFIG_PAX_SEGMEXEC
87924+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
87925+{
87926+ struct mm_struct *mm = vma->vm_mm;
87927+ spinlock_t *ptl;
87928+ pte_t *pte, entry;
87929+
87930+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
87931+ entry = *pte;
87932+ if (!pte_present(entry)) {
87933+ if (!pte_none(entry)) {
87934+ BUG_ON(pte_file(entry));
87935+ free_swap_and_cache(pte_to_swp_entry(entry));
87936+ pte_clear_not_present_full(mm, address, pte, 0);
87937+ }
87938+ } else {
87939+ struct page *page;
87940+
87941+ flush_cache_page(vma, address, pte_pfn(entry));
87942+ entry = ptep_clear_flush(vma, address, pte);
87943+ BUG_ON(pte_dirty(entry));
87944+ page = vm_normal_page(vma, address, entry);
87945+ if (page) {
87946+ update_hiwater_rss(mm);
87947+ if (PageAnon(page))
87948+ dec_mm_counter_fast(mm, MM_ANONPAGES);
87949+ else
87950+ dec_mm_counter_fast(mm, MM_FILEPAGES);
87951+ page_remove_rmap(page);
87952+ page_cache_release(page);
87953+ }
87954+ }
87955+ pte_unmap_unlock(pte, ptl);
87956+}
87957+
87958+/* PaX: if vma is mirrored, synchronize the mirror's PTE
87959+ *
87960+ * the ptl of the lower mapped page is held on entry and is not released on exit
87961+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
87962+ */
87963+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
87964+{
87965+ struct mm_struct *mm = vma->vm_mm;
87966+ unsigned long address_m;
87967+ spinlock_t *ptl_m;
87968+ struct vm_area_struct *vma_m;
87969+ pmd_t *pmd_m;
87970+ pte_t *pte_m, entry_m;
87971+
87972+ BUG_ON(!page_m || !PageAnon(page_m));
87973+
87974+ vma_m = pax_find_mirror_vma(vma);
87975+ if (!vma_m)
87976+ return;
87977+
87978+ BUG_ON(!PageLocked(page_m));
87979+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87980+ address_m = address + SEGMEXEC_TASK_SIZE;
87981+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
87982+ pte_m = pte_offset_map(pmd_m, address_m);
87983+ ptl_m = pte_lockptr(mm, pmd_m);
87984+ if (ptl != ptl_m) {
87985+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
87986+ if (!pte_none(*pte_m))
87987+ goto out;
87988+ }
87989+
87990+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
87991+ page_cache_get(page_m);
87992+ page_add_anon_rmap(page_m, vma_m, address_m);
87993+ inc_mm_counter_fast(mm, MM_ANONPAGES);
87994+ set_pte_at(mm, address_m, pte_m, entry_m);
87995+ update_mmu_cache(vma_m, address_m, pte_m);
87996+out:
87997+ if (ptl != ptl_m)
87998+ spin_unlock(ptl_m);
87999+ pte_unmap(pte_m);
88000+ unlock_page(page_m);
88001+}
88002+
88003+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
88004+{
88005+ struct mm_struct *mm = vma->vm_mm;
88006+ unsigned long address_m;
88007+ spinlock_t *ptl_m;
88008+ struct vm_area_struct *vma_m;
88009+ pmd_t *pmd_m;
88010+ pte_t *pte_m, entry_m;
88011+
88012+ BUG_ON(!page_m || PageAnon(page_m));
88013+
88014+ vma_m = pax_find_mirror_vma(vma);
88015+ if (!vma_m)
88016+ return;
88017+
88018+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
88019+ address_m = address + SEGMEXEC_TASK_SIZE;
88020+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
88021+ pte_m = pte_offset_map(pmd_m, address_m);
88022+ ptl_m = pte_lockptr(mm, pmd_m);
88023+ if (ptl != ptl_m) {
88024+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
88025+ if (!pte_none(*pte_m))
88026+ goto out;
88027+ }
88028+
88029+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
88030+ page_cache_get(page_m);
88031+ page_add_file_rmap(page_m);
88032+ inc_mm_counter_fast(mm, MM_FILEPAGES);
88033+ set_pte_at(mm, address_m, pte_m, entry_m);
88034+ update_mmu_cache(vma_m, address_m, pte_m);
88035+out:
88036+ if (ptl != ptl_m)
88037+ spin_unlock(ptl_m);
88038+ pte_unmap(pte_m);
88039+}
88040+
88041+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
88042+{
88043+ struct mm_struct *mm = vma->vm_mm;
88044+ unsigned long address_m;
88045+ spinlock_t *ptl_m;
88046+ struct vm_area_struct *vma_m;
88047+ pmd_t *pmd_m;
88048+ pte_t *pte_m, entry_m;
88049+
88050+ vma_m = pax_find_mirror_vma(vma);
88051+ if (!vma_m)
88052+ return;
88053+
88054+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
88055+ address_m = address + SEGMEXEC_TASK_SIZE;
88056+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
88057+ pte_m = pte_offset_map(pmd_m, address_m);
88058+ ptl_m = pte_lockptr(mm, pmd_m);
88059+ if (ptl != ptl_m) {
88060+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
88061+ if (!pte_none(*pte_m))
88062+ goto out;
88063+ }
88064+
88065+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
88066+ set_pte_at(mm, address_m, pte_m, entry_m);
88067+out:
88068+ if (ptl != ptl_m)
88069+ spin_unlock(ptl_m);
88070+ pte_unmap(pte_m);
88071+}
88072+
88073+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
88074+{
88075+ struct page *page_m;
88076+ pte_t entry;
88077+
88078+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
88079+ goto out;
88080+
88081+ entry = *pte;
88082+ page_m = vm_normal_page(vma, address, entry);
88083+ if (!page_m)
88084+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
88085+ else if (PageAnon(page_m)) {
88086+ if (pax_find_mirror_vma(vma)) {
88087+ pte_unmap_unlock(pte, ptl);
88088+ lock_page(page_m);
88089+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
88090+ if (pte_same(entry, *pte))
88091+ pax_mirror_anon_pte(vma, address, page_m, ptl);
88092+ else
88093+ unlock_page(page_m);
88094+ }
88095+ } else
88096+ pax_mirror_file_pte(vma, address, page_m, ptl);
88097+
88098+out:
88099+ pte_unmap_unlock(pte, ptl);
88100+}
88101+#endif
88102+
88103 /*
88104 * This routine handles present pages, when users try to write
88105 * to a shared page. It is done by copying the page to a new address
88106@@ -2808,6 +3004,12 @@ gotten:
88107 */
88108 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
88109 if (likely(pte_same(*page_table, orig_pte))) {
88110+
88111+#ifdef CONFIG_PAX_SEGMEXEC
88112+ if (pax_find_mirror_vma(vma))
88113+ BUG_ON(!trylock_page(new_page));
88114+#endif
88115+
88116 if (old_page) {
88117 if (!PageAnon(old_page)) {
88118 dec_mm_counter_fast(mm, MM_FILEPAGES);
88119@@ -2859,6 +3061,10 @@ gotten:
88120 page_remove_rmap(old_page);
88121 }
88122
88123+#ifdef CONFIG_PAX_SEGMEXEC
88124+ pax_mirror_anon_pte(vma, address, new_page, ptl);
88125+#endif
88126+
88127 /* Free the old page.. */
88128 new_page = old_page;
88129 ret |= VM_FAULT_WRITE;
88130@@ -3134,6 +3340,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
88131 swap_free(entry);
88132 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
88133 try_to_free_swap(page);
88134+
88135+#ifdef CONFIG_PAX_SEGMEXEC
88136+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
88137+#endif
88138+
88139 unlock_page(page);
88140 if (page != swapcache) {
88141 /*
88142@@ -3157,6 +3368,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
88143
88144 /* No need to invalidate - it was non-present before */
88145 update_mmu_cache(vma, address, page_table);
88146+
88147+#ifdef CONFIG_PAX_SEGMEXEC
88148+ pax_mirror_anon_pte(vma, address, page, ptl);
88149+#endif
88150+
88151 unlock:
88152 pte_unmap_unlock(page_table, ptl);
88153 out:
88154@@ -3176,40 +3392,6 @@ out_release:
88155 }
88156
88157 /*
88158- * This is like a special single-page "expand_{down|up}wards()",
88159- * except we must first make sure that 'address{-|+}PAGE_SIZE'
88160- * doesn't hit another vma.
88161- */
88162-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
88163-{
88164- address &= PAGE_MASK;
88165- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
88166- struct vm_area_struct *prev = vma->vm_prev;
88167-
88168- /*
88169- * Is there a mapping abutting this one below?
88170- *
88171- * That's only ok if it's the same stack mapping
88172- * that has gotten split..
88173- */
88174- if (prev && prev->vm_end == address)
88175- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
88176-
88177- expand_downwards(vma, address - PAGE_SIZE);
88178- }
88179- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
88180- struct vm_area_struct *next = vma->vm_next;
88181-
88182- /* As VM_GROWSDOWN but s/below/above/ */
88183- if (next && next->vm_start == address + PAGE_SIZE)
88184- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
88185-
88186- expand_upwards(vma, address + PAGE_SIZE);
88187- }
88188- return 0;
88189-}
88190-
88191-/*
88192 * We enter with non-exclusive mmap_sem (to exclude vma changes,
88193 * but allow concurrent faults), and pte mapped but not yet locked.
88194 * We return with mmap_sem still held, but pte unmapped and unlocked.
88195@@ -3218,27 +3400,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
88196 unsigned long address, pte_t *page_table, pmd_t *pmd,
88197 unsigned int flags)
88198 {
88199- struct page *page;
88200+ struct page *page = NULL;
88201 spinlock_t *ptl;
88202 pte_t entry;
88203
88204- pte_unmap(page_table);
88205-
88206- /* Check if we need to add a guard page to the stack */
88207- if (check_stack_guard_page(vma, address) < 0)
88208- return VM_FAULT_SIGBUS;
88209-
88210- /* Use the zero-page for reads */
88211 if (!(flags & FAULT_FLAG_WRITE)) {
88212 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
88213 vma->vm_page_prot));
88214- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
88215+ ptl = pte_lockptr(mm, pmd);
88216+ spin_lock(ptl);
88217 if (!pte_none(*page_table))
88218 goto unlock;
88219 goto setpte;
88220 }
88221
88222 /* Allocate our own private page. */
88223+ pte_unmap(page_table);
88224+
88225 if (unlikely(anon_vma_prepare(vma)))
88226 goto oom;
88227 page = alloc_zeroed_user_highpage_movable(vma, address);
88228@@ -3262,6 +3440,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
88229 if (!pte_none(*page_table))
88230 goto release;
88231
88232+#ifdef CONFIG_PAX_SEGMEXEC
88233+ if (pax_find_mirror_vma(vma))
88234+ BUG_ON(!trylock_page(page));
88235+#endif
88236+
88237 inc_mm_counter_fast(mm, MM_ANONPAGES);
88238 page_add_new_anon_rmap(page, vma, address);
88239 setpte:
88240@@ -3269,6 +3452,12 @@ setpte:
88241
88242 /* No need to invalidate - it was non-present before */
88243 update_mmu_cache(vma, address, page_table);
88244+
88245+#ifdef CONFIG_PAX_SEGMEXEC
88246+ if (page)
88247+ pax_mirror_anon_pte(vma, address, page, ptl);
88248+#endif
88249+
88250 unlock:
88251 pte_unmap_unlock(page_table, ptl);
88252 return 0;
88253@@ -3412,6 +3601,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88254 */
88255 /* Only go through if we didn't race with anybody else... */
88256 if (likely(pte_same(*page_table, orig_pte))) {
88257+
88258+#ifdef CONFIG_PAX_SEGMEXEC
88259+ if (anon && pax_find_mirror_vma(vma))
88260+ BUG_ON(!trylock_page(page));
88261+#endif
88262+
88263 flush_icache_page(vma, page);
88264 entry = mk_pte(page, vma->vm_page_prot);
88265 if (flags & FAULT_FLAG_WRITE)
88266@@ -3431,6 +3626,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88267
88268 /* no need to invalidate: a not-present page won't be cached */
88269 update_mmu_cache(vma, address, page_table);
88270+
88271+#ifdef CONFIG_PAX_SEGMEXEC
88272+ if (anon)
88273+ pax_mirror_anon_pte(vma, address, page, ptl);
88274+ else
88275+ pax_mirror_file_pte(vma, address, page, ptl);
88276+#endif
88277+
88278 } else {
88279 if (cow_page)
88280 mem_cgroup_uncharge_page(cow_page);
88281@@ -3752,6 +3955,12 @@ int handle_pte_fault(struct mm_struct *mm,
88282 if (flags & FAULT_FLAG_WRITE)
88283 flush_tlb_fix_spurious_fault(vma, address);
88284 }
88285+
88286+#ifdef CONFIG_PAX_SEGMEXEC
88287+ pax_mirror_pte(vma, address, pte, pmd, ptl);
88288+ return 0;
88289+#endif
88290+
88291 unlock:
88292 pte_unmap_unlock(pte, ptl);
88293 return 0;
88294@@ -3768,6 +3977,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88295 pmd_t *pmd;
88296 pte_t *pte;
88297
88298+#ifdef CONFIG_PAX_SEGMEXEC
88299+ struct vm_area_struct *vma_m;
88300+#endif
88301+
88302 __set_current_state(TASK_RUNNING);
88303
88304 count_vm_event(PGFAULT);
88305@@ -3779,6 +3992,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88306 if (unlikely(is_vm_hugetlb_page(vma)))
88307 return hugetlb_fault(mm, vma, address, flags);
88308
88309+#ifdef CONFIG_PAX_SEGMEXEC
88310+ vma_m = pax_find_mirror_vma(vma);
88311+ if (vma_m) {
88312+ unsigned long address_m;
88313+ pgd_t *pgd_m;
88314+ pud_t *pud_m;
88315+ pmd_t *pmd_m;
88316+
88317+ if (vma->vm_start > vma_m->vm_start) {
88318+ address_m = address;
88319+ address -= SEGMEXEC_TASK_SIZE;
88320+ vma = vma_m;
88321+ } else
88322+ address_m = address + SEGMEXEC_TASK_SIZE;
88323+
88324+ pgd_m = pgd_offset(mm, address_m);
88325+ pud_m = pud_alloc(mm, pgd_m, address_m);
88326+ if (!pud_m)
88327+ return VM_FAULT_OOM;
88328+ pmd_m = pmd_alloc(mm, pud_m, address_m);
88329+ if (!pmd_m)
88330+ return VM_FAULT_OOM;
88331+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
88332+ return VM_FAULT_OOM;
88333+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
88334+ }
88335+#endif
88336+
88337 retry:
88338 pgd = pgd_offset(mm, address);
88339 pud = pud_alloc(mm, pgd, address);
88340@@ -3877,6 +4118,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
88341 spin_unlock(&mm->page_table_lock);
88342 return 0;
88343 }
88344+
88345+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
88346+{
88347+ pud_t *new = pud_alloc_one(mm, address);
88348+ if (!new)
88349+ return -ENOMEM;
88350+
88351+ smp_wmb(); /* See comment in __pte_alloc */
88352+
88353+ spin_lock(&mm->page_table_lock);
88354+ if (pgd_present(*pgd)) /* Another has populated it */
88355+ pud_free(mm, new);
88356+ else
88357+ pgd_populate_kernel(mm, pgd, new);
88358+ spin_unlock(&mm->page_table_lock);
88359+ return 0;
88360+}
88361 #endif /* __PAGETABLE_PUD_FOLDED */
88362
88363 #ifndef __PAGETABLE_PMD_FOLDED
88364@@ -3907,6 +4165,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
88365 spin_unlock(&mm->page_table_lock);
88366 return 0;
88367 }
88368+
88369+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
88370+{
88371+ pmd_t *new = pmd_alloc_one(mm, address);
88372+ if (!new)
88373+ return -ENOMEM;
88374+
88375+ smp_wmb(); /* See comment in __pte_alloc */
88376+
88377+ spin_lock(&mm->page_table_lock);
88378+#ifndef __ARCH_HAS_4LEVEL_HACK
88379+ if (pud_present(*pud)) /* Another has populated it */
88380+ pmd_free(mm, new);
88381+ else
88382+ pud_populate_kernel(mm, pud, new);
88383+#else
88384+ if (pgd_present(*pud)) /* Another has populated it */
88385+ pmd_free(mm, new);
88386+ else
88387+ pgd_populate_kernel(mm, pud, new);
88388+#endif /* __ARCH_HAS_4LEVEL_HACK */
88389+ spin_unlock(&mm->page_table_lock);
88390+ return 0;
88391+}
88392 #endif /* __PAGETABLE_PMD_FOLDED */
88393
88394 #if !defined(__HAVE_ARCH_GATE_AREA)
88395@@ -3920,7 +4202,7 @@ static int __init gate_vma_init(void)
88396 gate_vma.vm_start = FIXADDR_USER_START;
88397 gate_vma.vm_end = FIXADDR_USER_END;
88398 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
88399- gate_vma.vm_page_prot = __P101;
88400+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
88401
88402 return 0;
88403 }
88404@@ -4054,8 +4336,8 @@ out:
88405 return ret;
88406 }
88407
88408-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
88409- void *buf, int len, int write)
88410+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
88411+ void *buf, size_t len, int write)
88412 {
88413 resource_size_t phys_addr;
88414 unsigned long prot = 0;
88415@@ -4080,8 +4362,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
88416 * Access another process' address space as given in mm. If non-NULL, use the
88417 * given task for page fault accounting.
88418 */
88419-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88420- unsigned long addr, void *buf, int len, int write)
88421+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88422+ unsigned long addr, void *buf, size_t len, int write)
88423 {
88424 struct vm_area_struct *vma;
88425 void *old_buf = buf;
88426@@ -4089,7 +4371,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88427 down_read(&mm->mmap_sem);
88428 /* ignore errors, just check how much was successfully transferred */
88429 while (len) {
88430- int bytes, ret, offset;
88431+ ssize_t bytes, ret, offset;
88432 void *maddr;
88433 struct page *page = NULL;
88434
88435@@ -4148,8 +4430,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88436 *
88437 * The caller must hold a reference on @mm.
88438 */
88439-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88440- void *buf, int len, int write)
88441+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88442+ void *buf, size_t len, int write)
88443 {
88444 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88445 }
88446@@ -4159,11 +4441,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88447 * Source/target buffer must be kernel space,
88448 * Do not walk the page table directly, use get_user_pages
88449 */
88450-int access_process_vm(struct task_struct *tsk, unsigned long addr,
88451- void *buf, int len, int write)
88452+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
88453+ void *buf, size_t len, int write)
88454 {
88455 struct mm_struct *mm;
88456- int ret;
88457+ ssize_t ret;
88458
88459 mm = get_task_mm(tsk);
88460 if (!mm)
88461diff --git a/mm/mempolicy.c b/mm/mempolicy.c
88462index 4baf12e..5497066 100644
88463--- a/mm/mempolicy.c
88464+++ b/mm/mempolicy.c
88465@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
88466 unsigned long vmstart;
88467 unsigned long vmend;
88468
88469+#ifdef CONFIG_PAX_SEGMEXEC
88470+ struct vm_area_struct *vma_m;
88471+#endif
88472+
88473 vma = find_vma(mm, start);
88474 if (!vma || vma->vm_start > start)
88475 return -EFAULT;
88476@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
88477 err = vma_replace_policy(vma, new_pol);
88478 if (err)
88479 goto out;
88480+
88481+#ifdef CONFIG_PAX_SEGMEXEC
88482+ vma_m = pax_find_mirror_vma(vma);
88483+ if (vma_m) {
88484+ err = vma_replace_policy(vma_m, new_pol);
88485+ if (err)
88486+ goto out;
88487+ }
88488+#endif
88489+
88490 }
88491
88492 out:
88493@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
88494
88495 if (end < start)
88496 return -EINVAL;
88497+
88498+#ifdef CONFIG_PAX_SEGMEXEC
88499+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88500+ if (end > SEGMEXEC_TASK_SIZE)
88501+ return -EINVAL;
88502+ } else
88503+#endif
88504+
88505+ if (end > TASK_SIZE)
88506+ return -EINVAL;
88507+
88508 if (end == start)
88509 return 0;
88510
88511@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
88512 */
88513 tcred = __task_cred(task);
88514 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
88515- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
88516- !capable(CAP_SYS_NICE)) {
88517+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
88518 rcu_read_unlock();
88519 err = -EPERM;
88520 goto out_put;
88521@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
88522 goto out;
88523 }
88524
88525+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
88526+ if (mm != current->mm &&
88527+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
88528+ mmput(mm);
88529+ err = -EPERM;
88530+ goto out;
88531+ }
88532+#endif
88533+
88534 err = do_migrate_pages(mm, old, new,
88535 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
88536
88537diff --git a/mm/migrate.c b/mm/migrate.c
88538index 6f0c244..6d1ae32 100644
88539--- a/mm/migrate.c
88540+++ b/mm/migrate.c
88541@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
88542 */
88543 tcred = __task_cred(task);
88544 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
88545- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
88546- !capable(CAP_SYS_NICE)) {
88547+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
88548 rcu_read_unlock();
88549 err = -EPERM;
88550 goto out;
88551diff --git a/mm/mlock.c b/mm/mlock.c
88552index 79b7cf7..9944291 100644
88553--- a/mm/mlock.c
88554+++ b/mm/mlock.c
88555@@ -13,6 +13,7 @@
88556 #include <linux/pagemap.h>
88557 #include <linux/mempolicy.h>
88558 #include <linux/syscalls.h>
88559+#include <linux/security.h>
88560 #include <linux/sched.h>
88561 #include <linux/export.h>
88562 #include <linux/rmap.h>
88563@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
88564 {
88565 unsigned long nstart, end, tmp;
88566 struct vm_area_struct * vma, * prev;
88567- int error;
88568+ int error = 0;
88569
88570 VM_BUG_ON(start & ~PAGE_MASK);
88571 VM_BUG_ON(len != PAGE_ALIGN(len));
88572@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
88573 return -EINVAL;
88574 if (end == start)
88575 return 0;
88576+ if (end > TASK_SIZE)
88577+ return -EINVAL;
88578+
88579 vma = find_vma(current->mm, start);
88580 if (!vma || vma->vm_start > start)
88581 return -ENOMEM;
88582@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
88583 for (nstart = start ; ; ) {
88584 vm_flags_t newflags;
88585
88586+#ifdef CONFIG_PAX_SEGMEXEC
88587+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
88588+ break;
88589+#endif
88590+
88591 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
88592
88593 newflags = vma->vm_flags & ~VM_LOCKED;
88594@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
88595 lock_limit >>= PAGE_SHIFT;
88596
88597 /* check against resource limits */
88598+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
88599 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
88600 error = do_mlock(start, len, 1);
88601 up_write(&current->mm->mmap_sem);
88602@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
88603 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
88604 vm_flags_t newflags;
88605
88606+#ifdef CONFIG_PAX_SEGMEXEC
88607+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
88608+ break;
88609+#endif
88610+
88611 newflags = vma->vm_flags & ~VM_LOCKED;
88612 if (flags & MCL_CURRENT)
88613 newflags |= VM_LOCKED;
88614@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
88615 lock_limit >>= PAGE_SHIFT;
88616
88617 ret = -ENOMEM;
88618+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
88619 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
88620 capable(CAP_IPC_LOCK))
88621 ret = do_mlockall(flags);
88622diff --git a/mm/mmap.c b/mm/mmap.c
88623index 8d25fdc..bfb7626 100644
88624--- a/mm/mmap.c
88625+++ b/mm/mmap.c
88626@@ -36,6 +36,7 @@
88627 #include <linux/sched/sysctl.h>
88628 #include <linux/notifier.h>
88629 #include <linux/memory.h>
88630+#include <linux/random.h>
88631
88632 #include <asm/uaccess.h>
88633 #include <asm/cacheflush.h>
88634@@ -52,6 +53,16 @@
88635 #define arch_rebalance_pgtables(addr, len) (addr)
88636 #endif
88637
88638+static inline void verify_mm_writelocked(struct mm_struct *mm)
88639+{
88640+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
88641+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88642+ up_read(&mm->mmap_sem);
88643+ BUG();
88644+ }
88645+#endif
88646+}
88647+
88648 static void unmap_region(struct mm_struct *mm,
88649 struct vm_area_struct *vma, struct vm_area_struct *prev,
88650 unsigned long start, unsigned long end);
88651@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
88652 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
88653 *
88654 */
88655-pgprot_t protection_map[16] = {
88656+pgprot_t protection_map[16] __read_only = {
88657 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
88658 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
88659 };
88660
88661-pgprot_t vm_get_page_prot(unsigned long vm_flags)
88662+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
88663 {
88664- return __pgprot(pgprot_val(protection_map[vm_flags &
88665+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
88666 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
88667 pgprot_val(arch_vm_get_page_prot(vm_flags)));
88668+
88669+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
88670+ if (!(__supported_pte_mask & _PAGE_NX) &&
88671+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
88672+ (vm_flags & (VM_READ | VM_WRITE)))
88673+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
88674+#endif
88675+
88676+ return prot;
88677 }
88678 EXPORT_SYMBOL(vm_get_page_prot);
88679
88680@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
88681 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
88682 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88683 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88684+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
88685 /*
88686 * Make sure vm_committed_as in one cacheline and not cacheline shared with
88687 * other variables. It can be updated by several CPUs frequently.
88688@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
88689 struct vm_area_struct *next = vma->vm_next;
88690
88691 might_sleep();
88692+ BUG_ON(vma->vm_mirror);
88693 if (vma->vm_ops && vma->vm_ops->close)
88694 vma->vm_ops->close(vma);
88695 if (vma->vm_file)
88696@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
88697 * not page aligned -Ram Gupta
88698 */
88699 rlim = rlimit(RLIMIT_DATA);
88700+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
88701 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
88702 (mm->end_data - mm->start_data) > rlim)
88703 goto out;
88704@@ -933,6 +956,12 @@ static int
88705 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
88706 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
88707 {
88708+
88709+#ifdef CONFIG_PAX_SEGMEXEC
88710+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
88711+ return 0;
88712+#endif
88713+
88714 if (is_mergeable_vma(vma, file, vm_flags) &&
88715 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
88716 if (vma->vm_pgoff == vm_pgoff)
88717@@ -952,6 +981,12 @@ static int
88718 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
88719 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
88720 {
88721+
88722+#ifdef CONFIG_PAX_SEGMEXEC
88723+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
88724+ return 0;
88725+#endif
88726+
88727 if (is_mergeable_vma(vma, file, vm_flags) &&
88728 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
88729 pgoff_t vm_pglen;
88730@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
88731 struct vm_area_struct *vma_merge(struct mm_struct *mm,
88732 struct vm_area_struct *prev, unsigned long addr,
88733 unsigned long end, unsigned long vm_flags,
88734- struct anon_vma *anon_vma, struct file *file,
88735+ struct anon_vma *anon_vma, struct file *file,
88736 pgoff_t pgoff, struct mempolicy *policy)
88737 {
88738 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
88739 struct vm_area_struct *area, *next;
88740 int err;
88741
88742+#ifdef CONFIG_PAX_SEGMEXEC
88743+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
88744+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
88745+
88746+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
88747+#endif
88748+
88749 /*
88750 * We later require that vma->vm_flags == vm_flags,
88751 * so this tests vma->vm_flags & VM_SPECIAL, too.
88752@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
88753 if (next && next->vm_end == end) /* cases 6, 7, 8 */
88754 next = next->vm_next;
88755
88756+#ifdef CONFIG_PAX_SEGMEXEC
88757+ if (prev)
88758+ prev_m = pax_find_mirror_vma(prev);
88759+ if (area)
88760+ area_m = pax_find_mirror_vma(area);
88761+ if (next)
88762+ next_m = pax_find_mirror_vma(next);
88763+#endif
88764+
88765 /*
88766 * Can it merge with the predecessor?
88767 */
88768@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
88769 /* cases 1, 6 */
88770 err = vma_adjust(prev, prev->vm_start,
88771 next->vm_end, prev->vm_pgoff, NULL);
88772- } else /* cases 2, 5, 7 */
88773+
88774+#ifdef CONFIG_PAX_SEGMEXEC
88775+ if (!err && prev_m)
88776+ err = vma_adjust(prev_m, prev_m->vm_start,
88777+ next_m->vm_end, prev_m->vm_pgoff, NULL);
88778+#endif
88779+
88780+ } else { /* cases 2, 5, 7 */
88781 err = vma_adjust(prev, prev->vm_start,
88782 end, prev->vm_pgoff, NULL);
88783+
88784+#ifdef CONFIG_PAX_SEGMEXEC
88785+ if (!err && prev_m)
88786+ err = vma_adjust(prev_m, prev_m->vm_start,
88787+ end_m, prev_m->vm_pgoff, NULL);
88788+#endif
88789+
88790+ }
88791 if (err)
88792 return NULL;
88793 khugepaged_enter_vma_merge(prev);
88794@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
88795 mpol_equal(policy, vma_policy(next)) &&
88796 can_vma_merge_before(next, vm_flags,
88797 anon_vma, file, pgoff+pglen)) {
88798- if (prev && addr < prev->vm_end) /* case 4 */
88799+ if (prev && addr < prev->vm_end) { /* case 4 */
88800 err = vma_adjust(prev, prev->vm_start,
88801 addr, prev->vm_pgoff, NULL);
88802- else /* cases 3, 8 */
88803+
88804+#ifdef CONFIG_PAX_SEGMEXEC
88805+ if (!err && prev_m)
88806+ err = vma_adjust(prev_m, prev_m->vm_start,
88807+ addr_m, prev_m->vm_pgoff, NULL);
88808+#endif
88809+
88810+ } else { /* cases 3, 8 */
88811 err = vma_adjust(area, addr, next->vm_end,
88812 next->vm_pgoff - pglen, NULL);
88813+
88814+#ifdef CONFIG_PAX_SEGMEXEC
88815+ if (!err && area_m)
88816+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
88817+ next_m->vm_pgoff - pglen, NULL);
88818+#endif
88819+
88820+ }
88821 if (err)
88822 return NULL;
88823 khugepaged_enter_vma_merge(area);
88824@@ -1165,8 +1246,10 @@ none:
88825 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
88826 struct file *file, long pages)
88827 {
88828- const unsigned long stack_flags
88829- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
88830+
88831+#ifdef CONFIG_PAX_RANDMMAP
88832+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
88833+#endif
88834
88835 mm->total_vm += pages;
88836
88837@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
88838 mm->shared_vm += pages;
88839 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
88840 mm->exec_vm += pages;
88841- } else if (flags & stack_flags)
88842+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
88843 mm->stack_vm += pages;
88844 }
88845 #endif /* CONFIG_PROC_FS */
88846@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88847 * (the exception is when the underlying filesystem is noexec
88848 * mounted, in which case we dont add PROT_EXEC.)
88849 */
88850- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88851+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88852 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
88853 prot |= PROT_EXEC;
88854
88855@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88856 /* Obtain the address to map to. we verify (or select) it and ensure
88857 * that it represents a valid section of the address space.
88858 */
88859- addr = get_unmapped_area(file, addr, len, pgoff, flags);
88860+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
88861 if (addr & ~PAGE_MASK)
88862 return addr;
88863
88864@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88865 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
88866 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
88867
88868+#ifdef CONFIG_PAX_MPROTECT
88869+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88870+
88871+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
88872+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
88873+ mm->binfmt->handle_mmap)
88874+ mm->binfmt->handle_mmap(file);
88875+#endif
88876+
88877+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88878+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
88879+ gr_log_rwxmmap(file);
88880+
88881+#ifdef CONFIG_PAX_EMUPLT
88882+ vm_flags &= ~VM_EXEC;
88883+#else
88884+ return -EPERM;
88885+#endif
88886+
88887+ }
88888+
88889+ if (!(vm_flags & VM_EXEC))
88890+ vm_flags &= ~VM_MAYEXEC;
88891+#else
88892+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88893+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88894+#endif
88895+ else
88896+ vm_flags &= ~VM_MAYWRITE;
88897+ }
88898+#endif
88899+
88900+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
88901+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
88902+ vm_flags &= ~VM_PAGEEXEC;
88903+#endif
88904+
88905 if (flags & MAP_LOCKED)
88906 if (!can_do_mlock())
88907 return -EPERM;
88908@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88909 locked += mm->locked_vm;
88910 lock_limit = rlimit(RLIMIT_MEMLOCK);
88911 lock_limit >>= PAGE_SHIFT;
88912+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
88913 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
88914 return -EAGAIN;
88915 }
88916@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88917 vm_flags |= VM_NORESERVE;
88918 }
88919
88920+ if (!gr_acl_handle_mmap(file, prot))
88921+ return -EACCES;
88922+
88923 addr = mmap_region(file, addr, len, vm_flags, pgoff);
88924 if (!IS_ERR_VALUE(addr) &&
88925 ((vm_flags & VM_LOCKED) ||
88926@@ -1432,7 +1556,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
88927 vm_flags_t vm_flags = vma->vm_flags;
88928
88929 /* If it was private or non-writable, the write bit is already clear */
88930- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
88931+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
88932 return 0;
88933
88934 /* The backer wishes to know when pages are first written to? */
88935@@ -1480,7 +1604,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
88936 unsigned long charged = 0;
88937 struct inode *inode = file ? file_inode(file) : NULL;
88938
88939+#ifdef CONFIG_PAX_SEGMEXEC
88940+ struct vm_area_struct *vma_m = NULL;
88941+#endif
88942+
88943+ /*
88944+ * mm->mmap_sem is required to protect against another thread
88945+ * changing the mappings in case we sleep.
88946+ */
88947+ verify_mm_writelocked(mm);
88948+
88949 /* Check against address space limit. */
88950+
88951+#ifdef CONFIG_PAX_RANDMMAP
88952+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
88953+#endif
88954+
88955 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
88956 unsigned long nr_pages;
88957
88958@@ -1499,11 +1638,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
88959
88960 /* Clear old maps */
88961 error = -ENOMEM;
88962-munmap_back:
88963 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88964 if (do_munmap(mm, addr, len))
88965 return -ENOMEM;
88966- goto munmap_back;
88967+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88968 }
88969
88970 /*
88971@@ -1534,6 +1672,16 @@ munmap_back:
88972 goto unacct_error;
88973 }
88974
88975+#ifdef CONFIG_PAX_SEGMEXEC
88976+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
88977+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88978+ if (!vma_m) {
88979+ error = -ENOMEM;
88980+ goto free_vma;
88981+ }
88982+ }
88983+#endif
88984+
88985 vma->vm_mm = mm;
88986 vma->vm_start = addr;
88987 vma->vm_end = addr + len;
88988@@ -1558,6 +1706,13 @@ munmap_back:
88989 if (error)
88990 goto unmap_and_free_vma;
88991
88992+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
88993+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
88994+ vma->vm_flags |= VM_PAGEEXEC;
88995+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88996+ }
88997+#endif
88998+
88999 /* Can addr have changed??
89000 *
89001 * Answer: Yes, several device drivers can do it in their
89002@@ -1596,6 +1751,11 @@ munmap_back:
89003 vma_link(mm, vma, prev, rb_link, rb_parent);
89004 file = vma->vm_file;
89005
89006+#ifdef CONFIG_PAX_SEGMEXEC
89007+ if (vma_m)
89008+ BUG_ON(pax_mirror_vma(vma_m, vma));
89009+#endif
89010+
89011 /* Once vma denies write, undo our temporary denial count */
89012 if (correct_wcount)
89013 atomic_inc(&inode->i_writecount);
89014@@ -1603,6 +1763,7 @@ out:
89015 perf_event_mmap(vma);
89016
89017 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
89018+ track_exec_limit(mm, addr, addr + len, vm_flags);
89019 if (vm_flags & VM_LOCKED) {
89020 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
89021 vma == get_gate_vma(current->mm)))
89022@@ -1626,6 +1787,12 @@ unmap_and_free_vma:
89023 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
89024 charged = 0;
89025 free_vma:
89026+
89027+#ifdef CONFIG_PAX_SEGMEXEC
89028+ if (vma_m)
89029+ kmem_cache_free(vm_area_cachep, vma_m);
89030+#endif
89031+
89032 kmem_cache_free(vm_area_cachep, vma);
89033 unacct_error:
89034 if (charged)
89035@@ -1633,7 +1800,63 @@ unacct_error:
89036 return error;
89037 }
89038
89039-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
89040+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
89041+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
89042+{
89043+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
89044+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
89045+
89046+ return 0;
89047+}
89048+#endif
89049+
89050+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
89051+{
89052+ if (!vma) {
89053+#ifdef CONFIG_STACK_GROWSUP
89054+ if (addr > sysctl_heap_stack_gap)
89055+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
89056+ else
89057+ vma = find_vma(current->mm, 0);
89058+ if (vma && (vma->vm_flags & VM_GROWSUP))
89059+ return false;
89060+#endif
89061+ return true;
89062+ }
89063+
89064+ if (addr + len > vma->vm_start)
89065+ return false;
89066+
89067+ if (vma->vm_flags & VM_GROWSDOWN)
89068+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
89069+#ifdef CONFIG_STACK_GROWSUP
89070+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
89071+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
89072+#endif
89073+ else if (offset)
89074+ return offset <= vma->vm_start - addr - len;
89075+
89076+ return true;
89077+}
89078+
89079+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
89080+{
89081+ if (vma->vm_start < len)
89082+ return -ENOMEM;
89083+
89084+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
89085+ if (offset <= vma->vm_start - len)
89086+ return vma->vm_start - len - offset;
89087+ else
89088+ return -ENOMEM;
89089+ }
89090+
89091+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
89092+ return vma->vm_start - len - sysctl_heap_stack_gap;
89093+ return -ENOMEM;
89094+}
89095+
89096+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
89097 {
89098 /*
89099 * We implement the search by looking for an rbtree node that
89100@@ -1681,11 +1904,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
89101 }
89102 }
89103
89104- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
89105+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
89106 check_current:
89107 /* Check if current node has a suitable gap */
89108 if (gap_start > high_limit)
89109 return -ENOMEM;
89110+
89111+ if (gap_end - gap_start > info->threadstack_offset)
89112+ gap_start += info->threadstack_offset;
89113+ else
89114+ gap_start = gap_end;
89115+
89116+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
89117+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89118+ gap_start += sysctl_heap_stack_gap;
89119+ else
89120+ gap_start = gap_end;
89121+ }
89122+ if (vma->vm_flags & VM_GROWSDOWN) {
89123+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89124+ gap_end -= sysctl_heap_stack_gap;
89125+ else
89126+ gap_end = gap_start;
89127+ }
89128 if (gap_end >= low_limit && gap_end - gap_start >= length)
89129 goto found;
89130
89131@@ -1735,7 +1976,7 @@ found:
89132 return gap_start;
89133 }
89134
89135-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
89136+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
89137 {
89138 struct mm_struct *mm = current->mm;
89139 struct vm_area_struct *vma;
89140@@ -1789,6 +2030,24 @@ check_current:
89141 gap_end = vma->vm_start;
89142 if (gap_end < low_limit)
89143 return -ENOMEM;
89144+
89145+ if (gap_end - gap_start > info->threadstack_offset)
89146+ gap_end -= info->threadstack_offset;
89147+ else
89148+ gap_end = gap_start;
89149+
89150+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
89151+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89152+ gap_start += sysctl_heap_stack_gap;
89153+ else
89154+ gap_start = gap_end;
89155+ }
89156+ if (vma->vm_flags & VM_GROWSDOWN) {
89157+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89158+ gap_end -= sysctl_heap_stack_gap;
89159+ else
89160+ gap_end = gap_start;
89161+ }
89162 if (gap_start <= high_limit && gap_end - gap_start >= length)
89163 goto found;
89164
89165@@ -1852,6 +2111,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
89166 struct mm_struct *mm = current->mm;
89167 struct vm_area_struct *vma;
89168 struct vm_unmapped_area_info info;
89169+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
89170
89171 if (len > TASK_SIZE)
89172 return -ENOMEM;
89173@@ -1859,29 +2119,45 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
89174 if (flags & MAP_FIXED)
89175 return addr;
89176
89177+#ifdef CONFIG_PAX_RANDMMAP
89178+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
89179+#endif
89180+
89181 if (addr) {
89182 addr = PAGE_ALIGN(addr);
89183 vma = find_vma(mm, addr);
89184- if (TASK_SIZE - len >= addr &&
89185- (!vma || addr + len <= vma->vm_start))
89186+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
89187 return addr;
89188 }
89189
89190 info.flags = 0;
89191 info.length = len;
89192 info.low_limit = TASK_UNMAPPED_BASE;
89193+
89194+#ifdef CONFIG_PAX_RANDMMAP
89195+ if (mm->pax_flags & MF_PAX_RANDMMAP)
89196+ info.low_limit += mm->delta_mmap;
89197+#endif
89198+
89199 info.high_limit = TASK_SIZE;
89200 info.align_mask = 0;
89201+ info.threadstack_offset = offset;
89202 return vm_unmapped_area(&info);
89203 }
89204 #endif
89205
89206 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
89207 {
89208+
89209+#ifdef CONFIG_PAX_SEGMEXEC
89210+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
89211+ return;
89212+#endif
89213+
89214 /*
89215 * Is this a new hole at the lowest possible address?
89216 */
89217- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
89218+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
89219 mm->free_area_cache = addr;
89220 }
89221
89222@@ -1899,6 +2175,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89223 struct mm_struct *mm = current->mm;
89224 unsigned long addr = addr0;
89225 struct vm_unmapped_area_info info;
89226+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
89227
89228 /* requested length too big for entire address space */
89229 if (len > TASK_SIZE)
89230@@ -1907,12 +2184,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89231 if (flags & MAP_FIXED)
89232 return addr;
89233
89234+#ifdef CONFIG_PAX_RANDMMAP
89235+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
89236+#endif
89237+
89238 /* requesting a specific address */
89239 if (addr) {
89240 addr = PAGE_ALIGN(addr);
89241 vma = find_vma(mm, addr);
89242- if (TASK_SIZE - len >= addr &&
89243- (!vma || addr + len <= vma->vm_start))
89244+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
89245 return addr;
89246 }
89247
89248@@ -1921,6 +2201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89249 info.low_limit = PAGE_SIZE;
89250 info.high_limit = mm->mmap_base;
89251 info.align_mask = 0;
89252+ info.threadstack_offset = offset;
89253 addr = vm_unmapped_area(&info);
89254
89255 /*
89256@@ -1933,6 +2214,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89257 VM_BUG_ON(addr != -ENOMEM);
89258 info.flags = 0;
89259 info.low_limit = TASK_UNMAPPED_BASE;
89260+
89261+#ifdef CONFIG_PAX_RANDMMAP
89262+ if (mm->pax_flags & MF_PAX_RANDMMAP)
89263+ info.low_limit += mm->delta_mmap;
89264+#endif
89265+
89266 info.high_limit = TASK_SIZE;
89267 addr = vm_unmapped_area(&info);
89268 }
89269@@ -1943,6 +2230,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89270
89271 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
89272 {
89273+
89274+#ifdef CONFIG_PAX_SEGMEXEC
89275+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
89276+ return;
89277+#endif
89278+
89279 /*
89280 * Is this a new hole at the highest possible address?
89281 */
89282@@ -1950,8 +2243,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
89283 mm->free_area_cache = addr;
89284
89285 /* dont allow allocations above current base */
89286- if (mm->free_area_cache > mm->mmap_base)
89287+ if (mm->free_area_cache > mm->mmap_base) {
89288 mm->free_area_cache = mm->mmap_base;
89289+ mm->cached_hole_size = ~0UL;
89290+ }
89291 }
89292
89293 unsigned long
89294@@ -2047,6 +2342,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
89295 return vma;
89296 }
89297
89298+#ifdef CONFIG_PAX_SEGMEXEC
89299+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
89300+{
89301+ struct vm_area_struct *vma_m;
89302+
89303+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
89304+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
89305+ BUG_ON(vma->vm_mirror);
89306+ return NULL;
89307+ }
89308+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
89309+ vma_m = vma->vm_mirror;
89310+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
89311+ BUG_ON(vma->vm_file != vma_m->vm_file);
89312+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
89313+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
89314+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
89315+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
89316+ return vma_m;
89317+}
89318+#endif
89319+
89320 /*
89321 * Verify that the stack growth is acceptable and
89322 * update accounting. This is shared with both the
89323@@ -2063,6 +2380,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89324 return -ENOMEM;
89325
89326 /* Stack limit test */
89327+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
89328 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
89329 return -ENOMEM;
89330
89331@@ -2073,6 +2391,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89332 locked = mm->locked_vm + grow;
89333 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
89334 limit >>= PAGE_SHIFT;
89335+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
89336 if (locked > limit && !capable(CAP_IPC_LOCK))
89337 return -ENOMEM;
89338 }
89339@@ -2102,37 +2421,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89340 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
89341 * vma is the last one with address > vma->vm_end. Have to extend vma.
89342 */
89343+#ifndef CONFIG_IA64
89344+static
89345+#endif
89346 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
89347 {
89348 int error;
89349+ bool locknext;
89350
89351 if (!(vma->vm_flags & VM_GROWSUP))
89352 return -EFAULT;
89353
89354+ /* Also guard against wrapping around to address 0. */
89355+ if (address < PAGE_ALIGN(address+1))
89356+ address = PAGE_ALIGN(address+1);
89357+ else
89358+ return -ENOMEM;
89359+
89360 /*
89361 * We must make sure the anon_vma is allocated
89362 * so that the anon_vma locking is not a noop.
89363 */
89364 if (unlikely(anon_vma_prepare(vma)))
89365 return -ENOMEM;
89366+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
89367+ if (locknext && anon_vma_prepare(vma->vm_next))
89368+ return -ENOMEM;
89369 vma_lock_anon_vma(vma);
89370+ if (locknext)
89371+ vma_lock_anon_vma(vma->vm_next);
89372
89373 /*
89374 * vma->vm_start/vm_end cannot change under us because the caller
89375 * is required to hold the mmap_sem in read mode. We need the
89376- * anon_vma lock to serialize against concurrent expand_stacks.
89377- * Also guard against wrapping around to address 0.
89378+ * anon_vma locks to serialize against concurrent expand_stacks
89379+ * and expand_upwards.
89380 */
89381- if (address < PAGE_ALIGN(address+4))
89382- address = PAGE_ALIGN(address+4);
89383- else {
89384- vma_unlock_anon_vma(vma);
89385- return -ENOMEM;
89386- }
89387 error = 0;
89388
89389 /* Somebody else might have raced and expanded it already */
89390- if (address > vma->vm_end) {
89391+ 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)
89392+ error = -ENOMEM;
89393+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
89394 unsigned long size, grow;
89395
89396 size = address - vma->vm_start;
89397@@ -2167,6 +2497,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
89398 }
89399 }
89400 }
89401+ if (locknext)
89402+ vma_unlock_anon_vma(vma->vm_next);
89403 vma_unlock_anon_vma(vma);
89404 khugepaged_enter_vma_merge(vma);
89405 validate_mm(vma->vm_mm);
89406@@ -2181,6 +2513,8 @@ int expand_downwards(struct vm_area_struct *vma,
89407 unsigned long address)
89408 {
89409 int error;
89410+ bool lockprev = false;
89411+ struct vm_area_struct *prev;
89412
89413 /*
89414 * We must make sure the anon_vma is allocated
89415@@ -2194,6 +2528,15 @@ int expand_downwards(struct vm_area_struct *vma,
89416 if (error)
89417 return error;
89418
89419+ prev = vma->vm_prev;
89420+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
89421+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
89422+#endif
89423+ if (lockprev && anon_vma_prepare(prev))
89424+ return -ENOMEM;
89425+ if (lockprev)
89426+ vma_lock_anon_vma(prev);
89427+
89428 vma_lock_anon_vma(vma);
89429
89430 /*
89431@@ -2203,9 +2546,17 @@ int expand_downwards(struct vm_area_struct *vma,
89432 */
89433
89434 /* Somebody else might have raced and expanded it already */
89435- if (address < vma->vm_start) {
89436+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
89437+ error = -ENOMEM;
89438+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
89439 unsigned long size, grow;
89440
89441+#ifdef CONFIG_PAX_SEGMEXEC
89442+ struct vm_area_struct *vma_m;
89443+
89444+ vma_m = pax_find_mirror_vma(vma);
89445+#endif
89446+
89447 size = vma->vm_end - address;
89448 grow = (vma->vm_start - address) >> PAGE_SHIFT;
89449
89450@@ -2230,13 +2581,27 @@ int expand_downwards(struct vm_area_struct *vma,
89451 vma->vm_pgoff -= grow;
89452 anon_vma_interval_tree_post_update_vma(vma);
89453 vma_gap_update(vma);
89454+
89455+#ifdef CONFIG_PAX_SEGMEXEC
89456+ if (vma_m) {
89457+ anon_vma_interval_tree_pre_update_vma(vma_m);
89458+ vma_m->vm_start -= grow << PAGE_SHIFT;
89459+ vma_m->vm_pgoff -= grow;
89460+ anon_vma_interval_tree_post_update_vma(vma_m);
89461+ vma_gap_update(vma_m);
89462+ }
89463+#endif
89464+
89465 spin_unlock(&vma->vm_mm->page_table_lock);
89466
89467+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
89468 perf_event_mmap(vma);
89469 }
89470 }
89471 }
89472 vma_unlock_anon_vma(vma);
89473+ if (lockprev)
89474+ vma_unlock_anon_vma(prev);
89475 khugepaged_enter_vma_merge(vma);
89476 validate_mm(vma->vm_mm);
89477 return error;
89478@@ -2334,6 +2699,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
89479 do {
89480 long nrpages = vma_pages(vma);
89481
89482+#ifdef CONFIG_PAX_SEGMEXEC
89483+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
89484+ vma = remove_vma(vma);
89485+ continue;
89486+ }
89487+#endif
89488+
89489 if (vma->vm_flags & VM_ACCOUNT)
89490 nr_accounted += nrpages;
89491 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
89492@@ -2379,6 +2751,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
89493 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
89494 vma->vm_prev = NULL;
89495 do {
89496+
89497+#ifdef CONFIG_PAX_SEGMEXEC
89498+ if (vma->vm_mirror) {
89499+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
89500+ vma->vm_mirror->vm_mirror = NULL;
89501+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
89502+ vma->vm_mirror = NULL;
89503+ }
89504+#endif
89505+
89506 vma_rb_erase(vma, &mm->mm_rb);
89507 mm->map_count--;
89508 tail_vma = vma;
89509@@ -2410,14 +2792,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89510 struct vm_area_struct *new;
89511 int err = -ENOMEM;
89512
89513+#ifdef CONFIG_PAX_SEGMEXEC
89514+ struct vm_area_struct *vma_m, *new_m = NULL;
89515+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
89516+#endif
89517+
89518 if (is_vm_hugetlb_page(vma) && (addr &
89519 ~(huge_page_mask(hstate_vma(vma)))))
89520 return -EINVAL;
89521
89522+#ifdef CONFIG_PAX_SEGMEXEC
89523+ vma_m = pax_find_mirror_vma(vma);
89524+#endif
89525+
89526 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89527 if (!new)
89528 goto out_err;
89529
89530+#ifdef CONFIG_PAX_SEGMEXEC
89531+ if (vma_m) {
89532+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89533+ if (!new_m) {
89534+ kmem_cache_free(vm_area_cachep, new);
89535+ goto out_err;
89536+ }
89537+ }
89538+#endif
89539+
89540 /* most fields are the same, copy all, and then fixup */
89541 *new = *vma;
89542
89543@@ -2430,6 +2831,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89544 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
89545 }
89546
89547+#ifdef CONFIG_PAX_SEGMEXEC
89548+ if (vma_m) {
89549+ *new_m = *vma_m;
89550+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
89551+ new_m->vm_mirror = new;
89552+ new->vm_mirror = new_m;
89553+
89554+ if (new_below)
89555+ new_m->vm_end = addr_m;
89556+ else {
89557+ new_m->vm_start = addr_m;
89558+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
89559+ }
89560+ }
89561+#endif
89562+
89563 pol = mpol_dup(vma_policy(vma));
89564 if (IS_ERR(pol)) {
89565 err = PTR_ERR(pol);
89566@@ -2452,6 +2869,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89567 else
89568 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
89569
89570+#ifdef CONFIG_PAX_SEGMEXEC
89571+ if (!err && vma_m) {
89572+ if (anon_vma_clone(new_m, vma_m))
89573+ goto out_free_mpol;
89574+
89575+ mpol_get(pol);
89576+ vma_set_policy(new_m, pol);
89577+
89578+ if (new_m->vm_file)
89579+ get_file(new_m->vm_file);
89580+
89581+ if (new_m->vm_ops && new_m->vm_ops->open)
89582+ new_m->vm_ops->open(new_m);
89583+
89584+ if (new_below)
89585+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
89586+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
89587+ else
89588+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
89589+
89590+ if (err) {
89591+ if (new_m->vm_ops && new_m->vm_ops->close)
89592+ new_m->vm_ops->close(new_m);
89593+ if (new_m->vm_file)
89594+ fput(new_m->vm_file);
89595+ mpol_put(pol);
89596+ }
89597+ }
89598+#endif
89599+
89600 /* Success. */
89601 if (!err)
89602 return 0;
89603@@ -2461,10 +2908,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89604 new->vm_ops->close(new);
89605 if (new->vm_file)
89606 fput(new->vm_file);
89607- unlink_anon_vmas(new);
89608 out_free_mpol:
89609 mpol_put(pol);
89610 out_free_vma:
89611+
89612+#ifdef CONFIG_PAX_SEGMEXEC
89613+ if (new_m) {
89614+ unlink_anon_vmas(new_m);
89615+ kmem_cache_free(vm_area_cachep, new_m);
89616+ }
89617+#endif
89618+
89619+ unlink_anon_vmas(new);
89620 kmem_cache_free(vm_area_cachep, new);
89621 out_err:
89622 return err;
89623@@ -2477,6 +2932,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89624 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
89625 unsigned long addr, int new_below)
89626 {
89627+
89628+#ifdef CONFIG_PAX_SEGMEXEC
89629+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
89630+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
89631+ if (mm->map_count >= sysctl_max_map_count-1)
89632+ return -ENOMEM;
89633+ } else
89634+#endif
89635+
89636 if (mm->map_count >= sysctl_max_map_count)
89637 return -ENOMEM;
89638
89639@@ -2488,11 +2952,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
89640 * work. This now handles partial unmappings.
89641 * Jeremy Fitzhardinge <jeremy@goop.org>
89642 */
89643+#ifdef CONFIG_PAX_SEGMEXEC
89644 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89645 {
89646+ int ret = __do_munmap(mm, start, len);
89647+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
89648+ return ret;
89649+
89650+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
89651+}
89652+
89653+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89654+#else
89655+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89656+#endif
89657+{
89658 unsigned long end;
89659 struct vm_area_struct *vma, *prev, *last;
89660
89661+ /*
89662+ * mm->mmap_sem is required to protect against another thread
89663+ * changing the mappings in case we sleep.
89664+ */
89665+ verify_mm_writelocked(mm);
89666+
89667 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
89668 return -EINVAL;
89669
89670@@ -2567,6 +3050,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89671 /* Fix up all other VM information */
89672 remove_vma_list(mm, vma);
89673
89674+ track_exec_limit(mm, start, end, 0UL);
89675+
89676 return 0;
89677 }
89678
89679@@ -2575,6 +3060,13 @@ int vm_munmap(unsigned long start, size_t len)
89680 int ret;
89681 struct mm_struct *mm = current->mm;
89682
89683+
89684+#ifdef CONFIG_PAX_SEGMEXEC
89685+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
89686+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
89687+ return -EINVAL;
89688+#endif
89689+
89690 down_write(&mm->mmap_sem);
89691 ret = do_munmap(mm, start, len);
89692 up_write(&mm->mmap_sem);
89693@@ -2588,16 +3080,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
89694 return vm_munmap(addr, len);
89695 }
89696
89697-static inline void verify_mm_writelocked(struct mm_struct *mm)
89698-{
89699-#ifdef CONFIG_DEBUG_VM
89700- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
89701- WARN_ON(1);
89702- up_read(&mm->mmap_sem);
89703- }
89704-#endif
89705-}
89706-
89707 /*
89708 * this is really a simplified "do_mmap". it only handles
89709 * anonymous maps. eventually we may be able to do some
89710@@ -2611,6 +3093,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89711 struct rb_node ** rb_link, * rb_parent;
89712 pgoff_t pgoff = addr >> PAGE_SHIFT;
89713 int error;
89714+ unsigned long charged;
89715
89716 len = PAGE_ALIGN(len);
89717 if (!len)
89718@@ -2618,16 +3101,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89719
89720 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
89721
89722+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
89723+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
89724+ flags &= ~VM_EXEC;
89725+
89726+#ifdef CONFIG_PAX_MPROTECT
89727+ if (mm->pax_flags & MF_PAX_MPROTECT)
89728+ flags &= ~VM_MAYEXEC;
89729+#endif
89730+
89731+ }
89732+#endif
89733+
89734 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
89735 if (error & ~PAGE_MASK)
89736 return error;
89737
89738+ charged = len >> PAGE_SHIFT;
89739+
89740 /*
89741 * mlock MCL_FUTURE?
89742 */
89743 if (mm->def_flags & VM_LOCKED) {
89744 unsigned long locked, lock_limit;
89745- locked = len >> PAGE_SHIFT;
89746+ locked = charged;
89747 locked += mm->locked_vm;
89748 lock_limit = rlimit(RLIMIT_MEMLOCK);
89749 lock_limit >>= PAGE_SHIFT;
89750@@ -2644,21 +3141,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89751 /*
89752 * Clear old maps. this also does some error checking for us
89753 */
89754- munmap_back:
89755 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
89756 if (do_munmap(mm, addr, len))
89757 return -ENOMEM;
89758- goto munmap_back;
89759+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
89760 }
89761
89762 /* Check against address space limits *after* clearing old maps... */
89763- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
89764+ if (!may_expand_vm(mm, charged))
89765 return -ENOMEM;
89766
89767 if (mm->map_count > sysctl_max_map_count)
89768 return -ENOMEM;
89769
89770- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
89771+ if (security_vm_enough_memory_mm(mm, charged))
89772 return -ENOMEM;
89773
89774 /* Can we just expand an old private anonymous mapping? */
89775@@ -2672,7 +3168,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89776 */
89777 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
89778 if (!vma) {
89779- vm_unacct_memory(len >> PAGE_SHIFT);
89780+ vm_unacct_memory(charged);
89781 return -ENOMEM;
89782 }
89783
89784@@ -2686,9 +3182,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89785 vma_link(mm, vma, prev, rb_link, rb_parent);
89786 out:
89787 perf_event_mmap(vma);
89788- mm->total_vm += len >> PAGE_SHIFT;
89789+ mm->total_vm += charged;
89790 if (flags & VM_LOCKED)
89791- mm->locked_vm += (len >> PAGE_SHIFT);
89792+ mm->locked_vm += charged;
89793+ track_exec_limit(mm, addr, addr + len, flags);
89794 return addr;
89795 }
89796
89797@@ -2750,6 +3247,7 @@ void exit_mmap(struct mm_struct *mm)
89798 while (vma) {
89799 if (vma->vm_flags & VM_ACCOUNT)
89800 nr_accounted += vma_pages(vma);
89801+ vma->vm_mirror = NULL;
89802 vma = remove_vma(vma);
89803 }
89804 vm_unacct_memory(nr_accounted);
89805@@ -2766,6 +3264,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
89806 struct vm_area_struct *prev;
89807 struct rb_node **rb_link, *rb_parent;
89808
89809+#ifdef CONFIG_PAX_SEGMEXEC
89810+ struct vm_area_struct *vma_m = NULL;
89811+#endif
89812+
89813+ if (security_mmap_addr(vma->vm_start))
89814+ return -EPERM;
89815+
89816 /*
89817 * The vm_pgoff of a purely anonymous vma should be irrelevant
89818 * until its first write fault, when page's anon_vma and index
89819@@ -2789,7 +3294,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
89820 security_vm_enough_memory_mm(mm, vma_pages(vma)))
89821 return -ENOMEM;
89822
89823+#ifdef CONFIG_PAX_SEGMEXEC
89824+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
89825+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
89826+ if (!vma_m)
89827+ return -ENOMEM;
89828+ }
89829+#endif
89830+
89831 vma_link(mm, vma, prev, rb_link, rb_parent);
89832+
89833+#ifdef CONFIG_PAX_SEGMEXEC
89834+ if (vma_m)
89835+ BUG_ON(pax_mirror_vma(vma_m, vma));
89836+#endif
89837+
89838 return 0;
89839 }
89840
89841@@ -2809,6 +3328,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
89842 struct mempolicy *pol;
89843 bool faulted_in_anon_vma = true;
89844
89845+ BUG_ON(vma->vm_mirror);
89846+
89847 /*
89848 * If anonymous vma has not yet been faulted, update new pgoff
89849 * to match new location, to increase its chance of merging.
89850@@ -2875,6 +3396,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
89851 return NULL;
89852 }
89853
89854+#ifdef CONFIG_PAX_SEGMEXEC
89855+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
89856+{
89857+ struct vm_area_struct *prev_m;
89858+ struct rb_node **rb_link_m, *rb_parent_m;
89859+ struct mempolicy *pol_m;
89860+
89861+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
89862+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
89863+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
89864+ *vma_m = *vma;
89865+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
89866+ if (anon_vma_clone(vma_m, vma))
89867+ return -ENOMEM;
89868+ pol_m = vma_policy(vma_m);
89869+ mpol_get(pol_m);
89870+ vma_set_policy(vma_m, pol_m);
89871+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
89872+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
89873+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
89874+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
89875+ if (vma_m->vm_file)
89876+ get_file(vma_m->vm_file);
89877+ if (vma_m->vm_ops && vma_m->vm_ops->open)
89878+ vma_m->vm_ops->open(vma_m);
89879+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
89880+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
89881+ vma_m->vm_mirror = vma;
89882+ vma->vm_mirror = vma_m;
89883+ return 0;
89884+}
89885+#endif
89886+
89887 /*
89888 * Return true if the calling process may expand its vm space by the passed
89889 * number of pages
89890@@ -2886,6 +3440,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
89891
89892 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
89893
89894+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
89895 if (cur + npages > lim)
89896 return 0;
89897 return 1;
89898@@ -2956,6 +3511,22 @@ int install_special_mapping(struct mm_struct *mm,
89899 vma->vm_start = addr;
89900 vma->vm_end = addr + len;
89901
89902+#ifdef CONFIG_PAX_MPROTECT
89903+ if (mm->pax_flags & MF_PAX_MPROTECT) {
89904+#ifndef CONFIG_PAX_MPROTECT_COMPAT
89905+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
89906+ return -EPERM;
89907+ if (!(vm_flags & VM_EXEC))
89908+ vm_flags &= ~VM_MAYEXEC;
89909+#else
89910+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
89911+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
89912+#endif
89913+ else
89914+ vm_flags &= ~VM_MAYWRITE;
89915+ }
89916+#endif
89917+
89918 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
89919 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
89920
89921diff --git a/mm/mprotect.c b/mm/mprotect.c
89922index 94722a4..e661e29 100644
89923--- a/mm/mprotect.c
89924+++ b/mm/mprotect.c
89925@@ -23,10 +23,18 @@
89926 #include <linux/mmu_notifier.h>
89927 #include <linux/migrate.h>
89928 #include <linux/perf_event.h>
89929+#include <linux/sched/sysctl.h>
89930+
89931+#ifdef CONFIG_PAX_MPROTECT
89932+#include <linux/elf.h>
89933+#include <linux/binfmts.h>
89934+#endif
89935+
89936 #include <asm/uaccess.h>
89937 #include <asm/pgtable.h>
89938 #include <asm/cacheflush.h>
89939 #include <asm/tlbflush.h>
89940+#include <asm/mmu_context.h>
89941
89942 #ifndef pgprot_modify
89943 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
89944@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
89945 return pages;
89946 }
89947
89948+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
89949+/* called while holding the mmap semaphor for writing except stack expansion */
89950+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
89951+{
89952+ unsigned long oldlimit, newlimit = 0UL;
89953+
89954+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
89955+ return;
89956+
89957+ spin_lock(&mm->page_table_lock);
89958+ oldlimit = mm->context.user_cs_limit;
89959+ if ((prot & VM_EXEC) && oldlimit < end)
89960+ /* USER_CS limit moved up */
89961+ newlimit = end;
89962+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
89963+ /* USER_CS limit moved down */
89964+ newlimit = start;
89965+
89966+ if (newlimit) {
89967+ mm->context.user_cs_limit = newlimit;
89968+
89969+#ifdef CONFIG_SMP
89970+ wmb();
89971+ cpus_clear(mm->context.cpu_user_cs_mask);
89972+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
89973+#endif
89974+
89975+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
89976+ }
89977+ spin_unlock(&mm->page_table_lock);
89978+ if (newlimit == end) {
89979+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
89980+
89981+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
89982+ if (is_vm_hugetlb_page(vma))
89983+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
89984+ else
89985+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
89986+ }
89987+}
89988+#endif
89989+
89990 int
89991 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
89992 unsigned long start, unsigned long end, unsigned long newflags)
89993@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
89994 int error;
89995 int dirty_accountable = 0;
89996
89997+#ifdef CONFIG_PAX_SEGMEXEC
89998+ struct vm_area_struct *vma_m = NULL;
89999+ unsigned long start_m, end_m;
90000+
90001+ start_m = start + SEGMEXEC_TASK_SIZE;
90002+ end_m = end + SEGMEXEC_TASK_SIZE;
90003+#endif
90004+
90005 if (newflags == oldflags) {
90006 *pprev = vma;
90007 return 0;
90008 }
90009
90010+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
90011+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
90012+
90013+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
90014+ return -ENOMEM;
90015+
90016+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
90017+ return -ENOMEM;
90018+ }
90019+
90020 /*
90021 * If we make a private mapping writable we increase our commit;
90022 * but (without finer accounting) cannot reduce our commit if we
90023@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
90024 }
90025 }
90026
90027+#ifdef CONFIG_PAX_SEGMEXEC
90028+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
90029+ if (start != vma->vm_start) {
90030+ error = split_vma(mm, vma, start, 1);
90031+ if (error)
90032+ goto fail;
90033+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
90034+ *pprev = (*pprev)->vm_next;
90035+ }
90036+
90037+ if (end != vma->vm_end) {
90038+ error = split_vma(mm, vma, end, 0);
90039+ if (error)
90040+ goto fail;
90041+ }
90042+
90043+ if (pax_find_mirror_vma(vma)) {
90044+ error = __do_munmap(mm, start_m, end_m - start_m);
90045+ if (error)
90046+ goto fail;
90047+ } else {
90048+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
90049+ if (!vma_m) {
90050+ error = -ENOMEM;
90051+ goto fail;
90052+ }
90053+ vma->vm_flags = newflags;
90054+ error = pax_mirror_vma(vma_m, vma);
90055+ if (error) {
90056+ vma->vm_flags = oldflags;
90057+ goto fail;
90058+ }
90059+ }
90060+ }
90061+#endif
90062+
90063 /*
90064 * First try to merge with previous and/or next vma.
90065 */
90066@@ -296,9 +400,21 @@ success:
90067 * vm_flags and vm_page_prot are protected by the mmap_sem
90068 * held in write mode.
90069 */
90070+
90071+#ifdef CONFIG_PAX_SEGMEXEC
90072+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
90073+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
90074+#endif
90075+
90076 vma->vm_flags = newflags;
90077+
90078+#ifdef CONFIG_PAX_MPROTECT
90079+ if (mm->binfmt && mm->binfmt->handle_mprotect)
90080+ mm->binfmt->handle_mprotect(vma, newflags);
90081+#endif
90082+
90083 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
90084- vm_get_page_prot(newflags));
90085+ vm_get_page_prot(vma->vm_flags));
90086
90087 if (vma_wants_writenotify(vma)) {
90088 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
90089@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90090 end = start + len;
90091 if (end <= start)
90092 return -ENOMEM;
90093+
90094+#ifdef CONFIG_PAX_SEGMEXEC
90095+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
90096+ if (end > SEGMEXEC_TASK_SIZE)
90097+ return -EINVAL;
90098+ } else
90099+#endif
90100+
90101+ if (end > TASK_SIZE)
90102+ return -EINVAL;
90103+
90104 if (!arch_validate_prot(prot))
90105 return -EINVAL;
90106
90107@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90108 /*
90109 * Does the application expect PROT_READ to imply PROT_EXEC:
90110 */
90111- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
90112+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
90113 prot |= PROT_EXEC;
90114
90115 vm_flags = calc_vm_prot_bits(prot);
90116@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90117 if (start > vma->vm_start)
90118 prev = vma;
90119
90120+#ifdef CONFIG_PAX_MPROTECT
90121+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
90122+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
90123+#endif
90124+
90125 for (nstart = start ; ; ) {
90126 unsigned long newflags;
90127
90128@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90129
90130 /* newflags >> 4 shift VM_MAY% in place of VM_% */
90131 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
90132+ if (prot & (PROT_WRITE | PROT_EXEC))
90133+ gr_log_rwxmprotect(vma);
90134+
90135+ error = -EACCES;
90136+ goto out;
90137+ }
90138+
90139+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
90140 error = -EACCES;
90141 goto out;
90142 }
90143@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90144 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
90145 if (error)
90146 goto out;
90147+
90148+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
90149+
90150 nstart = tmp;
90151
90152 if (nstart < prev->vm_end)
90153diff --git a/mm/mremap.c b/mm/mremap.c
90154index 463a257..c0c7a92 100644
90155--- a/mm/mremap.c
90156+++ b/mm/mremap.c
90157@@ -126,6 +126,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
90158 continue;
90159 pte = ptep_get_and_clear(mm, old_addr, old_pte);
90160 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
90161+
90162+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
90163+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
90164+ pte = pte_exprotect(pte);
90165+#endif
90166+
90167 set_pte_at(mm, new_addr, new_pte, pte);
90168 }
90169
90170@@ -318,6 +324,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
90171 if (is_vm_hugetlb_page(vma))
90172 goto Einval;
90173
90174+#ifdef CONFIG_PAX_SEGMEXEC
90175+ if (pax_find_mirror_vma(vma))
90176+ goto Einval;
90177+#endif
90178+
90179 /* We can't remap across vm area boundaries */
90180 if (old_len > vma->vm_end - addr)
90181 goto Efault;
90182@@ -373,20 +384,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
90183 unsigned long ret = -EINVAL;
90184 unsigned long charged = 0;
90185 unsigned long map_flags;
90186+ unsigned long pax_task_size = TASK_SIZE;
90187
90188 if (new_addr & ~PAGE_MASK)
90189 goto out;
90190
90191- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
90192+#ifdef CONFIG_PAX_SEGMEXEC
90193+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
90194+ pax_task_size = SEGMEXEC_TASK_SIZE;
90195+#endif
90196+
90197+ pax_task_size -= PAGE_SIZE;
90198+
90199+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
90200 goto out;
90201
90202 /* Check if the location we're moving into overlaps the
90203 * old location at all, and fail if it does.
90204 */
90205- if ((new_addr <= addr) && (new_addr+new_len) > addr)
90206- goto out;
90207-
90208- if ((addr <= new_addr) && (addr+old_len) > new_addr)
90209+ if (addr + old_len > new_addr && new_addr + new_len > addr)
90210 goto out;
90211
90212 ret = do_munmap(mm, new_addr, new_len);
90213@@ -455,6 +471,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
90214 unsigned long ret = -EINVAL;
90215 unsigned long charged = 0;
90216 bool locked = false;
90217+ unsigned long pax_task_size = TASK_SIZE;
90218
90219 down_write(&current->mm->mmap_sem);
90220
90221@@ -475,6 +492,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
90222 if (!new_len)
90223 goto out;
90224
90225+#ifdef CONFIG_PAX_SEGMEXEC
90226+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
90227+ pax_task_size = SEGMEXEC_TASK_SIZE;
90228+#endif
90229+
90230+ pax_task_size -= PAGE_SIZE;
90231+
90232+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
90233+ old_len > pax_task_size || addr > pax_task_size-old_len)
90234+ goto out;
90235+
90236 if (flags & MREMAP_FIXED) {
90237 if (flags & MREMAP_MAYMOVE)
90238 ret = mremap_to(addr, old_len, new_addr, new_len,
90239@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
90240 new_addr = addr;
90241 }
90242 ret = addr;
90243+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
90244 goto out;
90245 }
90246 }
90247@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
90248 goto out;
90249 }
90250
90251+ map_flags = vma->vm_flags;
90252 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
90253+ if (!(ret & ~PAGE_MASK)) {
90254+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
90255+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
90256+ }
90257 }
90258 out:
90259 if (ret & ~PAGE_MASK)
90260diff --git a/mm/nommu.c b/mm/nommu.c
90261index 298884d..5f74980 100644
90262--- a/mm/nommu.c
90263+++ b/mm/nommu.c
90264@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
90265 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
90266 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
90267 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
90268-int heap_stack_gap = 0;
90269
90270 atomic_long_t mmap_pages_allocated;
90271
90272@@ -842,15 +841,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
90273 EXPORT_SYMBOL(find_vma);
90274
90275 /*
90276- * find a VMA
90277- * - we don't extend stack VMAs under NOMMU conditions
90278- */
90279-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
90280-{
90281- return find_vma(mm, addr);
90282-}
90283-
90284-/*
90285 * expand a stack to a given address
90286 * - not supported under NOMMU conditions
90287 */
90288@@ -1561,6 +1551,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
90289
90290 /* most fields are the same, copy all, and then fixup */
90291 *new = *vma;
90292+ INIT_LIST_HEAD(&new->anon_vma_chain);
90293 *region = *vma->vm_region;
90294 new->vm_region = region;
90295
90296@@ -1995,8 +1986,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
90297 }
90298 EXPORT_SYMBOL(generic_file_remap_pages);
90299
90300-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
90301- unsigned long addr, void *buf, int len, int write)
90302+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
90303+ unsigned long addr, void *buf, size_t len, int write)
90304 {
90305 struct vm_area_struct *vma;
90306
90307@@ -2037,8 +2028,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
90308 *
90309 * The caller must hold a reference on @mm.
90310 */
90311-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
90312- void *buf, int len, int write)
90313+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
90314+ void *buf, size_t len, int write)
90315 {
90316 return __access_remote_vm(NULL, mm, addr, buf, len, write);
90317 }
90318@@ -2047,7 +2038,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
90319 * Access another process' address space.
90320 * - source/target buffer must be kernel space
90321 */
90322-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
90323+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
90324 {
90325 struct mm_struct *mm;
90326
90327diff --git a/mm/page-writeback.c b/mm/page-writeback.c
90328index 4514ad7..92eaa1c 100644
90329--- a/mm/page-writeback.c
90330+++ b/mm/page-writeback.c
90331@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
90332 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
90333 * - the bdi dirty thresh drops quickly due to change of JBOD workload
90334 */
90335-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
90336+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
90337 unsigned long thresh,
90338 unsigned long bg_thresh,
90339 unsigned long dirty,
90340@@ -1634,7 +1634,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
90341 }
90342 }
90343
90344-static struct notifier_block __cpuinitdata ratelimit_nb = {
90345+static struct notifier_block ratelimit_nb = {
90346 .notifier_call = ratelimit_handler,
90347 .next = NULL,
90348 };
90349diff --git a/mm/page_alloc.c b/mm/page_alloc.c
90350index 2ee0fd3..6e2edfb 100644
90351--- a/mm/page_alloc.c
90352+++ b/mm/page_alloc.c
90353@@ -60,6 +60,7 @@
90354 #include <linux/page-debug-flags.h>
90355 #include <linux/hugetlb.h>
90356 #include <linux/sched/rt.h>
90357+#include <linux/random.h>
90358
90359 #include <asm/tlbflush.h>
90360 #include <asm/div64.h>
90361@@ -345,7 +346,7 @@ out:
90362 * This usage means that zero-order pages may not be compound.
90363 */
90364
90365-static void free_compound_page(struct page *page)
90366+void free_compound_page(struct page *page)
90367 {
90368 __free_pages_ok(page, compound_order(page));
90369 }
90370@@ -702,6 +703,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
90371 int i;
90372 int bad = 0;
90373
90374+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90375+ unsigned long index = 1UL << order;
90376+#endif
90377+
90378 trace_mm_page_free(page, order);
90379 kmemcheck_free_shadow(page, order);
90380
90381@@ -717,6 +722,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
90382 debug_check_no_obj_freed(page_address(page),
90383 PAGE_SIZE << order);
90384 }
90385+
90386+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90387+ for (; index; --index)
90388+ sanitize_highpage(page + index - 1);
90389+#endif
90390+
90391 arch_free_page(page, order);
90392 kernel_map_pages(page, 1 << order, 0);
90393
90394@@ -739,6 +750,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
90395 local_irq_restore(flags);
90396 }
90397
90398+#ifdef CONFIG_PAX_LATENT_ENTROPY
90399+bool __meminitdata extra_latent_entropy;
90400+
90401+static int __init setup_pax_extra_latent_entropy(char *str)
90402+{
90403+ extra_latent_entropy = true;
90404+ return 0;
90405+}
90406+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
90407+
90408+volatile u64 latent_entropy;
90409+#endif
90410+
90411 /*
90412 * Read access to zone->managed_pages is safe because it's unsigned long,
90413 * but we still need to serialize writers. Currently all callers of
90414@@ -761,6 +785,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
90415 set_page_count(p, 0);
90416 }
90417
90418+#ifdef CONFIG_PAX_LATENT_ENTROPY
90419+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
90420+ u64 hash = 0;
90421+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
90422+ const u64 *data = lowmem_page_address(page);
90423+
90424+ for (index = 0; index < end; index++)
90425+ hash ^= hash + data[index];
90426+ latent_entropy ^= hash;
90427+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
90428+ }
90429+#endif
90430+
90431 page_zone(page)->managed_pages += 1 << order;
90432 set_page_refcounted(page);
90433 __free_pages(page, order);
90434@@ -870,8 +907,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
90435 arch_alloc_page(page, order);
90436 kernel_map_pages(page, 1 << order, 1);
90437
90438+#ifndef CONFIG_PAX_MEMORY_SANITIZE
90439 if (gfp_flags & __GFP_ZERO)
90440 prep_zero_page(page, order, gfp_flags);
90441+#endif
90442
90443 if (order && (gfp_flags & __GFP_COMP))
90444 prep_compound_page(page, order);
90445diff --git a/mm/page_io.c b/mm/page_io.c
90446index a8a3ef4..7260a60 100644
90447--- a/mm/page_io.c
90448+++ b/mm/page_io.c
90449@@ -214,7 +214,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
90450 struct file *swap_file = sis->swap_file;
90451 struct address_space *mapping = swap_file->f_mapping;
90452 struct iovec iov = {
90453- .iov_base = kmap(page),
90454+ .iov_base = (void __force_user *)kmap(page),
90455 .iov_len = PAGE_SIZE,
90456 };
90457
90458diff --git a/mm/percpu.c b/mm/percpu.c
90459index 8c8e08f..73a5cda 100644
90460--- a/mm/percpu.c
90461+++ b/mm/percpu.c
90462@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
90463 static unsigned int pcpu_high_unit_cpu __read_mostly;
90464
90465 /* the address of the first chunk which starts with the kernel static area */
90466-void *pcpu_base_addr __read_mostly;
90467+void *pcpu_base_addr __read_only;
90468 EXPORT_SYMBOL_GPL(pcpu_base_addr);
90469
90470 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
90471diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
90472index fd26d04..0cea1b0 100644
90473--- a/mm/process_vm_access.c
90474+++ b/mm/process_vm_access.c
90475@@ -13,6 +13,7 @@
90476 #include <linux/uio.h>
90477 #include <linux/sched.h>
90478 #include <linux/highmem.h>
90479+#include <linux/security.h>
90480 #include <linux/ptrace.h>
90481 #include <linux/slab.h>
90482 #include <linux/syscalls.h>
90483@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
90484 size_t iov_l_curr_offset = 0;
90485 ssize_t iov_len;
90486
90487+ return -ENOSYS; // PaX: until properly audited
90488+
90489 /*
90490 * Work out how many pages of struct pages we're going to need
90491 * when eventually calling get_user_pages
90492 */
90493 for (i = 0; i < riovcnt; i++) {
90494 iov_len = rvec[i].iov_len;
90495- if (iov_len > 0) {
90496- nr_pages_iov = ((unsigned long)rvec[i].iov_base
90497- + iov_len)
90498- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
90499- / PAGE_SIZE + 1;
90500- nr_pages = max(nr_pages, nr_pages_iov);
90501- }
90502+ if (iov_len <= 0)
90503+ continue;
90504+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
90505+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
90506+ nr_pages = max(nr_pages, nr_pages_iov);
90507 }
90508
90509 if (nr_pages == 0)
90510@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
90511 goto free_proc_pages;
90512 }
90513
90514+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
90515+ rc = -EPERM;
90516+ goto put_task_struct;
90517+ }
90518+
90519 mm = mm_access(task, PTRACE_MODE_ATTACH);
90520 if (!mm || IS_ERR(mm)) {
90521 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
90522diff --git a/mm/rmap.c b/mm/rmap.c
90523index 6280da8..b5c090e 100644
90524--- a/mm/rmap.c
90525+++ b/mm/rmap.c
90526@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90527 struct anon_vma *anon_vma = vma->anon_vma;
90528 struct anon_vma_chain *avc;
90529
90530+#ifdef CONFIG_PAX_SEGMEXEC
90531+ struct anon_vma_chain *avc_m = NULL;
90532+#endif
90533+
90534 might_sleep();
90535 if (unlikely(!anon_vma)) {
90536 struct mm_struct *mm = vma->vm_mm;
90537@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90538 if (!avc)
90539 goto out_enomem;
90540
90541+#ifdef CONFIG_PAX_SEGMEXEC
90542+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
90543+ if (!avc_m)
90544+ goto out_enomem_free_avc;
90545+#endif
90546+
90547 anon_vma = find_mergeable_anon_vma(vma);
90548 allocated = NULL;
90549 if (!anon_vma) {
90550@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90551 /* page_table_lock to protect against threads */
90552 spin_lock(&mm->page_table_lock);
90553 if (likely(!vma->anon_vma)) {
90554+
90555+#ifdef CONFIG_PAX_SEGMEXEC
90556+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
90557+
90558+ if (vma_m) {
90559+ BUG_ON(vma_m->anon_vma);
90560+ vma_m->anon_vma = anon_vma;
90561+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
90562+ avc_m = NULL;
90563+ }
90564+#endif
90565+
90566 vma->anon_vma = anon_vma;
90567 anon_vma_chain_link(vma, avc, anon_vma);
90568 allocated = NULL;
90569@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90570
90571 if (unlikely(allocated))
90572 put_anon_vma(allocated);
90573+
90574+#ifdef CONFIG_PAX_SEGMEXEC
90575+ if (unlikely(avc_m))
90576+ anon_vma_chain_free(avc_m);
90577+#endif
90578+
90579 if (unlikely(avc))
90580 anon_vma_chain_free(avc);
90581 }
90582 return 0;
90583
90584 out_enomem_free_avc:
90585+
90586+#ifdef CONFIG_PAX_SEGMEXEC
90587+ if (avc_m)
90588+ anon_vma_chain_free(avc_m);
90589+#endif
90590+
90591 anon_vma_chain_free(avc);
90592 out_enomem:
90593 return -ENOMEM;
90594@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
90595 * Attach the anon_vmas from src to dst.
90596 * Returns 0 on success, -ENOMEM on failure.
90597 */
90598-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
90599+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
90600 {
90601 struct anon_vma_chain *avc, *pavc;
90602 struct anon_vma *root = NULL;
90603@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
90604 * the corresponding VMA in the parent process is attached to.
90605 * Returns 0 on success, non-zero on failure.
90606 */
90607-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
90608+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
90609 {
90610 struct anon_vma_chain *avc;
90611 struct anon_vma *anon_vma;
90612@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
90613 void __init anon_vma_init(void)
90614 {
90615 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
90616- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
90617- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
90618+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
90619+ anon_vma_ctor);
90620+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
90621+ SLAB_PANIC|SLAB_NO_SANITIZE);
90622 }
90623
90624 /*
90625diff --git a/mm/shmem.c b/mm/shmem.c
90626index 5e6a842..b41916e 100644
90627--- a/mm/shmem.c
90628+++ b/mm/shmem.c
90629@@ -33,7 +33,7 @@
90630 #include <linux/swap.h>
90631 #include <linux/aio.h>
90632
90633-static struct vfsmount *shm_mnt;
90634+struct vfsmount *shm_mnt;
90635
90636 #ifdef CONFIG_SHMEM
90637 /*
90638@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
90639 #define BOGO_DIRENT_SIZE 20
90640
90641 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
90642-#define SHORT_SYMLINK_LEN 128
90643+#define SHORT_SYMLINK_LEN 64
90644
90645 /*
90646 * shmem_fallocate and shmem_writepage communicate via inode->i_private
90647@@ -2203,6 +2203,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
90648 static int shmem_xattr_validate(const char *name)
90649 {
90650 struct { const char *prefix; size_t len; } arr[] = {
90651+
90652+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
90653+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
90654+#endif
90655+
90656 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
90657 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
90658 };
90659@@ -2258,6 +2263,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
90660 if (err)
90661 return err;
90662
90663+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
90664+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
90665+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
90666+ return -EOPNOTSUPP;
90667+ if (size > 8)
90668+ return -EINVAL;
90669+ }
90670+#endif
90671+
90672 return simple_xattr_set(&info->xattrs, name, value, size, flags);
90673 }
90674
90675@@ -2570,8 +2584,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
90676 int err = -ENOMEM;
90677
90678 /* Round up to L1_CACHE_BYTES to resist false sharing */
90679- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
90680- L1_CACHE_BYTES), GFP_KERNEL);
90681+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
90682 if (!sbinfo)
90683 return -ENOMEM;
90684
90685diff --git a/mm/slab.c b/mm/slab.c
90686index bd88411..2d46fd6 100644
90687--- a/mm/slab.c
90688+++ b/mm/slab.c
90689@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
90690 if ((x)->max_freeable < i) \
90691 (x)->max_freeable = i; \
90692 } while (0)
90693-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
90694-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
90695-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
90696-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
90697+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
90698+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
90699+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
90700+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
90701+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
90702+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
90703 #else
90704 #define STATS_INC_ACTIVE(x) do { } while (0)
90705 #define STATS_DEC_ACTIVE(x) do { } while (0)
90706@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
90707 #define STATS_INC_ALLOCMISS(x) do { } while (0)
90708 #define STATS_INC_FREEHIT(x) do { } while (0)
90709 #define STATS_INC_FREEMISS(x) do { } while (0)
90710+#define STATS_INC_SANITIZED(x) do { } while (0)
90711+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
90712 #endif
90713
90714 #if DEBUG
90715@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
90716 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
90717 */
90718 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
90719- const struct slab *slab, void *obj)
90720+ const struct slab *slab, const void *obj)
90721 {
90722 u32 offset = (obj - slab->s_mem);
90723 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
90724@@ -1384,7 +1388,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
90725 return notifier_from_errno(err);
90726 }
90727
90728-static struct notifier_block __cpuinitdata cpucache_notifier = {
90729+static struct notifier_block cpucache_notifier = {
90730 &cpuup_callback, NULL, 0
90731 };
90732
90733@@ -1565,12 +1569,12 @@ void __init kmem_cache_init(void)
90734 */
90735
90736 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
90737- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
90738+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
90739
90740 if (INDEX_AC != INDEX_NODE)
90741 kmalloc_caches[INDEX_NODE] =
90742 create_kmalloc_cache("kmalloc-node",
90743- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
90744+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
90745
90746 slab_early_init = 0;
90747
90748@@ -3583,6 +3587,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
90749 struct array_cache *ac = cpu_cache_get(cachep);
90750
90751 check_irq_off();
90752+
90753+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90754+ if (pax_sanitize_slab) {
90755+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
90756+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
90757+
90758+ if (cachep->ctor)
90759+ cachep->ctor(objp);
90760+
90761+ STATS_INC_SANITIZED(cachep);
90762+ } else
90763+ STATS_INC_NOT_SANITIZED(cachep);
90764+ }
90765+#endif
90766+
90767 kmemleak_free_recursive(objp, cachep->flags);
90768 objp = cache_free_debugcheck(cachep, objp, caller);
90769
90770@@ -3800,6 +3819,7 @@ void kfree(const void *objp)
90771
90772 if (unlikely(ZERO_OR_NULL_PTR(objp)))
90773 return;
90774+ VM_BUG_ON(!virt_addr_valid(objp));
90775 local_irq_save(flags);
90776 kfree_debugcheck(objp);
90777 c = virt_to_cache(objp);
90778@@ -4241,14 +4261,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
90779 }
90780 /* cpu stats */
90781 {
90782- unsigned long allochit = atomic_read(&cachep->allochit);
90783- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
90784- unsigned long freehit = atomic_read(&cachep->freehit);
90785- unsigned long freemiss = atomic_read(&cachep->freemiss);
90786+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
90787+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
90788+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
90789+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
90790
90791 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
90792 allochit, allocmiss, freehit, freemiss);
90793 }
90794+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90795+ {
90796+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
90797+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
90798+
90799+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
90800+ }
90801+#endif
90802 #endif
90803 }
90804
90805@@ -4476,13 +4504,71 @@ static const struct file_operations proc_slabstats_operations = {
90806 static int __init slab_proc_init(void)
90807 {
90808 #ifdef CONFIG_DEBUG_SLAB_LEAK
90809- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
90810+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
90811 #endif
90812 return 0;
90813 }
90814 module_init(slab_proc_init);
90815 #endif
90816
90817+bool is_usercopy_object(const void *ptr)
90818+{
90819+ struct page *page;
90820+ struct kmem_cache *cachep;
90821+
90822+ if (ZERO_OR_NULL_PTR(ptr))
90823+ return false;
90824+
90825+ if (!slab_is_available())
90826+ return false;
90827+
90828+ if (!virt_addr_valid(ptr))
90829+ return false;
90830+
90831+ page = virt_to_head_page(ptr);
90832+
90833+ if (!PageSlab(page))
90834+ return false;
90835+
90836+ cachep = page->slab_cache;
90837+ return cachep->flags & SLAB_USERCOPY;
90838+}
90839+
90840+#ifdef CONFIG_PAX_USERCOPY
90841+const char *check_heap_object(const void *ptr, unsigned long n)
90842+{
90843+ struct page *page;
90844+ struct kmem_cache *cachep;
90845+ struct slab *slabp;
90846+ unsigned int objnr;
90847+ unsigned long offset;
90848+
90849+ if (ZERO_OR_NULL_PTR(ptr))
90850+ return "<null>";
90851+
90852+ if (!virt_addr_valid(ptr))
90853+ return NULL;
90854+
90855+ page = virt_to_head_page(ptr);
90856+
90857+ if (!PageSlab(page))
90858+ return NULL;
90859+
90860+ cachep = page->slab_cache;
90861+ if (!(cachep->flags & SLAB_USERCOPY))
90862+ return cachep->name;
90863+
90864+ slabp = page->slab_page;
90865+ objnr = obj_to_index(cachep, slabp, ptr);
90866+ BUG_ON(objnr >= cachep->num);
90867+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
90868+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
90869+ return NULL;
90870+
90871+ return cachep->name;
90872+}
90873+#endif
90874+
90875 /**
90876 * ksize - get the actual amount of memory allocated for a given object
90877 * @objp: Pointer to the object
90878diff --git a/mm/slab.h b/mm/slab.h
90879index 4d6d836..3fb743a 100644
90880--- a/mm/slab.h
90881+++ b/mm/slab.h
90882@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
90883 /* The slab cache that manages slab cache information */
90884 extern struct kmem_cache *kmem_cache;
90885
90886+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90887+#ifdef CONFIG_X86_64
90888+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
90889+#else
90890+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
90891+#endif
90892+extern bool pax_sanitize_slab;
90893+#endif
90894+
90895 unsigned long calculate_alignment(unsigned long flags,
90896 unsigned long align, unsigned long size);
90897
90898@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90899
90900 /* Legal flag mask for kmem_cache_create(), for various configurations */
90901 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
90902- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
90903+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
90904+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
90905
90906 #if defined(CONFIG_DEBUG_SLAB)
90907 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
90908@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
90909 return s;
90910
90911 page = virt_to_head_page(x);
90912+
90913+ BUG_ON(!PageSlab(page));
90914+
90915 cachep = page->slab_cache;
90916 if (slab_equal_or_root(cachep, s))
90917 return cachep;
90918diff --git a/mm/slab_common.c b/mm/slab_common.c
90919index 2d41450..4efe6ee 100644
90920--- a/mm/slab_common.c
90921+++ b/mm/slab_common.c
90922@@ -22,11 +22,22 @@
90923
90924 #include "slab.h"
90925
90926-enum slab_state slab_state;
90927+enum slab_state slab_state __read_only;
90928 LIST_HEAD(slab_caches);
90929 DEFINE_MUTEX(slab_mutex);
90930 struct kmem_cache *kmem_cache;
90931
90932+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90933+bool pax_sanitize_slab __read_only = true;
90934+static int __init pax_sanitize_slab_setup(char *str)
90935+{
90936+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
90937+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
90938+ return 1;
90939+}
90940+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
90941+#endif
90942+
90943 #ifdef CONFIG_DEBUG_VM
90944 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
90945 size_t size)
90946@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
90947
90948 err = __kmem_cache_create(s, flags);
90949 if (!err) {
90950- s->refcount = 1;
90951+ atomic_set(&s->refcount, 1);
90952 list_add(&s->list, &slab_caches);
90953 memcg_cache_list_add(memcg, s);
90954 } else {
90955@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
90956
90957 get_online_cpus();
90958 mutex_lock(&slab_mutex);
90959- s->refcount--;
90960- if (!s->refcount) {
90961+ if (atomic_dec_and_test(&s->refcount)) {
90962 list_del(&s->list);
90963
90964 if (!__kmem_cache_shutdown(s)) {
90965@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
90966 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
90967 name, size, err);
90968
90969- s->refcount = -1; /* Exempt from merging for now */
90970+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
90971 }
90972
90973 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
90974@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
90975
90976 create_boot_cache(s, name, size, flags);
90977 list_add(&s->list, &slab_caches);
90978- s->refcount = 1;
90979+ atomic_set(&s->refcount, 1);
90980 return s;
90981 }
90982
90983@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
90984 EXPORT_SYMBOL(kmalloc_dma_caches);
90985 #endif
90986
90987+#ifdef CONFIG_PAX_USERCOPY_SLABS
90988+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
90989+EXPORT_SYMBOL(kmalloc_usercopy_caches);
90990+#endif
90991+
90992 /*
90993 * Conversion table for small slabs sizes / 8 to the index in the
90994 * kmalloc array. This is necessary for slabs < 192 since we have non power
90995@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
90996 return kmalloc_dma_caches[index];
90997
90998 #endif
90999+
91000+#ifdef CONFIG_PAX_USERCOPY_SLABS
91001+ if (unlikely((flags & GFP_USERCOPY)))
91002+ return kmalloc_usercopy_caches[index];
91003+
91004+#endif
91005+
91006 return kmalloc_caches[index];
91007 }
91008
91009@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
91010 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
91011 if (!kmalloc_caches[i]) {
91012 kmalloc_caches[i] = create_kmalloc_cache(NULL,
91013- 1 << i, flags);
91014+ 1 << i, SLAB_USERCOPY | flags);
91015 }
91016
91017 /*
91018@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
91019 * earlier power of two caches
91020 */
91021 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
91022- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
91023+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
91024
91025 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
91026- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
91027+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
91028 }
91029
91030 /* Kmalloc array is now usable */
91031@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
91032 }
91033 }
91034 #endif
91035+
91036+#ifdef CONFIG_PAX_USERCOPY_SLABS
91037+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
91038+ struct kmem_cache *s = kmalloc_caches[i];
91039+
91040+ if (s) {
91041+ int size = kmalloc_size(i);
91042+ char *n = kasprintf(GFP_NOWAIT,
91043+ "usercopy-kmalloc-%d", size);
91044+
91045+ BUG_ON(!n);
91046+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
91047+ size, SLAB_USERCOPY | flags);
91048+ }
91049+ }
91050+#endif
91051+
91052 }
91053 #endif /* !CONFIG_SLOB */
91054
91055@@ -516,6 +555,9 @@ void print_slabinfo_header(struct seq_file *m)
91056 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
91057 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
91058 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
91059+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91060+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
91061+#endif
91062 #endif
91063 seq_putc(m, '\n');
91064 }
91065diff --git a/mm/slob.c b/mm/slob.c
91066index eeed4a0..bb0e9ab 100644
91067--- a/mm/slob.c
91068+++ b/mm/slob.c
91069@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
91070 /*
91071 * Return the size of a slob block.
91072 */
91073-static slobidx_t slob_units(slob_t *s)
91074+static slobidx_t slob_units(const slob_t *s)
91075 {
91076 if (s->units > 0)
91077 return s->units;
91078@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
91079 /*
91080 * Return the next free slob block pointer after this one.
91081 */
91082-static slob_t *slob_next(slob_t *s)
91083+static slob_t *slob_next(const slob_t *s)
91084 {
91085 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
91086 slobidx_t next;
91087@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
91088 /*
91089 * Returns true if s is the last free block in its page.
91090 */
91091-static int slob_last(slob_t *s)
91092+static int slob_last(const slob_t *s)
91093 {
91094 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
91095 }
91096
91097-static void *slob_new_pages(gfp_t gfp, int order, int node)
91098+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
91099 {
91100- void *page;
91101+ struct page *page;
91102
91103 #ifdef CONFIG_NUMA
91104 if (node != NUMA_NO_NODE)
91105@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
91106 if (!page)
91107 return NULL;
91108
91109- return page_address(page);
91110+ __SetPageSlab(page);
91111+ return page;
91112 }
91113
91114-static void slob_free_pages(void *b, int order)
91115+static void slob_free_pages(struct page *sp, int order)
91116 {
91117 if (current->reclaim_state)
91118 current->reclaim_state->reclaimed_slab += 1 << order;
91119- free_pages((unsigned long)b, order);
91120+ __ClearPageSlab(sp);
91121+ page_mapcount_reset(sp);
91122+ sp->private = 0;
91123+ __free_pages(sp, order);
91124 }
91125
91126 /*
91127@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
91128
91129 /* Not enough space: must allocate a new page */
91130 if (!b) {
91131- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
91132- if (!b)
91133+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
91134+ if (!sp)
91135 return NULL;
91136- sp = virt_to_page(b);
91137- __SetPageSlab(sp);
91138+ b = page_address(sp);
91139
91140 spin_lock_irqsave(&slob_lock, flags);
91141 sp->units = SLOB_UNITS(PAGE_SIZE);
91142 sp->freelist = b;
91143+ sp->private = 0;
91144 INIT_LIST_HEAD(&sp->list);
91145 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
91146 set_slob_page_free(sp, slob_list);
91147@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
91148 if (slob_page_free(sp))
91149 clear_slob_page_free(sp);
91150 spin_unlock_irqrestore(&slob_lock, flags);
91151- __ClearPageSlab(sp);
91152- page_mapcount_reset(sp);
91153- slob_free_pages(b, 0);
91154+ slob_free_pages(sp, 0);
91155 return;
91156 }
91157
91158+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91159+ if (pax_sanitize_slab)
91160+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
91161+#endif
91162+
91163 if (!slob_page_free(sp)) {
91164 /* This slob page is about to become partially free. Easy! */
91165 sp->units = units;
91166@@ -424,11 +431,10 @@ out:
91167 */
91168
91169 static __always_inline void *
91170-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
91171+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
91172 {
91173- unsigned int *m;
91174- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91175- void *ret;
91176+ slob_t *m;
91177+ void *ret = NULL;
91178
91179 gfp &= gfp_allowed_mask;
91180
91181@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
91182
91183 if (!m)
91184 return NULL;
91185- *m = size;
91186+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
91187+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
91188+ m[0].units = size;
91189+ m[1].units = align;
91190 ret = (void *)m + align;
91191
91192 trace_kmalloc_node(caller, ret,
91193 size, size + align, gfp, node);
91194 } else {
91195 unsigned int order = get_order(size);
91196+ struct page *page;
91197
91198 if (likely(order))
91199 gfp |= __GFP_COMP;
91200- ret = slob_new_pages(gfp, order, node);
91201+ page = slob_new_pages(gfp, order, node);
91202+ if (page) {
91203+ ret = page_address(page);
91204+ page->private = size;
91205+ }
91206
91207 trace_kmalloc_node(caller, ret,
91208 size, PAGE_SIZE << order, gfp, node);
91209 }
91210
91211- kmemleak_alloc(ret, size, 1, gfp);
91212+ return ret;
91213+}
91214+
91215+static __always_inline void *
91216+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
91217+{
91218+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91219+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
91220+
91221+ if (!ZERO_OR_NULL_PTR(ret))
91222+ kmemleak_alloc(ret, size, 1, gfp);
91223 return ret;
91224 }
91225
91226@@ -493,34 +517,112 @@ void kfree(const void *block)
91227 return;
91228 kmemleak_free(block);
91229
91230+ VM_BUG_ON(!virt_addr_valid(block));
91231 sp = virt_to_page(block);
91232- if (PageSlab(sp)) {
91233+ VM_BUG_ON(!PageSlab(sp));
91234+ if (!sp->private) {
91235 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91236- unsigned int *m = (unsigned int *)(block - align);
91237- slob_free(m, *m + align);
91238- } else
91239+ slob_t *m = (slob_t *)(block - align);
91240+ slob_free(m, m[0].units + align);
91241+ } else {
91242+ __ClearPageSlab(sp);
91243+ page_mapcount_reset(sp);
91244+ sp->private = 0;
91245 __free_pages(sp, compound_order(sp));
91246+ }
91247 }
91248 EXPORT_SYMBOL(kfree);
91249
91250+bool is_usercopy_object(const void *ptr)
91251+{
91252+ if (!slab_is_available())
91253+ return false;
91254+
91255+ // PAX: TODO
91256+
91257+ return false;
91258+}
91259+
91260+#ifdef CONFIG_PAX_USERCOPY
91261+const char *check_heap_object(const void *ptr, unsigned long n)
91262+{
91263+ struct page *page;
91264+ const slob_t *free;
91265+ const void *base;
91266+ unsigned long flags;
91267+
91268+ if (ZERO_OR_NULL_PTR(ptr))
91269+ return "<null>";
91270+
91271+ if (!virt_addr_valid(ptr))
91272+ return NULL;
91273+
91274+ page = virt_to_head_page(ptr);
91275+ if (!PageSlab(page))
91276+ return NULL;
91277+
91278+ if (page->private) {
91279+ base = page;
91280+ if (base <= ptr && n <= page->private - (ptr - base))
91281+ return NULL;
91282+ return "<slob>";
91283+ }
91284+
91285+ /* some tricky double walking to find the chunk */
91286+ spin_lock_irqsave(&slob_lock, flags);
91287+ base = (void *)((unsigned long)ptr & PAGE_MASK);
91288+ free = page->freelist;
91289+
91290+ while (!slob_last(free) && (void *)free <= ptr) {
91291+ base = free + slob_units(free);
91292+ free = slob_next(free);
91293+ }
91294+
91295+ while (base < (void *)free) {
91296+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
91297+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
91298+ int offset;
91299+
91300+ if (ptr < base + align)
91301+ break;
91302+
91303+ offset = ptr - base - align;
91304+ if (offset >= m) {
91305+ base += size;
91306+ continue;
91307+ }
91308+
91309+ if (n > m - offset)
91310+ break;
91311+
91312+ spin_unlock_irqrestore(&slob_lock, flags);
91313+ return NULL;
91314+ }
91315+
91316+ spin_unlock_irqrestore(&slob_lock, flags);
91317+ return "<slob>";
91318+}
91319+#endif
91320+
91321 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
91322 size_t ksize(const void *block)
91323 {
91324 struct page *sp;
91325 int align;
91326- unsigned int *m;
91327+ slob_t *m;
91328
91329 BUG_ON(!block);
91330 if (unlikely(block == ZERO_SIZE_PTR))
91331 return 0;
91332
91333 sp = virt_to_page(block);
91334- if (unlikely(!PageSlab(sp)))
91335- return PAGE_SIZE << compound_order(sp);
91336+ VM_BUG_ON(!PageSlab(sp));
91337+ if (sp->private)
91338+ return sp->private;
91339
91340 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91341- m = (unsigned int *)(block - align);
91342- return SLOB_UNITS(*m) * SLOB_UNIT;
91343+ m = (slob_t *)(block - align);
91344+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
91345 }
91346 EXPORT_SYMBOL(ksize);
91347
91348@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
91349
91350 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
91351 {
91352- void *b;
91353+ void *b = NULL;
91354
91355 flags &= gfp_allowed_mask;
91356
91357 lockdep_trace_alloc(flags);
91358
91359+#ifdef CONFIG_PAX_USERCOPY_SLABS
91360+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
91361+#else
91362 if (c->size < PAGE_SIZE) {
91363 b = slob_alloc(c->size, flags, c->align, node);
91364 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
91365 SLOB_UNITS(c->size) * SLOB_UNIT,
91366 flags, node);
91367 } else {
91368- b = slob_new_pages(flags, get_order(c->size), node);
91369+ struct page *sp;
91370+
91371+ sp = slob_new_pages(flags, get_order(c->size), node);
91372+ if (sp) {
91373+ b = page_address(sp);
91374+ sp->private = c->size;
91375+ }
91376 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
91377 PAGE_SIZE << get_order(c->size),
91378 flags, node);
91379 }
91380+#endif
91381
91382 if (c->ctor)
91383 c->ctor(b);
91384@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
91385
91386 static void __kmem_cache_free(void *b, int size)
91387 {
91388- if (size < PAGE_SIZE)
91389+ struct page *sp;
91390+
91391+ sp = virt_to_page(b);
91392+ BUG_ON(!PageSlab(sp));
91393+ if (!sp->private)
91394 slob_free(b, size);
91395 else
91396- slob_free_pages(b, get_order(size));
91397+ slob_free_pages(sp, get_order(size));
91398 }
91399
91400 static void kmem_rcu_free(struct rcu_head *head)
91401@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
91402
91403 void kmem_cache_free(struct kmem_cache *c, void *b)
91404 {
91405+ int size = c->size;
91406+
91407+#ifdef CONFIG_PAX_USERCOPY_SLABS
91408+ if (size + c->align < PAGE_SIZE) {
91409+ size += c->align;
91410+ b -= c->align;
91411+ }
91412+#endif
91413+
91414 kmemleak_free_recursive(b, c->flags);
91415 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
91416 struct slob_rcu *slob_rcu;
91417- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
91418- slob_rcu->size = c->size;
91419+ slob_rcu = b + (size - sizeof(struct slob_rcu));
91420+ slob_rcu->size = size;
91421 call_rcu(&slob_rcu->head, kmem_rcu_free);
91422 } else {
91423- __kmem_cache_free(b, c->size);
91424+ __kmem_cache_free(b, size);
91425 }
91426
91427+#ifdef CONFIG_PAX_USERCOPY_SLABS
91428+ trace_kfree(_RET_IP_, b);
91429+#else
91430 trace_kmem_cache_free(_RET_IP_, b);
91431+#endif
91432+
91433 }
91434 EXPORT_SYMBOL(kmem_cache_free);
91435
91436diff --git a/mm/slub.c b/mm/slub.c
91437index 57707f0..7857bd3 100644
91438--- a/mm/slub.c
91439+++ b/mm/slub.c
91440@@ -198,7 +198,7 @@ struct track {
91441
91442 enum track_item { TRACK_ALLOC, TRACK_FREE };
91443
91444-#ifdef CONFIG_SYSFS
91445+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91446 static int sysfs_slab_add(struct kmem_cache *);
91447 static int sysfs_slab_alias(struct kmem_cache *, const char *);
91448 static void sysfs_slab_remove(struct kmem_cache *);
91449@@ -519,7 +519,7 @@ static void print_track(const char *s, struct track *t)
91450 if (!t->addr)
91451 return;
91452
91453- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
91454+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
91455 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
91456 #ifdef CONFIG_STACKTRACE
91457 {
91458@@ -2594,6 +2594,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
91459
91460 slab_free_hook(s, x);
91461
91462+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91463+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
91464+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
91465+ if (s->ctor)
91466+ s->ctor(x);
91467+ }
91468+#endif
91469+
91470 redo:
91471 /*
91472 * Determine the currently cpus per cpu slab.
91473@@ -2661,7 +2669,7 @@ static int slub_min_objects;
91474 * Merge control. If this is set then no merging of slab caches will occur.
91475 * (Could be removed. This was introduced to pacify the merge skeptics.)
91476 */
91477-static int slub_nomerge;
91478+static int slub_nomerge = 1;
91479
91480 /*
91481 * Calculate the order of allocation given an slab object size.
91482@@ -2938,6 +2946,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
91483 s->inuse = size;
91484
91485 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
91486+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91487+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
91488+#endif
91489 s->ctor)) {
91490 /*
91491 * Relocate free pointer after the object if it is not
91492@@ -3283,6 +3294,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
91493 EXPORT_SYMBOL(__kmalloc_node);
91494 #endif
91495
91496+bool is_usercopy_object(const void *ptr)
91497+{
91498+ struct page *page;
91499+ struct kmem_cache *s;
91500+
91501+ if (ZERO_OR_NULL_PTR(ptr))
91502+ return false;
91503+
91504+ if (!slab_is_available())
91505+ return false;
91506+
91507+ if (!virt_addr_valid(ptr))
91508+ return false;
91509+
91510+ page = virt_to_head_page(ptr);
91511+
91512+ if (!PageSlab(page))
91513+ return false;
91514+
91515+ s = page->slab_cache;
91516+ return s->flags & SLAB_USERCOPY;
91517+}
91518+
91519+#ifdef CONFIG_PAX_USERCOPY
91520+const char *check_heap_object(const void *ptr, unsigned long n)
91521+{
91522+ struct page *page;
91523+ struct kmem_cache *s;
91524+ unsigned long offset;
91525+
91526+ if (ZERO_OR_NULL_PTR(ptr))
91527+ return "<null>";
91528+
91529+ if (!virt_addr_valid(ptr))
91530+ return NULL;
91531+
91532+ page = virt_to_head_page(ptr);
91533+
91534+ if (!PageSlab(page))
91535+ return NULL;
91536+
91537+ s = page->slab_cache;
91538+ if (!(s->flags & SLAB_USERCOPY))
91539+ return s->name;
91540+
91541+ offset = (ptr - page_address(page)) % s->size;
91542+ if (offset <= s->object_size && n <= s->object_size - offset)
91543+ return NULL;
91544+
91545+ return s->name;
91546+}
91547+#endif
91548+
91549 size_t ksize(const void *object)
91550 {
91551 struct page *page;
91552@@ -3347,6 +3411,7 @@ void kfree(const void *x)
91553 if (unlikely(ZERO_OR_NULL_PTR(x)))
91554 return;
91555
91556+ VM_BUG_ON(!virt_addr_valid(x));
91557 page = virt_to_head_page(x);
91558 if (unlikely(!PageSlab(page))) {
91559 BUG_ON(!PageCompound(page));
91560@@ -3652,7 +3717,7 @@ static int slab_unmergeable(struct kmem_cache *s)
91561 /*
91562 * We may have set a slab to be unmergeable during bootstrap.
91563 */
91564- if (s->refcount < 0)
91565+ if (atomic_read(&s->refcount) < 0)
91566 return 1;
91567
91568 return 0;
91569@@ -3710,7 +3775,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
91570
91571 s = find_mergeable(memcg, size, align, flags, name, ctor);
91572 if (s) {
91573- s->refcount++;
91574+ atomic_inc(&s->refcount);
91575 /*
91576 * Adjust the object sizes so that we clear
91577 * the complete object on kzalloc.
91578@@ -3719,7 +3784,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
91579 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
91580
91581 if (sysfs_slab_alias(s, name)) {
91582- s->refcount--;
91583+ atomic_dec(&s->refcount);
91584 s = NULL;
91585 }
91586 }
91587@@ -3781,7 +3846,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
91588 return NOTIFY_OK;
91589 }
91590
91591-static struct notifier_block __cpuinitdata slab_notifier = {
91592+static struct notifier_block slab_notifier = {
91593 .notifier_call = slab_cpuup_callback
91594 };
91595
91596@@ -3839,7 +3904,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
91597 }
91598 #endif
91599
91600-#ifdef CONFIG_SYSFS
91601+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91602 static int count_inuse(struct page *page)
91603 {
91604 return page->inuse;
91605@@ -4226,12 +4291,12 @@ static void resiliency_test(void)
91606 validate_slab_cache(kmalloc_caches[9]);
91607 }
91608 #else
91609-#ifdef CONFIG_SYSFS
91610+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91611 static void resiliency_test(void) {};
91612 #endif
91613 #endif
91614
91615-#ifdef CONFIG_SYSFS
91616+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91617 enum slab_stat_type {
91618 SL_ALL, /* All slabs */
91619 SL_PARTIAL, /* Only partially allocated slabs */
91620@@ -4475,7 +4540,7 @@ SLAB_ATTR_RO(ctor);
91621
91622 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
91623 {
91624- return sprintf(buf, "%d\n", s->refcount - 1);
91625+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
91626 }
91627 SLAB_ATTR_RO(aliases);
91628
91629@@ -4563,6 +4628,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
91630 SLAB_ATTR_RO(cache_dma);
91631 #endif
91632
91633+#ifdef CONFIG_PAX_USERCOPY_SLABS
91634+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
91635+{
91636+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
91637+}
91638+SLAB_ATTR_RO(usercopy);
91639+#endif
91640+
91641 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
91642 {
91643 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
91644@@ -4897,6 +4970,9 @@ static struct attribute *slab_attrs[] = {
91645 #ifdef CONFIG_ZONE_DMA
91646 &cache_dma_attr.attr,
91647 #endif
91648+#ifdef CONFIG_PAX_USERCOPY_SLABS
91649+ &usercopy_attr.attr,
91650+#endif
91651 #ifdef CONFIG_NUMA
91652 &remote_node_defrag_ratio_attr.attr,
91653 #endif
91654@@ -5128,6 +5204,7 @@ static char *create_unique_id(struct kmem_cache *s)
91655 return name;
91656 }
91657
91658+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91659 static int sysfs_slab_add(struct kmem_cache *s)
91660 {
91661 int err;
91662@@ -5151,7 +5228,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
91663 }
91664
91665 s->kobj.kset = slab_kset;
91666- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
91667+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
91668 if (err) {
91669 kobject_put(&s->kobj);
91670 return err;
91671@@ -5185,6 +5262,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
91672 kobject_del(&s->kobj);
91673 kobject_put(&s->kobj);
91674 }
91675+#endif
91676
91677 /*
91678 * Need to buffer aliases during bootup until sysfs becomes
91679@@ -5198,6 +5276,7 @@ struct saved_alias {
91680
91681 static struct saved_alias *alias_list;
91682
91683+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91684 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
91685 {
91686 struct saved_alias *al;
91687@@ -5220,6 +5299,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
91688 alias_list = al;
91689 return 0;
91690 }
91691+#endif
91692
91693 static int __init slab_sysfs_init(void)
91694 {
91695diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
91696index 27eeab3..7c3f7f2 100644
91697--- a/mm/sparse-vmemmap.c
91698+++ b/mm/sparse-vmemmap.c
91699@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
91700 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
91701 if (!p)
91702 return NULL;
91703- pud_populate(&init_mm, pud, p);
91704+ pud_populate_kernel(&init_mm, pud, p);
91705 }
91706 return pud;
91707 }
91708@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
91709 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
91710 if (!p)
91711 return NULL;
91712- pgd_populate(&init_mm, pgd, p);
91713+ pgd_populate_kernel(&init_mm, pgd, p);
91714 }
91715 return pgd;
91716 }
91717diff --git a/mm/sparse.c b/mm/sparse.c
91718index 1c91f0d3..485470a 100644
91719--- a/mm/sparse.c
91720+++ b/mm/sparse.c
91721@@ -761,7 +761,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
91722
91723 for (i = 0; i < PAGES_PER_SECTION; i++) {
91724 if (PageHWPoison(&memmap[i])) {
91725- atomic_long_sub(1, &num_poisoned_pages);
91726+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
91727 ClearPageHWPoison(&memmap[i]);
91728 }
91729 }
91730diff --git a/mm/swap.c b/mm/swap.c
91731index dfd7d71..ccdf688 100644
91732--- a/mm/swap.c
91733+++ b/mm/swap.c
91734@@ -31,6 +31,7 @@
91735 #include <linux/memcontrol.h>
91736 #include <linux/gfp.h>
91737 #include <linux/uio.h>
91738+#include <linux/hugetlb.h>
91739
91740 #include "internal.h"
91741
91742@@ -73,6 +74,8 @@ static void __put_compound_page(struct page *page)
91743
91744 __page_cache_release(page);
91745 dtor = get_compound_page_dtor(page);
91746+ if (!PageHuge(page))
91747+ BUG_ON(dtor != free_compound_page);
91748 (*dtor)(page);
91749 }
91750
91751diff --git a/mm/swapfile.c b/mm/swapfile.c
91752index 746af55b..7ac94ae 100644
91753--- a/mm/swapfile.c
91754+++ b/mm/swapfile.c
91755@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
91756
91757 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
91758 /* Activity counter to indicate that a swapon or swapoff has occurred */
91759-static atomic_t proc_poll_event = ATOMIC_INIT(0);
91760+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
91761
91762 static inline unsigned char swap_count(unsigned char ent)
91763 {
91764@@ -1684,7 +1684,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
91765 }
91766 filp_close(swap_file, NULL);
91767 err = 0;
91768- atomic_inc(&proc_poll_event);
91769+ atomic_inc_unchecked(&proc_poll_event);
91770 wake_up_interruptible(&proc_poll_wait);
91771
91772 out_dput:
91773@@ -1701,8 +1701,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
91774
91775 poll_wait(file, &proc_poll_wait, wait);
91776
91777- if (seq->poll_event != atomic_read(&proc_poll_event)) {
91778- seq->poll_event = atomic_read(&proc_poll_event);
91779+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
91780+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
91781 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
91782 }
91783
91784@@ -1800,7 +1800,7 @@ static int swaps_open(struct inode *inode, struct file *file)
91785 return ret;
91786
91787 seq = file->private_data;
91788- seq->poll_event = atomic_read(&proc_poll_event);
91789+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
91790 return 0;
91791 }
91792
91793@@ -2143,7 +2143,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
91794 (frontswap_map) ? "FS" : "");
91795
91796 mutex_unlock(&swapon_mutex);
91797- atomic_inc(&proc_poll_event);
91798+ atomic_inc_unchecked(&proc_poll_event);
91799 wake_up_interruptible(&proc_poll_wait);
91800
91801 if (S_ISREG(inode->i_mode))
91802diff --git a/mm/util.c b/mm/util.c
91803index ab1424d..7c5bd5a 100644
91804--- a/mm/util.c
91805+++ b/mm/util.c
91806@@ -294,6 +294,12 @@ done:
91807 void arch_pick_mmap_layout(struct mm_struct *mm)
91808 {
91809 mm->mmap_base = TASK_UNMAPPED_BASE;
91810+
91811+#ifdef CONFIG_PAX_RANDMMAP
91812+ if (mm->pax_flags & MF_PAX_RANDMMAP)
91813+ mm->mmap_base += mm->delta_mmap;
91814+#endif
91815+
91816 mm->get_unmapped_area = arch_get_unmapped_area;
91817 mm->unmap_area = arch_unmap_area;
91818 }
91819diff --git a/mm/vmalloc.c b/mm/vmalloc.c
91820index d365724..6cae7c2 100644
91821--- a/mm/vmalloc.c
91822+++ b/mm/vmalloc.c
91823@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
91824
91825 pte = pte_offset_kernel(pmd, addr);
91826 do {
91827- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
91828- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
91829+
91830+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91831+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
91832+ BUG_ON(!pte_exec(*pte));
91833+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
91834+ continue;
91835+ }
91836+#endif
91837+
91838+ {
91839+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
91840+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
91841+ }
91842 } while (pte++, addr += PAGE_SIZE, addr != end);
91843 }
91844
91845@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
91846 pte = pte_alloc_kernel(pmd, addr);
91847 if (!pte)
91848 return -ENOMEM;
91849+
91850+ pax_open_kernel();
91851 do {
91852 struct page *page = pages[*nr];
91853
91854- if (WARN_ON(!pte_none(*pte)))
91855+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91856+ if (pgprot_val(prot) & _PAGE_NX)
91857+#endif
91858+
91859+ if (!pte_none(*pte)) {
91860+ pax_close_kernel();
91861+ WARN_ON(1);
91862 return -EBUSY;
91863- if (WARN_ON(!page))
91864+ }
91865+ if (!page) {
91866+ pax_close_kernel();
91867+ WARN_ON(1);
91868 return -ENOMEM;
91869+ }
91870 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
91871 (*nr)++;
91872 } while (pte++, addr += PAGE_SIZE, addr != end);
91873+ pax_close_kernel();
91874 return 0;
91875 }
91876
91877@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
91878 pmd_t *pmd;
91879 unsigned long next;
91880
91881- pmd = pmd_alloc(&init_mm, pud, addr);
91882+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91883 if (!pmd)
91884 return -ENOMEM;
91885 do {
91886@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
91887 pud_t *pud;
91888 unsigned long next;
91889
91890- pud = pud_alloc(&init_mm, pgd, addr);
91891+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91892 if (!pud)
91893 return -ENOMEM;
91894 do {
91895@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
91896 if (addr >= MODULES_VADDR && addr < MODULES_END)
91897 return 1;
91898 #endif
91899+
91900+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91901+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
91902+ return 1;
91903+#endif
91904+
91905 return is_vmalloc_addr(x);
91906 }
91907
91908@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
91909
91910 if (!pgd_none(*pgd)) {
91911 pud_t *pud = pud_offset(pgd, addr);
91912+#ifdef CONFIG_X86
91913+ if (!pud_large(*pud))
91914+#endif
91915 if (!pud_none(*pud)) {
91916 pmd_t *pmd = pmd_offset(pud, addr);
91917+#ifdef CONFIG_X86
91918+ if (!pmd_large(*pmd))
91919+#endif
91920 if (!pmd_none(*pmd)) {
91921 pte_t *ptep, pte;
91922
91923@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
91924 * Allocate a region of KVA of the specified size and alignment, within the
91925 * vstart and vend.
91926 */
91927-static struct vmap_area *alloc_vmap_area(unsigned long size,
91928+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
91929 unsigned long align,
91930 unsigned long vstart, unsigned long vend,
91931 int node, gfp_t gfp_mask)
91932@@ -1337,6 +1373,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
91933 struct vm_struct *area;
91934
91935 BUG_ON(in_interrupt());
91936+
91937+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
91938+ if (flags & VM_KERNEXEC) {
91939+ if (start != VMALLOC_START || end != VMALLOC_END)
91940+ return NULL;
91941+ start = (unsigned long)MODULES_EXEC_VADDR;
91942+ end = (unsigned long)MODULES_EXEC_END;
91943+ }
91944+#endif
91945+
91946 if (flags & VM_IOREMAP) {
91947 int bit = fls(size);
91948
91949@@ -1581,6 +1627,11 @@ void *vmap(struct page **pages, unsigned int count,
91950 if (count > totalram_pages)
91951 return NULL;
91952
91953+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
91954+ if (!(pgprot_val(prot) & _PAGE_NX))
91955+ flags |= VM_KERNEXEC;
91956+#endif
91957+
91958 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
91959 __builtin_return_address(0));
91960 if (!area)
91961@@ -1682,6 +1733,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
91962 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
91963 goto fail;
91964
91965+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
91966+ if (!(pgprot_val(prot) & _PAGE_NX))
91967+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
91968+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
91969+ else
91970+#endif
91971+
91972 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
91973 start, end, node, gfp_mask, caller);
91974 if (!area)
91975@@ -1858,10 +1916,9 @@ EXPORT_SYMBOL(vzalloc_node);
91976 * For tight control over page level allocator and protection flags
91977 * use __vmalloc() instead.
91978 */
91979-
91980 void *vmalloc_exec(unsigned long size)
91981 {
91982- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
91983+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
91984 NUMA_NO_NODE, __builtin_return_address(0));
91985 }
91986
91987@@ -2168,6 +2225,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
91988 unsigned long uaddr = vma->vm_start;
91989 unsigned long usize = vma->vm_end - vma->vm_start;
91990
91991+ BUG_ON(vma->vm_mirror);
91992+
91993 if ((PAGE_SIZE-1) & (unsigned long)addr)
91994 return -EINVAL;
91995
91996@@ -2629,7 +2688,11 @@ static int s_show(struct seq_file *m, void *p)
91997 v->addr, v->addr + v->size, v->size);
91998
91999 if (v->caller)
92000+#ifdef CONFIG_GRKERNSEC_HIDESYM
92001+ seq_printf(m, " %pK", v->caller);
92002+#else
92003 seq_printf(m, " %pS", v->caller);
92004+#endif
92005
92006 if (v->nr_pages)
92007 seq_printf(m, " pages=%d", v->nr_pages);
92008diff --git a/mm/vmstat.c b/mm/vmstat.c
92009index f42745e..62f8346 100644
92010--- a/mm/vmstat.c
92011+++ b/mm/vmstat.c
92012@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
92013 *
92014 * vm_stat contains the global counters
92015 */
92016-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
92017+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
92018 EXPORT_SYMBOL(vm_stat);
92019
92020 #ifdef CONFIG_SMP
92021@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
92022 v = p->vm_stat_diff[i];
92023 p->vm_stat_diff[i] = 0;
92024 local_irq_restore(flags);
92025- atomic_long_add(v, &zone->vm_stat[i]);
92026+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
92027 global_diff[i] += v;
92028 #ifdef CONFIG_NUMA
92029 /* 3 seconds idle till flush */
92030@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
92031
92032 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
92033 if (global_diff[i])
92034- atomic_long_add(global_diff[i], &vm_stat[i]);
92035+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
92036 }
92037
92038 /*
92039@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
92040 if (pset->vm_stat_diff[i]) {
92041 int v = pset->vm_stat_diff[i];
92042 pset->vm_stat_diff[i] = 0;
92043- atomic_long_add(v, &zone->vm_stat[i]);
92044- atomic_long_add(v, &vm_stat[i]);
92045+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
92046+ atomic_long_add_unchecked(v, &vm_stat[i]);
92047 }
92048 }
92049 #endif
92050@@ -1226,7 +1226,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
92051 return NOTIFY_OK;
92052 }
92053
92054-static struct notifier_block __cpuinitdata vmstat_notifier =
92055+static struct notifier_block vmstat_notifier =
92056 { &vmstat_cpuup_callback, NULL, 0 };
92057 #endif
92058
92059@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
92060 start_cpu_timer(cpu);
92061 #endif
92062 #ifdef CONFIG_PROC_FS
92063- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
92064- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
92065- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
92066- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
92067+ {
92068+ mode_t gr_mode = S_IRUGO;
92069+#ifdef CONFIG_GRKERNSEC_PROC_ADD
92070+ gr_mode = S_IRUSR;
92071+#endif
92072+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
92073+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
92074+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
92075+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
92076+#else
92077+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
92078+#endif
92079+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
92080+ }
92081 #endif
92082 return 0;
92083 }
92084diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
92085index 9424f37..6aabf19 100644
92086--- a/net/8021q/vlan.c
92087+++ b/net/8021q/vlan.c
92088@@ -469,7 +469,7 @@ out:
92089 return NOTIFY_DONE;
92090 }
92091
92092-static struct notifier_block vlan_notifier_block __read_mostly = {
92093+static struct notifier_block vlan_notifier_block = {
92094 .notifier_call = vlan_device_event,
92095 };
92096
92097@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
92098 err = -EPERM;
92099 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
92100 break;
92101- if ((args.u.name_type >= 0) &&
92102- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
92103+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
92104 struct vlan_net *vn;
92105
92106 vn = net_generic(net, vlan_net_id);
92107diff --git a/net/9p/mod.c b/net/9p/mod.c
92108index 6ab36ae..6f1841b 100644
92109--- a/net/9p/mod.c
92110+++ b/net/9p/mod.c
92111@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
92112 void v9fs_register_trans(struct p9_trans_module *m)
92113 {
92114 spin_lock(&v9fs_trans_lock);
92115- list_add_tail(&m->list, &v9fs_trans_list);
92116+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
92117 spin_unlock(&v9fs_trans_lock);
92118 }
92119 EXPORT_SYMBOL(v9fs_register_trans);
92120@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
92121 void v9fs_unregister_trans(struct p9_trans_module *m)
92122 {
92123 spin_lock(&v9fs_trans_lock);
92124- list_del_init(&m->list);
92125+ pax_list_del_init((struct list_head *)&m->list);
92126 spin_unlock(&v9fs_trans_lock);
92127 }
92128 EXPORT_SYMBOL(v9fs_unregister_trans);
92129diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
92130index 02efb25..41541a9 100644
92131--- a/net/9p/trans_fd.c
92132+++ b/net/9p/trans_fd.c
92133@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
92134 oldfs = get_fs();
92135 set_fs(get_ds());
92136 /* The cast to a user pointer is valid due to the set_fs() */
92137- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
92138+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
92139 set_fs(oldfs);
92140
92141 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
92142diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
92143index 876fbe8..8bbea9f 100644
92144--- a/net/atm/atm_misc.c
92145+++ b/net/atm/atm_misc.c
92146@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
92147 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
92148 return 1;
92149 atm_return(vcc, truesize);
92150- atomic_inc(&vcc->stats->rx_drop);
92151+ atomic_inc_unchecked(&vcc->stats->rx_drop);
92152 return 0;
92153 }
92154 EXPORT_SYMBOL(atm_charge);
92155@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
92156 }
92157 }
92158 atm_return(vcc, guess);
92159- atomic_inc(&vcc->stats->rx_drop);
92160+ atomic_inc_unchecked(&vcc->stats->rx_drop);
92161 return NULL;
92162 }
92163 EXPORT_SYMBOL(atm_alloc_charge);
92164@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
92165
92166 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
92167 {
92168-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
92169+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
92170 __SONET_ITEMS
92171 #undef __HANDLE_ITEM
92172 }
92173@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
92174
92175 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
92176 {
92177-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
92178+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
92179 __SONET_ITEMS
92180 #undef __HANDLE_ITEM
92181 }
92182diff --git a/net/atm/lec.h b/net/atm/lec.h
92183index 4149db1..f2ab682 100644
92184--- a/net/atm/lec.h
92185+++ b/net/atm/lec.h
92186@@ -48,7 +48,7 @@ struct lane2_ops {
92187 const u8 *tlvs, u32 sizeoftlvs);
92188 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
92189 const u8 *tlvs, u32 sizeoftlvs);
92190-};
92191+} __no_const;
92192
92193 /*
92194 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
92195diff --git a/net/atm/proc.c b/net/atm/proc.c
92196index bbb6461..cf04016 100644
92197--- a/net/atm/proc.c
92198+++ b/net/atm/proc.c
92199@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
92200 const struct k_atm_aal_stats *stats)
92201 {
92202 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
92203- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
92204- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
92205- atomic_read(&stats->rx_drop));
92206+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
92207+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
92208+ atomic_read_unchecked(&stats->rx_drop));
92209 }
92210
92211 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
92212diff --git a/net/atm/resources.c b/net/atm/resources.c
92213index 0447d5d..3cf4728 100644
92214--- a/net/atm/resources.c
92215+++ b/net/atm/resources.c
92216@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
92217 static void copy_aal_stats(struct k_atm_aal_stats *from,
92218 struct atm_aal_stats *to)
92219 {
92220-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
92221+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
92222 __AAL_STAT_ITEMS
92223 #undef __HANDLE_ITEM
92224 }
92225@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
92226 static void subtract_aal_stats(struct k_atm_aal_stats *from,
92227 struct atm_aal_stats *to)
92228 {
92229-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
92230+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
92231 __AAL_STAT_ITEMS
92232 #undef __HANDLE_ITEM
92233 }
92234diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
92235index d5744b7..506bae3 100644
92236--- a/net/ax25/sysctl_net_ax25.c
92237+++ b/net/ax25/sysctl_net_ax25.c
92238@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
92239 {
92240 char path[sizeof("net/ax25/") + IFNAMSIZ];
92241 int k;
92242- struct ctl_table *table;
92243+ ctl_table_no_const *table;
92244
92245 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
92246 if (!table)
92247diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
92248index f680ee1..97e3542 100644
92249--- a/net/batman-adv/bat_iv_ogm.c
92250+++ b/net/batman-adv/bat_iv_ogm.c
92251@@ -79,7 +79,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
92252
92253 /* randomize initial seqno to avoid collision */
92254 get_random_bytes(&random_seqno, sizeof(random_seqno));
92255- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
92256+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
92257
92258 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
92259 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
92260@@ -627,9 +627,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
92261 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
92262
92263 /* change sequence number to network order */
92264- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
92265+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
92266 batadv_ogm_packet->seqno = htonl(seqno);
92267- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
92268+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
92269
92270 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
92271 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
92272@@ -1037,7 +1037,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
92273 return;
92274
92275 /* could be changed by schedule_own_packet() */
92276- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
92277+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
92278
92279 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
92280 has_directlink_flag = 1;
92281diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
92282index de27b31..7058bfe 100644
92283--- a/net/batman-adv/bridge_loop_avoidance.c
92284+++ b/net/batman-adv/bridge_loop_avoidance.c
92285@@ -1522,6 +1522,8 @@ out:
92286 * in these cases, the skb is further handled by this function and
92287 * returns 1, otherwise it returns 0 and the caller shall further
92288 * process the skb.
92289+ *
92290+ * This call might reallocate skb data.
92291 */
92292 int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid)
92293 {
92294diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
92295index f105219..7614af3 100644
92296--- a/net/batman-adv/gateway_client.c
92297+++ b/net/batman-adv/gateway_client.c
92298@@ -508,6 +508,7 @@ out:
92299 return 0;
92300 }
92301
92302+/* this call might reallocate skb data */
92303 static bool batadv_is_type_dhcprequest(struct sk_buff *skb, int header_len)
92304 {
92305 int ret = false;
92306@@ -568,6 +569,7 @@ out:
92307 return ret;
92308 }
92309
92310+/* this call might reallocate skb data */
92311 bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len)
92312 {
92313 struct ethhdr *ethhdr;
92314@@ -619,6 +621,12 @@ bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len)
92315
92316 if (!pskb_may_pull(skb, *header_len + sizeof(*udphdr)))
92317 return false;
92318+
92319+ /* skb->data might have been reallocated by pskb_may_pull() */
92320+ ethhdr = (struct ethhdr *)skb->data;
92321+ if (ntohs(ethhdr->h_proto) == ETH_P_8021Q)
92322+ ethhdr = (struct ethhdr *)(skb->data + VLAN_HLEN);
92323+
92324 udphdr = (struct udphdr *)(skb->data + *header_len);
92325 *header_len += sizeof(*udphdr);
92326
92327@@ -634,12 +642,14 @@ bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len)
92328 return true;
92329 }
92330
92331+/* this call might reallocate skb data */
92332 bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
92333- struct sk_buff *skb, struct ethhdr *ethhdr)
92334+ struct sk_buff *skb)
92335 {
92336 struct batadv_neigh_node *neigh_curr = NULL, *neigh_old = NULL;
92337 struct batadv_orig_node *orig_dst_node = NULL;
92338 struct batadv_gw_node *curr_gw = NULL;
92339+ struct ethhdr *ethhdr;
92340 bool ret, out_of_range = false;
92341 unsigned int header_len = 0;
92342 uint8_t curr_tq_avg;
92343@@ -648,6 +658,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
92344 if (!ret)
92345 goto out;
92346
92347+ ethhdr = (struct ethhdr *)skb->data;
92348 orig_dst_node = batadv_transtable_search(bat_priv, ethhdr->h_source,
92349 ethhdr->h_dest);
92350 if (!orig_dst_node)
92351diff --git a/net/batman-adv/gateway_client.h b/net/batman-adv/gateway_client.h
92352index 039902d..1037d75 100644
92353--- a/net/batman-adv/gateway_client.h
92354+++ b/net/batman-adv/gateway_client.h
92355@@ -34,7 +34,6 @@ void batadv_gw_node_delete(struct batadv_priv *bat_priv,
92356 void batadv_gw_node_purge(struct batadv_priv *bat_priv);
92357 int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset);
92358 bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len);
92359-bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
92360- struct sk_buff *skb, struct ethhdr *ethhdr);
92361+bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, struct sk_buff *skb);
92362
92363 #endif /* _NET_BATMAN_ADV_GATEWAY_CLIENT_H_ */
92364diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
92365index 522243a..b48c0ef 100644
92366--- a/net/batman-adv/hard-interface.c
92367+++ b/net/batman-adv/hard-interface.c
92368@@ -401,7 +401,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
92369 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
92370 dev_add_pack(&hard_iface->batman_adv_ptype);
92371
92372- atomic_set(&hard_iface->frag_seqno, 1);
92373+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
92374 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
92375 hard_iface->net_dev->name);
92376
92377@@ -550,7 +550,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
92378 /* This can't be called via a bat_priv callback because
92379 * we have no bat_priv yet.
92380 */
92381- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
92382+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
92383 hard_iface->bat_iv.ogm_buff = NULL;
92384
92385 return hard_iface;
92386diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
92387index 819dfb0..226bacd 100644
92388--- a/net/batman-adv/soft-interface.c
92389+++ b/net/batman-adv/soft-interface.c
92390@@ -180,6 +180,9 @@ static int batadv_interface_tx(struct sk_buff *skb,
92391 if (batadv_bla_tx(bat_priv, skb, vid))
92392 goto dropped;
92393
92394+ /* skb->data might have been reallocated by batadv_bla_tx() */
92395+ ethhdr = (struct ethhdr *)skb->data;
92396+
92397 /* Register the client MAC in the transtable */
92398 if (!is_multicast_ether_addr(ethhdr->h_source))
92399 batadv_tt_local_add(soft_iface, ethhdr->h_source, skb->skb_iif);
92400@@ -220,6 +223,10 @@ static int batadv_interface_tx(struct sk_buff *skb,
92401 default:
92402 break;
92403 }
92404+
92405+ /* reminder: ethhdr might have become unusable from here on
92406+ * (batadv_gw_is_dhcp_target() might have reallocated skb data)
92407+ */
92408 }
92409
92410 /* ethernet packet should be broadcasted */
92411@@ -253,7 +260,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
92412 primary_if->net_dev->dev_addr, ETH_ALEN);
92413
92414 /* set broadcast sequence number */
92415- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
92416+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
92417 bcast_packet->seqno = htonl(seqno);
92418
92419 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
92420@@ -266,7 +273,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
92421 /* unicast packet */
92422 } else {
92423 if (atomic_read(&bat_priv->gw_mode) != BATADV_GW_MODE_OFF) {
92424- ret = batadv_gw_out_of_range(bat_priv, skb, ethhdr);
92425+ ret = batadv_gw_out_of_range(bat_priv, skb);
92426 if (ret)
92427 goto dropped;
92428 }
92429@@ -472,7 +479,7 @@ static int batadv_softif_init_late(struct net_device *dev)
92430 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
92431
92432 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
92433- atomic_set(&bat_priv->bcast_seqno, 1);
92434+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
92435 atomic_set(&bat_priv->tt.vn, 0);
92436 atomic_set(&bat_priv->tt.local_changes, 0);
92437 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
92438diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
92439index aba8364..50fcbb8 100644
92440--- a/net/batman-adv/types.h
92441+++ b/net/batman-adv/types.h
92442@@ -51,7 +51,7 @@
92443 struct batadv_hard_iface_bat_iv {
92444 unsigned char *ogm_buff;
92445 int ogm_buff_len;
92446- atomic_t ogm_seqno;
92447+ atomic_unchecked_t ogm_seqno;
92448 };
92449
92450 /**
92451@@ -75,7 +75,7 @@ struct batadv_hard_iface {
92452 int16_t if_num;
92453 char if_status;
92454 struct net_device *net_dev;
92455- atomic_t frag_seqno;
92456+ atomic_unchecked_t frag_seqno;
92457 struct kobject *hardif_obj;
92458 atomic_t refcount;
92459 struct packet_type batman_adv_ptype;
92460@@ -558,7 +558,7 @@ struct batadv_priv {
92461 #ifdef CONFIG_BATMAN_ADV_DEBUG
92462 atomic_t log_level;
92463 #endif
92464- atomic_t bcast_seqno;
92465+ atomic_unchecked_t bcast_seqno;
92466 atomic_t bcast_queue_left;
92467 atomic_t batman_queue_left;
92468 char num_ifaces;
92469diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
92470index 0bb3b59..0e3052e 100644
92471--- a/net/batman-adv/unicast.c
92472+++ b/net/batman-adv/unicast.c
92473@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
92474 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
92475 frag2->flags = large_tail;
92476
92477- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
92478+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
92479 frag1->seqno = htons(seqno - 1);
92480 frag2->seqno = htons(seqno);
92481
92482@@ -326,7 +326,9 @@ static bool batadv_unicast_push_and_fill_skb(struct sk_buff *skb, int hdr_size,
92483 * @skb: the skb containing the payload to encapsulate
92484 * @orig_node: the destination node
92485 *
92486- * Returns false if the payload could not be encapsulated or true otherwise
92487+ * Returns false if the payload could not be encapsulated or true otherwise.
92488+ *
92489+ * This call might reallocate skb data.
92490 */
92491 static bool batadv_unicast_prepare_skb(struct sk_buff *skb,
92492 struct batadv_orig_node *orig_node)
92493@@ -343,7 +345,9 @@ static bool batadv_unicast_prepare_skb(struct sk_buff *skb,
92494 * @orig_node: the destination node
92495 * @packet_subtype: the batman 4addr packet subtype to use
92496 *
92497- * Returns false if the payload could not be encapsulated or true otherwise
92498+ * Returns false if the payload could not be encapsulated or true otherwise.
92499+ *
92500+ * This call might reallocate skb data.
92501 */
92502 bool batadv_unicast_4addr_prepare_skb(struct batadv_priv *bat_priv,
92503 struct sk_buff *skb,
92504@@ -401,7 +405,7 @@ int batadv_unicast_generic_send_skb(struct batadv_priv *bat_priv,
92505 struct batadv_neigh_node *neigh_node;
92506 int data_len = skb->len;
92507 int ret = NET_RX_DROP;
92508- unsigned int dev_mtu;
92509+ unsigned int dev_mtu, header_len;
92510
92511 /* get routing information */
92512 if (is_multicast_ether_addr(ethhdr->h_dest)) {
92513@@ -429,10 +433,12 @@ find_router:
92514 switch (packet_type) {
92515 case BATADV_UNICAST:
92516 batadv_unicast_prepare_skb(skb, orig_node);
92517+ header_len = sizeof(struct batadv_unicast_packet);
92518 break;
92519 case BATADV_UNICAST_4ADDR:
92520 batadv_unicast_4addr_prepare_skb(bat_priv, skb, orig_node,
92521 packet_subtype);
92522+ header_len = sizeof(struct batadv_unicast_4addr_packet);
92523 break;
92524 default:
92525 /* this function supports UNICAST and UNICAST_4ADDR only. It
92526@@ -441,6 +447,7 @@ find_router:
92527 goto out;
92528 }
92529
92530+ ethhdr = (struct ethhdr *)(skb->data + header_len);
92531 unicast_packet = (struct batadv_unicast_packet *)skb->data;
92532
92533 /* inform the destination node that we are still missing a correct route
92534diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
92535index ace5e55..a65a1c0 100644
92536--- a/net/bluetooth/hci_core.c
92537+++ b/net/bluetooth/hci_core.c
92538@@ -2211,16 +2211,16 @@ int hci_register_dev(struct hci_dev *hdev)
92539 list_add(&hdev->list, &hci_dev_list);
92540 write_unlock(&hci_dev_list_lock);
92541
92542- hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND |
92543- WQ_MEM_RECLAIM, 1);
92544+ hdev->workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
92545+ WQ_MEM_RECLAIM, 1, hdev->name);
92546 if (!hdev->workqueue) {
92547 error = -ENOMEM;
92548 goto err;
92549 }
92550
92551- hdev->req_workqueue = alloc_workqueue(hdev->name,
92552+ hdev->req_workqueue = alloc_workqueue("%s",
92553 WQ_HIGHPRI | WQ_UNBOUND |
92554- WQ_MEM_RECLAIM, 1);
92555+ WQ_MEM_RECLAIM, 1, hdev->name);
92556 if (!hdev->req_workqueue) {
92557 destroy_workqueue(hdev->workqueue);
92558 error = -ENOMEM;
92559diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
92560index 9bd7d95..6c4884f 100644
92561--- a/net/bluetooth/hci_sock.c
92562+++ b/net/bluetooth/hci_sock.c
92563@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
92564 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
92565 }
92566
92567- len = min_t(unsigned int, len, sizeof(uf));
92568+ len = min((size_t)len, sizeof(uf));
92569 if (copy_from_user(&uf, optval, len)) {
92570 err = -EFAULT;
92571 break;
92572diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
92573index 68843a2..30e9342 100644
92574--- a/net/bluetooth/l2cap_core.c
92575+++ b/net/bluetooth/l2cap_core.c
92576@@ -3507,8 +3507,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
92577 break;
92578
92579 case L2CAP_CONF_RFC:
92580- if (olen == sizeof(rfc))
92581- memcpy(&rfc, (void *)val, olen);
92582+ if (olen != sizeof(rfc))
92583+ break;
92584+
92585+ memcpy(&rfc, (void *)val, olen);
92586
92587 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
92588 rfc.mode != chan->mode)
92589diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
92590index 36fed40..be2eeb2 100644
92591--- a/net/bluetooth/l2cap_sock.c
92592+++ b/net/bluetooth/l2cap_sock.c
92593@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
92594 struct sock *sk = sock->sk;
92595 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
92596 struct l2cap_options opts;
92597- int len, err = 0;
92598+ int err = 0;
92599+ size_t len = optlen;
92600 u32 opt;
92601
92602 BT_DBG("sk %p", sk);
92603@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
92604 opts.max_tx = chan->max_tx;
92605 opts.txwin_size = chan->tx_win;
92606
92607- len = min_t(unsigned int, sizeof(opts), optlen);
92608+ len = min(sizeof(opts), len);
92609 if (copy_from_user((char *) &opts, optval, len)) {
92610 err = -EFAULT;
92611 break;
92612@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
92613 struct bt_security sec;
92614 struct bt_power pwr;
92615 struct l2cap_conn *conn;
92616- int len, err = 0;
92617+ int err = 0;
92618+ size_t len = optlen;
92619 u32 opt;
92620
92621 BT_DBG("sk %p", sk);
92622@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
92623
92624 sec.level = BT_SECURITY_LOW;
92625
92626- len = min_t(unsigned int, sizeof(sec), optlen);
92627+ len = min(sizeof(sec), len);
92628 if (copy_from_user((char *) &sec, optval, len)) {
92629 err = -EFAULT;
92630 break;
92631@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
92632
92633 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
92634
92635- len = min_t(unsigned int, sizeof(pwr), optlen);
92636+ len = min(sizeof(pwr), len);
92637 if (copy_from_user((char *) &pwr, optval, len)) {
92638 err = -EFAULT;
92639 break;
92640diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
92641index 30b3721..c1bd0a0 100644
92642--- a/net/bluetooth/rfcomm/sock.c
92643+++ b/net/bluetooth/rfcomm/sock.c
92644@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
92645 struct sock *sk = sock->sk;
92646 struct bt_security sec;
92647 int err = 0;
92648- size_t len;
92649+ size_t len = optlen;
92650 u32 opt;
92651
92652 BT_DBG("sk %p", sk);
92653@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
92654
92655 sec.level = BT_SECURITY_LOW;
92656
92657- len = min_t(unsigned int, sizeof(sec), optlen);
92658+ len = min(sizeof(sec), len);
92659 if (copy_from_user((char *) &sec, optval, len)) {
92660 err = -EFAULT;
92661 break;
92662diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
92663index b6e44ad..5b0d514 100644
92664--- a/net/bluetooth/rfcomm/tty.c
92665+++ b/net/bluetooth/rfcomm/tty.c
92666@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
92667 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
92668
92669 spin_lock_irqsave(&dev->port.lock, flags);
92670- if (dev->port.count > 0) {
92671+ if (atomic_read(&dev->port.count) > 0) {
92672 spin_unlock_irqrestore(&dev->port.lock, flags);
92673 return;
92674 }
92675@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
92676 return -ENODEV;
92677
92678 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
92679- dev->channel, dev->port.count);
92680+ dev->channel, atomic_read(&dev->port.count));
92681
92682 spin_lock_irqsave(&dev->port.lock, flags);
92683- if (++dev->port.count > 1) {
92684+ if (atomic_inc_return(&dev->port.count) > 1) {
92685 spin_unlock_irqrestore(&dev->port.lock, flags);
92686 return 0;
92687 }
92688@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
92689 return;
92690
92691 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
92692- dev->port.count);
92693+ atomic_read(&dev->port.count));
92694
92695 spin_lock_irqsave(&dev->port.lock, flags);
92696- if (!--dev->port.count) {
92697+ if (!atomic_dec_return(&dev->port.count)) {
92698 spin_unlock_irqrestore(&dev->port.lock, flags);
92699 if (dev->tty_dev->parent)
92700 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
92701diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
92702index 3d110c4..4e1b2eb 100644
92703--- a/net/bridge/netfilter/ebtables.c
92704+++ b/net/bridge/netfilter/ebtables.c
92705@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92706 tmp.valid_hooks = t->table->valid_hooks;
92707 }
92708 mutex_unlock(&ebt_mutex);
92709- if (copy_to_user(user, &tmp, *len) != 0){
92710+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
92711 BUGPRINT("c2u Didn't work\n");
92712 ret = -EFAULT;
92713 break;
92714@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
92715 goto out;
92716 tmp.valid_hooks = t->valid_hooks;
92717
92718- if (copy_to_user(user, &tmp, *len) != 0) {
92719+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
92720 ret = -EFAULT;
92721 break;
92722 }
92723@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
92724 tmp.entries_size = t->table->entries_size;
92725 tmp.valid_hooks = t->table->valid_hooks;
92726
92727- if (copy_to_user(user, &tmp, *len) != 0) {
92728+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
92729 ret = -EFAULT;
92730 break;
92731 }
92732diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
92733index 2bd4b58..0dc30a1 100644
92734--- a/net/caif/cfctrl.c
92735+++ b/net/caif/cfctrl.c
92736@@ -10,6 +10,7 @@
92737 #include <linux/spinlock.h>
92738 #include <linux/slab.h>
92739 #include <linux/pkt_sched.h>
92740+#include <linux/sched.h>
92741 #include <net/caif/caif_layer.h>
92742 #include <net/caif/cfpkt.h>
92743 #include <net/caif/cfctrl.h>
92744@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
92745 memset(&dev_info, 0, sizeof(dev_info));
92746 dev_info.id = 0xff;
92747 cfsrvl_init(&this->serv, 0, &dev_info, false);
92748- atomic_set(&this->req_seq_no, 1);
92749- atomic_set(&this->rsp_seq_no, 1);
92750+ atomic_set_unchecked(&this->req_seq_no, 1);
92751+ atomic_set_unchecked(&this->rsp_seq_no, 1);
92752 this->serv.layer.receive = cfctrl_recv;
92753 sprintf(this->serv.layer.name, "ctrl");
92754 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
92755@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
92756 struct cfctrl_request_info *req)
92757 {
92758 spin_lock_bh(&ctrl->info_list_lock);
92759- atomic_inc(&ctrl->req_seq_no);
92760- req->sequence_no = atomic_read(&ctrl->req_seq_no);
92761+ atomic_inc_unchecked(&ctrl->req_seq_no);
92762+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
92763 list_add_tail(&req->list, &ctrl->list);
92764 spin_unlock_bh(&ctrl->info_list_lock);
92765 }
92766@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
92767 if (p != first)
92768 pr_warn("Requests are not received in order\n");
92769
92770- atomic_set(&ctrl->rsp_seq_no,
92771+ atomic_set_unchecked(&ctrl->rsp_seq_no,
92772 p->sequence_no);
92773 list_del(&p->list);
92774 goto out;
92775diff --git a/net/can/af_can.c b/net/can/af_can.c
92776index c4e5085..aa9efdf 100644
92777--- a/net/can/af_can.c
92778+++ b/net/can/af_can.c
92779@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
92780 };
92781
92782 /* notifier block for netdevice event */
92783-static struct notifier_block can_netdev_notifier __read_mostly = {
92784+static struct notifier_block can_netdev_notifier = {
92785 .notifier_call = can_notifier,
92786 };
92787
92788diff --git a/net/can/gw.c b/net/can/gw.c
92789index 3ee690e..00d581b 100644
92790--- a/net/can/gw.c
92791+++ b/net/can/gw.c
92792@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
92793 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
92794
92795 static HLIST_HEAD(cgw_list);
92796-static struct notifier_block notifier;
92797
92798 static struct kmem_cache *cgw_cache __read_mostly;
92799
92800@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
92801 return err;
92802 }
92803
92804+static struct notifier_block notifier = {
92805+ .notifier_call = cgw_notifier
92806+};
92807+
92808 static __init int cgw_module_init(void)
92809 {
92810 /* sanitize given module parameter */
92811@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
92812 return -ENOMEM;
92813
92814 /* set notifier */
92815- notifier.notifier_call = cgw_notifier;
92816 register_netdevice_notifier(&notifier);
92817
92818 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
92819diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
92820index eb0a46a..5f3bae8 100644
92821--- a/net/ceph/messenger.c
92822+++ b/net/ceph/messenger.c
92823@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
92824 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
92825
92826 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
92827-static atomic_t addr_str_seq = ATOMIC_INIT(0);
92828+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
92829
92830 static struct page *zero_page; /* used in certain error cases */
92831
92832@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
92833 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
92834 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
92835
92836- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
92837+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
92838 s = addr_str[i];
92839
92840 switch (ss->ss_family) {
92841diff --git a/net/compat.c b/net/compat.c
92842index f0a1ba6..0541331 100644
92843--- a/net/compat.c
92844+++ b/net/compat.c
92845@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
92846 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
92847 __get_user(kmsg->msg_flags, &umsg->msg_flags))
92848 return -EFAULT;
92849- kmsg->msg_name = compat_ptr(tmp1);
92850- kmsg->msg_iov = compat_ptr(tmp2);
92851- kmsg->msg_control = compat_ptr(tmp3);
92852+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
92853+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
92854+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
92855 return 0;
92856 }
92857
92858@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
92859
92860 if (kern_msg->msg_namelen) {
92861 if (mode == VERIFY_READ) {
92862- int err = move_addr_to_kernel(kern_msg->msg_name,
92863+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
92864 kern_msg->msg_namelen,
92865 kern_address);
92866 if (err < 0)
92867@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
92868 kern_msg->msg_name = NULL;
92869
92870 tot_len = iov_from_user_compat_to_kern(kern_iov,
92871- (struct compat_iovec __user *)kern_msg->msg_iov,
92872+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
92873 kern_msg->msg_iovlen);
92874 if (tot_len >= 0)
92875 kern_msg->msg_iov = kern_iov;
92876@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
92877
92878 #define CMSG_COMPAT_FIRSTHDR(msg) \
92879 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
92880- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
92881+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
92882 (struct compat_cmsghdr __user *)NULL)
92883
92884 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
92885 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
92886 (ucmlen) <= (unsigned long) \
92887 ((mhdr)->msg_controllen - \
92888- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
92889+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
92890
92891 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
92892 struct compat_cmsghdr __user *cmsg, int cmsg_len)
92893 {
92894 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
92895- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
92896+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
92897 msg->msg_controllen)
92898 return NULL;
92899 return (struct compat_cmsghdr __user *)ptr;
92900@@ -219,7 +219,7 @@ Efault:
92901
92902 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
92903 {
92904- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
92905+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
92906 struct compat_cmsghdr cmhdr;
92907 struct compat_timeval ctv;
92908 struct compat_timespec cts[3];
92909@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
92910
92911 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
92912 {
92913- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
92914+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
92915 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
92916 int fdnum = scm->fp->count;
92917 struct file **fp = scm->fp->fp;
92918@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
92919 return -EFAULT;
92920 old_fs = get_fs();
92921 set_fs(KERNEL_DS);
92922- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
92923+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
92924 set_fs(old_fs);
92925
92926 return err;
92927@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
92928 len = sizeof(ktime);
92929 old_fs = get_fs();
92930 set_fs(KERNEL_DS);
92931- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
92932+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
92933 set_fs(old_fs);
92934
92935 if (!err) {
92936@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
92937 case MCAST_JOIN_GROUP:
92938 case MCAST_LEAVE_GROUP:
92939 {
92940- struct compat_group_req __user *gr32 = (void *)optval;
92941+ struct compat_group_req __user *gr32 = (void __user *)optval;
92942 struct group_req __user *kgr =
92943 compat_alloc_user_space(sizeof(struct group_req));
92944 u32 interface;
92945@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
92946 case MCAST_BLOCK_SOURCE:
92947 case MCAST_UNBLOCK_SOURCE:
92948 {
92949- struct compat_group_source_req __user *gsr32 = (void *)optval;
92950+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
92951 struct group_source_req __user *kgsr = compat_alloc_user_space(
92952 sizeof(struct group_source_req));
92953 u32 interface;
92954@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
92955 }
92956 case MCAST_MSFILTER:
92957 {
92958- struct compat_group_filter __user *gf32 = (void *)optval;
92959+ struct compat_group_filter __user *gf32 = (void __user *)optval;
92960 struct group_filter __user *kgf;
92961 u32 interface, fmode, numsrc;
92962
92963@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
92964 char __user *optval, int __user *optlen,
92965 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
92966 {
92967- struct compat_group_filter __user *gf32 = (void *)optval;
92968+ struct compat_group_filter __user *gf32 = (void __user *)optval;
92969 struct group_filter __user *kgf;
92970 int __user *koptlen;
92971 u32 interface, fmode, numsrc;
92972@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
92973
92974 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
92975 return -EINVAL;
92976- if (copy_from_user(a, args, nas[call]))
92977+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
92978 return -EFAULT;
92979 a0 = a[0];
92980 a1 = a[1];
92981diff --git a/net/core/datagram.c b/net/core/datagram.c
92982index b71423d..0360434 100644
92983--- a/net/core/datagram.c
92984+++ b/net/core/datagram.c
92985@@ -295,7 +295,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
92986 }
92987
92988 kfree_skb(skb);
92989- atomic_inc(&sk->sk_drops);
92990+ atomic_inc_unchecked(&sk->sk_drops);
92991 sk_mem_reclaim_partial(sk);
92992
92993 return err;
92994diff --git a/net/core/dev.c b/net/core/dev.c
92995index 7ddbb31..3902452 100644
92996--- a/net/core/dev.c
92997+++ b/net/core/dev.c
92998@@ -1649,7 +1649,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
92999 {
93000 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
93001 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
93002- atomic_long_inc(&dev->rx_dropped);
93003+ atomic_long_inc_unchecked(&dev->rx_dropped);
93004 kfree_skb(skb);
93005 return NET_RX_DROP;
93006 }
93007@@ -1658,7 +1658,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
93008 skb_orphan(skb);
93009
93010 if (unlikely(!is_skb_forwardable(dev, skb))) {
93011- atomic_long_inc(&dev->rx_dropped);
93012+ atomic_long_inc_unchecked(&dev->rx_dropped);
93013 kfree_skb(skb);
93014 return NET_RX_DROP;
93015 }
93016@@ -2404,7 +2404,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
93017
93018 struct dev_gso_cb {
93019 void (*destructor)(struct sk_buff *skb);
93020-};
93021+} __no_const;
93022
93023 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
93024
93025@@ -3139,7 +3139,7 @@ enqueue:
93026
93027 local_irq_restore(flags);
93028
93029- atomic_long_inc(&skb->dev->rx_dropped);
93030+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
93031 kfree_skb(skb);
93032 return NET_RX_DROP;
93033 }
93034@@ -3211,7 +3211,7 @@ int netif_rx_ni(struct sk_buff *skb)
93035 }
93036 EXPORT_SYMBOL(netif_rx_ni);
93037
93038-static void net_tx_action(struct softirq_action *h)
93039+static void net_tx_action(void)
93040 {
93041 struct softnet_data *sd = &__get_cpu_var(softnet_data);
93042
93043@@ -3545,7 +3545,7 @@ ncls:
93044 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
93045 } else {
93046 drop:
93047- atomic_long_inc(&skb->dev->rx_dropped);
93048+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
93049 kfree_skb(skb);
93050 /* Jamal, now you will not able to escape explaining
93051 * me how you were going to use this. :-)
93052@@ -4153,7 +4153,7 @@ void netif_napi_del(struct napi_struct *napi)
93053 }
93054 EXPORT_SYMBOL(netif_napi_del);
93055
93056-static void net_rx_action(struct softirq_action *h)
93057+static void net_rx_action(void)
93058 {
93059 struct softnet_data *sd = &__get_cpu_var(softnet_data);
93060 unsigned long time_limit = jiffies + 2;
93061@@ -5590,7 +5590,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
93062 } else {
93063 netdev_stats_to_stats64(storage, &dev->stats);
93064 }
93065- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
93066+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
93067 return storage;
93068 }
93069 EXPORT_SYMBOL(dev_get_stats);
93070diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
93071index 5b7d0e1..cb960fc 100644
93072--- a/net/core/dev_ioctl.c
93073+++ b/net/core/dev_ioctl.c
93074@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
93075 if (no_module && capable(CAP_NET_ADMIN))
93076 no_module = request_module("netdev-%s", name);
93077 if (no_module && capable(CAP_SYS_MODULE)) {
93078+#ifdef CONFIG_GRKERNSEC_MODHARDEN
93079+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
93080+#else
93081 if (!request_module("%s", name))
93082 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
93083 name);
93084+#endif
93085 }
93086 }
93087 EXPORT_SYMBOL(dev_load);
93088diff --git a/net/core/ethtool.c b/net/core/ethtool.c
93089index ce91766..3b71cdb 100644
93090--- a/net/core/ethtool.c
93091+++ b/net/core/ethtool.c
93092@@ -1319,10 +1319,19 @@ static int ethtool_get_dump_data(struct net_device *dev,
93093 if (ret)
93094 return ret;
93095
93096- len = (tmp.len > dump.len) ? dump.len : tmp.len;
93097+ len = min(tmp.len, dump.len);
93098 if (!len)
93099 return -EFAULT;
93100
93101+ /* Don't ever let the driver think there's more space available
93102+ * than it requested with .get_dump_flag().
93103+ */
93104+ dump.len = len;
93105+
93106+ /* Always allocate enough space to hold the whole thing so that the
93107+ * driver does not need to check the length and bother with partial
93108+ * dumping.
93109+ */
93110 data = vzalloc(tmp.len);
93111 if (!data)
93112 return -ENOMEM;
93113@@ -1330,6 +1339,16 @@ static int ethtool_get_dump_data(struct net_device *dev,
93114 if (ret)
93115 goto out;
93116
93117+ /* There are two sane possibilities:
93118+ * 1. The driver's .get_dump_data() does not touch dump.len.
93119+ * 2. Or it may set dump.len to how much it really writes, which
93120+ * should be tmp.len (or len if it can do a partial dump).
93121+ * In any case respond to userspace with the actual length of data
93122+ * it's receiving.
93123+ */
93124+ WARN_ON(dump.len != len && dump.len != tmp.len);
93125+ dump.len = len;
93126+
93127 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
93128 ret = -EFAULT;
93129 goto out;
93130diff --git a/net/core/flow.c b/net/core/flow.c
93131index 7102f16..146b4bd 100644
93132--- a/net/core/flow.c
93133+++ b/net/core/flow.c
93134@@ -61,7 +61,7 @@ struct flow_cache {
93135 struct timer_list rnd_timer;
93136 };
93137
93138-atomic_t flow_cache_genid = ATOMIC_INIT(0);
93139+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
93140 EXPORT_SYMBOL(flow_cache_genid);
93141 static struct flow_cache flow_cache_global;
93142 static struct kmem_cache *flow_cachep __read_mostly;
93143@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
93144
93145 static int flow_entry_valid(struct flow_cache_entry *fle)
93146 {
93147- if (atomic_read(&flow_cache_genid) != fle->genid)
93148+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
93149 return 0;
93150 if (fle->object && !fle->object->ops->check(fle->object))
93151 return 0;
93152@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
93153 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
93154 fcp->hash_count++;
93155 }
93156- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
93157+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
93158 flo = fle->object;
93159 if (!flo)
93160 goto ret_object;
93161@@ -279,7 +279,7 @@ nocache:
93162 }
93163 flo = resolver(net, key, family, dir, flo, ctx);
93164 if (fle) {
93165- fle->genid = atomic_read(&flow_cache_genid);
93166+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
93167 if (!IS_ERR(flo))
93168 fle->object = flo;
93169 else
93170diff --git a/net/core/iovec.c b/net/core/iovec.c
93171index de178e4..1dabd8b 100644
93172--- a/net/core/iovec.c
93173+++ b/net/core/iovec.c
93174@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
93175 if (m->msg_namelen) {
93176 if (mode == VERIFY_READ) {
93177 void __user *namep;
93178- namep = (void __user __force *) m->msg_name;
93179+ namep = (void __force_user *) m->msg_name;
93180 err = move_addr_to_kernel(namep, m->msg_namelen,
93181 address);
93182 if (err < 0)
93183@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
93184 }
93185
93186 size = m->msg_iovlen * sizeof(struct iovec);
93187- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
93188+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
93189 return -EFAULT;
93190
93191 m->msg_iov = iov;
93192diff --git a/net/core/neighbour.c b/net/core/neighbour.c
93193index ce90b02..8752627 100644
93194--- a/net/core/neighbour.c
93195+++ b/net/core/neighbour.c
93196@@ -2771,7 +2771,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
93197 size_t *lenp, loff_t *ppos)
93198 {
93199 int size, ret;
93200- ctl_table tmp = *ctl;
93201+ ctl_table_no_const tmp = *ctl;
93202
93203 tmp.extra1 = &zero;
93204 tmp.extra2 = &unres_qlen_max;
93205diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
93206index 569d355..79cf2d0 100644
93207--- a/net/core/net-procfs.c
93208+++ b/net/core/net-procfs.c
93209@@ -271,8 +271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
93210 else
93211 seq_printf(seq, "%04x", ntohs(pt->type));
93212
93213+#ifdef CONFIG_GRKERNSEC_HIDESYM
93214+ seq_printf(seq, " %-8s %pf\n",
93215+ pt->dev ? pt->dev->name : "", NULL);
93216+#else
93217 seq_printf(seq, " %-8s %pf\n",
93218 pt->dev ? pt->dev->name : "", pt->func);
93219+#endif
93220 }
93221
93222 return 0;
93223diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
93224index 981fed3..536af34 100644
93225--- a/net/core/net-sysfs.c
93226+++ b/net/core/net-sysfs.c
93227@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
93228 }
93229 EXPORT_SYMBOL(netdev_class_remove_file);
93230
93231-int netdev_kobject_init(void)
93232+int __init netdev_kobject_init(void)
93233 {
93234 kobj_ns_type_register(&net_ns_type_operations);
93235 return class_register(&net_class);
93236diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
93237index f9765203..9feaef8 100644
93238--- a/net/core/net_namespace.c
93239+++ b/net/core/net_namespace.c
93240@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
93241 int error;
93242 LIST_HEAD(net_exit_list);
93243
93244- list_add_tail(&ops->list, list);
93245+ pax_list_add_tail((struct list_head *)&ops->list, list);
93246 if (ops->init || (ops->id && ops->size)) {
93247 for_each_net(net) {
93248 error = ops_init(ops, net);
93249@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
93250
93251 out_undo:
93252 /* If I have an error cleanup all namespaces I initialized */
93253- list_del(&ops->list);
93254+ pax_list_del((struct list_head *)&ops->list);
93255 ops_exit_list(ops, &net_exit_list);
93256 ops_free_list(ops, &net_exit_list);
93257 return error;
93258@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
93259 struct net *net;
93260 LIST_HEAD(net_exit_list);
93261
93262- list_del(&ops->list);
93263+ pax_list_del((struct list_head *)&ops->list);
93264 for_each_net(net)
93265 list_add_tail(&net->exit_list, &net_exit_list);
93266 ops_exit_list(ops, &net_exit_list);
93267@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
93268 mutex_lock(&net_mutex);
93269 error = register_pernet_operations(&pernet_list, ops);
93270 if (!error && (first_device == &pernet_list))
93271- first_device = &ops->list;
93272+ first_device = (struct list_head *)&ops->list;
93273 mutex_unlock(&net_mutex);
93274 return error;
93275 }
93276diff --git a/net/core/netpoll.c b/net/core/netpoll.c
93277index cec074b..a53a938 100644
93278--- a/net/core/netpoll.c
93279+++ b/net/core/netpoll.c
93280@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
93281 struct udphdr *udph;
93282 struct iphdr *iph;
93283 struct ethhdr *eth;
93284- static atomic_t ip_ident;
93285+ static atomic_unchecked_t ip_ident;
93286 struct ipv6hdr *ip6h;
93287
93288 udp_len = len + sizeof(*udph);
93289@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
93290 put_unaligned(0x45, (unsigned char *)iph);
93291 iph->tos = 0;
93292 put_unaligned(htons(ip_len), &(iph->tot_len));
93293- iph->id = htons(atomic_inc_return(&ip_ident));
93294+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
93295 iph->frag_off = 0;
93296 iph->ttl = 64;
93297 iph->protocol = IPPROTO_UDP;
93298diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
93299index a08bd2b..c59bd7c 100644
93300--- a/net/core/rtnetlink.c
93301+++ b/net/core/rtnetlink.c
93302@@ -58,7 +58,7 @@ struct rtnl_link {
93303 rtnl_doit_func doit;
93304 rtnl_dumpit_func dumpit;
93305 rtnl_calcit_func calcit;
93306-};
93307+} __no_const;
93308
93309 static DEFINE_MUTEX(rtnl_mutex);
93310
93311@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
93312 if (rtnl_link_ops_get(ops->kind))
93313 return -EEXIST;
93314
93315- if (!ops->dellink)
93316- ops->dellink = unregister_netdevice_queue;
93317+ if (!ops->dellink) {
93318+ pax_open_kernel();
93319+ *(void **)&ops->dellink = unregister_netdevice_queue;
93320+ pax_close_kernel();
93321+ }
93322
93323- list_add_tail(&ops->list, &link_ops);
93324+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
93325 return 0;
93326 }
93327 EXPORT_SYMBOL_GPL(__rtnl_link_register);
93328@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
93329 for_each_net(net) {
93330 __rtnl_kill_links(net, ops);
93331 }
93332- list_del(&ops->list);
93333+ pax_list_del((struct list_head *)&ops->list);
93334 }
93335 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
93336
93337@@ -2374,7 +2377,7 @@ static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
93338 struct nlattr *extfilt;
93339 u32 filter_mask = 0;
93340
93341- extfilt = nlmsg_find_attr(cb->nlh, sizeof(struct rtgenmsg),
93342+ extfilt = nlmsg_find_attr(cb->nlh, sizeof(struct ifinfomsg),
93343 IFLA_EXT_MASK);
93344 if (extfilt)
93345 filter_mask = nla_get_u32(extfilt);
93346diff --git a/net/core/scm.c b/net/core/scm.c
93347index 03795d0..98d6bdb 100644
93348--- a/net/core/scm.c
93349+++ b/net/core/scm.c
93350@@ -54,7 +54,7 @@ static __inline__ int scm_check_creds(struct ucred *creds)
93351 return -EINVAL;
93352
93353 if ((creds->pid == task_tgid_vnr(current) ||
93354- ns_capable(current->nsproxy->pid_ns->user_ns, CAP_SYS_ADMIN)) &&
93355+ ns_capable(task_active_pid_ns(current)->user_ns, CAP_SYS_ADMIN)) &&
93356 ((uid_eq(uid, cred->uid) || uid_eq(uid, cred->euid) ||
93357 uid_eq(uid, cred->suid)) || nsown_capable(CAP_SETUID)) &&
93358 ((gid_eq(gid, cred->gid) || gid_eq(gid, cred->egid) ||
93359@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
93360 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
93361 {
93362 struct cmsghdr __user *cm
93363- = (__force struct cmsghdr __user *)msg->msg_control;
93364+ = (struct cmsghdr __force_user *)msg->msg_control;
93365 struct cmsghdr cmhdr;
93366 int cmlen = CMSG_LEN(len);
93367 int err;
93368@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
93369 err = -EFAULT;
93370 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
93371 goto out;
93372- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
93373+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
93374 goto out;
93375 cmlen = CMSG_SPACE(len);
93376 if (msg->msg_controllen < cmlen)
93377@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
93378 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
93379 {
93380 struct cmsghdr __user *cm
93381- = (__force struct cmsghdr __user*)msg->msg_control;
93382+ = (struct cmsghdr __force_user *)msg->msg_control;
93383
93384 int fdmax = 0;
93385 int fdnum = scm->fp->count;
93386@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
93387 if (fdnum < fdmax)
93388 fdmax = fdnum;
93389
93390- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
93391+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
93392 i++, cmfptr++)
93393 {
93394 struct socket *sock;
93395diff --git a/net/core/skbuff.c b/net/core/skbuff.c
93396index 1c1738c..4cab7f0 100644
93397--- a/net/core/skbuff.c
93398+++ b/net/core/skbuff.c
93399@@ -3087,13 +3087,15 @@ void __init skb_init(void)
93400 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
93401 sizeof(struct sk_buff),
93402 0,
93403- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
93404+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
93405+ SLAB_NO_SANITIZE,
93406 NULL);
93407 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
93408 (2*sizeof(struct sk_buff)) +
93409 sizeof(atomic_t),
93410 0,
93411- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
93412+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
93413+ SLAB_NO_SANITIZE,
93414 NULL);
93415 }
93416
93417diff --git a/net/core/sock.c b/net/core/sock.c
93418index d6d024c..6ea7ab4 100644
93419--- a/net/core/sock.c
93420+++ b/net/core/sock.c
93421@@ -390,7 +390,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
93422 struct sk_buff_head *list = &sk->sk_receive_queue;
93423
93424 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
93425- atomic_inc(&sk->sk_drops);
93426+ atomic_inc_unchecked(&sk->sk_drops);
93427 trace_sock_rcvqueue_full(sk, skb);
93428 return -ENOMEM;
93429 }
93430@@ -400,7 +400,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
93431 return err;
93432
93433 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
93434- atomic_inc(&sk->sk_drops);
93435+ atomic_inc_unchecked(&sk->sk_drops);
93436 return -ENOBUFS;
93437 }
93438
93439@@ -420,7 +420,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
93440 skb_dst_force(skb);
93441
93442 spin_lock_irqsave(&list->lock, flags);
93443- skb->dropcount = atomic_read(&sk->sk_drops);
93444+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
93445 __skb_queue_tail(list, skb);
93446 spin_unlock_irqrestore(&list->lock, flags);
93447
93448@@ -440,7 +440,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
93449 skb->dev = NULL;
93450
93451 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
93452- atomic_inc(&sk->sk_drops);
93453+ atomic_inc_unchecked(&sk->sk_drops);
93454 goto discard_and_relse;
93455 }
93456 if (nested)
93457@@ -458,7 +458,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
93458 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
93459 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
93460 bh_unlock_sock(sk);
93461- atomic_inc(&sk->sk_drops);
93462+ atomic_inc_unchecked(&sk->sk_drops);
93463 goto discard_and_relse;
93464 }
93465
93466@@ -933,12 +933,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
93467 struct timeval tm;
93468 } v;
93469
93470- int lv = sizeof(int);
93471- int len;
93472+ unsigned int lv = sizeof(int);
93473+ unsigned int len;
93474
93475 if (get_user(len, optlen))
93476 return -EFAULT;
93477- if (len < 0)
93478+ if (len > INT_MAX)
93479 return -EINVAL;
93480
93481 memset(&v, 0, sizeof(v));
93482@@ -1090,11 +1090,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
93483
93484 case SO_PEERNAME:
93485 {
93486- char address[128];
93487+ char address[_K_SS_MAXSIZE];
93488
93489 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
93490 return -ENOTCONN;
93491- if (lv < len)
93492+ if (lv < len || sizeof address < len)
93493 return -EINVAL;
93494 if (copy_to_user(optval, address, len))
93495 return -EFAULT;
93496@@ -1161,7 +1161,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
93497
93498 if (len > lv)
93499 len = lv;
93500- if (copy_to_user(optval, &v, len))
93501+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
93502 return -EFAULT;
93503 lenout:
93504 if (put_user(len, optlen))
93505@@ -2277,7 +2277,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
93506 */
93507 smp_wmb();
93508 atomic_set(&sk->sk_refcnt, 1);
93509- atomic_set(&sk->sk_drops, 0);
93510+ atomic_set_unchecked(&sk->sk_drops, 0);
93511 }
93512 EXPORT_SYMBOL(sock_init_data);
93513
93514diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
93515index a0e9cf6..ef7f9ed 100644
93516--- a/net/core/sock_diag.c
93517+++ b/net/core/sock_diag.c
93518@@ -9,26 +9,33 @@
93519 #include <linux/inet_diag.h>
93520 #include <linux/sock_diag.h>
93521
93522-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
93523+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
93524 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
93525 static DEFINE_MUTEX(sock_diag_table_mutex);
93526
93527 int sock_diag_check_cookie(void *sk, __u32 *cookie)
93528 {
93529+#ifndef CONFIG_GRKERNSEC_HIDESYM
93530 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
93531 cookie[1] != INET_DIAG_NOCOOKIE) &&
93532 ((u32)(unsigned long)sk != cookie[0] ||
93533 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
93534 return -ESTALE;
93535 else
93536+#endif
93537 return 0;
93538 }
93539 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
93540
93541 void sock_diag_save_cookie(void *sk, __u32 *cookie)
93542 {
93543+#ifdef CONFIG_GRKERNSEC_HIDESYM
93544+ cookie[0] = 0;
93545+ cookie[1] = 0;
93546+#else
93547 cookie[0] = (u32)(unsigned long)sk;
93548 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
93549+#endif
93550 }
93551 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
93552
93553@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
93554 mutex_lock(&sock_diag_table_mutex);
93555 if (sock_diag_handlers[hndl->family])
93556 err = -EBUSY;
93557- else
93558+ else {
93559+ pax_open_kernel();
93560 sock_diag_handlers[hndl->family] = hndl;
93561+ pax_close_kernel();
93562+ }
93563 mutex_unlock(&sock_diag_table_mutex);
93564
93565 return err;
93566@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
93567
93568 mutex_lock(&sock_diag_table_mutex);
93569 BUG_ON(sock_diag_handlers[family] != hnld);
93570+ pax_open_kernel();
93571 sock_diag_handlers[family] = NULL;
93572+ pax_close_kernel();
93573 mutex_unlock(&sock_diag_table_mutex);
93574 }
93575 EXPORT_SYMBOL_GPL(sock_diag_unregister);
93576diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
93577index cfdb46a..cef55e1 100644
93578--- a/net/core/sysctl_net_core.c
93579+++ b/net/core/sysctl_net_core.c
93580@@ -28,7 +28,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
93581 {
93582 unsigned int orig_size, size;
93583 int ret, i;
93584- ctl_table tmp = {
93585+ ctl_table_no_const tmp = {
93586 .data = &size,
93587 .maxlen = sizeof(size),
93588 .mode = table->mode
93589@@ -211,13 +211,12 @@ static struct ctl_table netns_core_table[] = {
93590
93591 static __net_init int sysctl_core_net_init(struct net *net)
93592 {
93593- struct ctl_table *tbl;
93594+ ctl_table_no_const *tbl = NULL;
93595
93596 net->core.sysctl_somaxconn = SOMAXCONN;
93597
93598- tbl = netns_core_table;
93599 if (!net_eq(net, &init_net)) {
93600- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
93601+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
93602 if (tbl == NULL)
93603 goto err_dup;
93604
93605@@ -227,17 +226,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
93606 if (net->user_ns != &init_user_ns) {
93607 tbl[0].procname = NULL;
93608 }
93609- }
93610-
93611- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
93612+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
93613+ } else
93614+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
93615 if (net->core.sysctl_hdr == NULL)
93616 goto err_reg;
93617
93618 return 0;
93619
93620 err_reg:
93621- if (tbl != netns_core_table)
93622- kfree(tbl);
93623+ kfree(tbl);
93624 err_dup:
93625 return -ENOMEM;
93626 }
93627@@ -252,7 +250,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
93628 kfree(tbl);
93629 }
93630
93631-static __net_initdata struct pernet_operations sysctl_core_ops = {
93632+static __net_initconst struct pernet_operations sysctl_core_ops = {
93633 .init = sysctl_core_net_init,
93634 .exit = sysctl_core_net_exit,
93635 };
93636diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
93637index c21f200..bc4565b 100644
93638--- a/net/decnet/af_decnet.c
93639+++ b/net/decnet/af_decnet.c
93640@@ -465,6 +465,7 @@ static struct proto dn_proto = {
93641 .sysctl_rmem = sysctl_decnet_rmem,
93642 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
93643 .obj_size = sizeof(struct dn_sock),
93644+ .slab_flags = SLAB_USERCOPY,
93645 };
93646
93647 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
93648diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
93649index a55eecc..dd8428c 100644
93650--- a/net/decnet/sysctl_net_decnet.c
93651+++ b/net/decnet/sysctl_net_decnet.c
93652@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
93653
93654 if (len > *lenp) len = *lenp;
93655
93656- if (copy_to_user(buffer, addr, len))
93657+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
93658 return -EFAULT;
93659
93660 *lenp = len;
93661@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
93662
93663 if (len > *lenp) len = *lenp;
93664
93665- if (copy_to_user(buffer, devname, len))
93666+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
93667 return -EFAULT;
93668
93669 *lenp = len;
93670diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
93671index 55e1fd5..fd602b8 100644
93672--- a/net/ieee802154/6lowpan.c
93673+++ b/net/ieee802154/6lowpan.c
93674@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
93675 hc06_ptr += 3;
93676 } else {
93677 /* compress nothing */
93678- memcpy(hc06_ptr, &hdr, 4);
93679+ memcpy(hc06_ptr, hdr, 4);
93680 /* replace the top byte with new ECN | DSCP format */
93681 *hc06_ptr = tmp;
93682 hc06_ptr += 4;
93683diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
93684index d01be2a..8976537 100644
93685--- a/net/ipv4/af_inet.c
93686+++ b/net/ipv4/af_inet.c
93687@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
93688
93689 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
93690
93691- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
93692- if (!sysctl_local_reserved_ports)
93693- goto out;
93694-
93695 rc = proto_register(&tcp_prot, 1);
93696 if (rc)
93697- goto out_free_reserved_ports;
93698+ goto out;
93699
93700 rc = proto_register(&udp_prot, 1);
93701 if (rc)
93702@@ -1818,8 +1814,6 @@ out_unregister_udp_proto:
93703 proto_unregister(&udp_prot);
93704 out_unregister_tcp_proto:
93705 proto_unregister(&tcp_prot);
93706-out_free_reserved_ports:
93707- kfree(sysctl_local_reserved_ports);
93708 goto out;
93709 }
93710
93711diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
93712index 2e7f194..0fa4d6d 100644
93713--- a/net/ipv4/ah4.c
93714+++ b/net/ipv4/ah4.c
93715@@ -420,7 +420,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
93716 return;
93717
93718 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
93719- atomic_inc(&flow_cache_genid);
93720+ atomic_inc_unchecked(&flow_cache_genid);
93721 rt_genid_bump(net);
93722
93723 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
93724diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
93725index dfc39d4..0d4fa52 100644
93726--- a/net/ipv4/devinet.c
93727+++ b/net/ipv4/devinet.c
93728@@ -771,7 +771,7 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
93729 ci = nla_data(tb[IFA_CACHEINFO]);
93730 if (!ci->ifa_valid || ci->ifa_prefered > ci->ifa_valid) {
93731 err = -EINVAL;
93732- goto errout;
93733+ goto errout_free;
93734 }
93735 *pvalid_lft = ci->ifa_valid;
93736 *pprefered_lft = ci->ifa_prefered;
93737@@ -779,6 +779,8 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
93738
93739 return ifa;
93740
93741+errout_free:
93742+ inet_free_ifa(ifa);
93743 errout:
93744 return ERR_PTR(err);
93745 }
93746@@ -1529,7 +1531,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
93747 idx = 0;
93748 head = &net->dev_index_head[h];
93749 rcu_read_lock();
93750- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
93751+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
93752 net->dev_base_seq;
93753 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93754 if (idx < s_idx)
93755@@ -1840,7 +1842,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
93756 idx = 0;
93757 head = &net->dev_index_head[h];
93758 rcu_read_lock();
93759- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
93760+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
93761 net->dev_base_seq;
93762 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93763 if (idx < s_idx)
93764@@ -2065,7 +2067,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
93765 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
93766 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
93767
93768-static struct devinet_sysctl_table {
93769+static const struct devinet_sysctl_table {
93770 struct ctl_table_header *sysctl_header;
93771 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
93772 } devinet_sysctl = {
93773@@ -2183,7 +2185,7 @@ static __net_init int devinet_init_net(struct net *net)
93774 int err;
93775 struct ipv4_devconf *all, *dflt;
93776 #ifdef CONFIG_SYSCTL
93777- struct ctl_table *tbl = ctl_forward_entry;
93778+ ctl_table_no_const *tbl = NULL;
93779 struct ctl_table_header *forw_hdr;
93780 #endif
93781
93782@@ -2201,7 +2203,7 @@ static __net_init int devinet_init_net(struct net *net)
93783 goto err_alloc_dflt;
93784
93785 #ifdef CONFIG_SYSCTL
93786- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
93787+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
93788 if (tbl == NULL)
93789 goto err_alloc_ctl;
93790
93791@@ -2221,7 +2223,10 @@ static __net_init int devinet_init_net(struct net *net)
93792 goto err_reg_dflt;
93793
93794 err = -ENOMEM;
93795- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
93796+ if (!net_eq(net, &init_net))
93797+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
93798+ else
93799+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
93800 if (forw_hdr == NULL)
93801 goto err_reg_ctl;
93802 net->ipv4.forw_hdr = forw_hdr;
93803@@ -2237,8 +2242,7 @@ err_reg_ctl:
93804 err_reg_dflt:
93805 __devinet_sysctl_unregister(all);
93806 err_reg_all:
93807- if (tbl != ctl_forward_entry)
93808- kfree(tbl);
93809+ kfree(tbl);
93810 err_alloc_ctl:
93811 #endif
93812 if (dflt != &ipv4_devconf_dflt)
93813diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
93814index 4cfe34d..d2fac8a 100644
93815--- a/net/ipv4/esp4.c
93816+++ b/net/ipv4/esp4.c
93817@@ -477,7 +477,7 @@ static u32 esp4_get_mtu(struct xfrm_state *x, int mtu)
93818 }
93819
93820 return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) -
93821- net_adj) & ~(align - 1)) + (net_adj - 2);
93822+ net_adj) & ~(align - 1)) + net_adj - 2;
93823 }
93824
93825 static void esp4_err(struct sk_buff *skb, u32 info)
93826@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
93827 return;
93828
93829 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
93830- atomic_inc(&flow_cache_genid);
93831+ atomic_inc_unchecked(&flow_cache_genid);
93832 rt_genid_bump(net);
93833
93834 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
93835diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
93836index c7629a2..b62d139 100644
93837--- a/net/ipv4/fib_frontend.c
93838+++ b/net/ipv4/fib_frontend.c
93839@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
93840 #ifdef CONFIG_IP_ROUTE_MULTIPATH
93841 fib_sync_up(dev);
93842 #endif
93843- atomic_inc(&net->ipv4.dev_addr_genid);
93844+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
93845 rt_cache_flush(dev_net(dev));
93846 break;
93847 case NETDEV_DOWN:
93848 fib_del_ifaddr(ifa, NULL);
93849- atomic_inc(&net->ipv4.dev_addr_genid);
93850+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
93851 if (ifa->ifa_dev->ifa_list == NULL) {
93852 /* Last address was deleted from this interface.
93853 * Disable IP.
93854@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
93855 #ifdef CONFIG_IP_ROUTE_MULTIPATH
93856 fib_sync_up(dev);
93857 #endif
93858- atomic_inc(&net->ipv4.dev_addr_genid);
93859+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
93860 rt_cache_flush(net);
93861 break;
93862 case NETDEV_DOWN:
93863diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
93864index 8f6cb7a..34507f9 100644
93865--- a/net/ipv4/fib_semantics.c
93866+++ b/net/ipv4/fib_semantics.c
93867@@ -765,7 +765,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
93868 nh->nh_saddr = inet_select_addr(nh->nh_dev,
93869 nh->nh_gw,
93870 nh->nh_parent->fib_scope);
93871- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
93872+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
93873
93874 return nh->nh_saddr;
93875 }
93876diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
93877index 49616fe..6e8a13d 100644
93878--- a/net/ipv4/fib_trie.c
93879+++ b/net/ipv4/fib_trie.c
93880@@ -71,7 +71,6 @@
93881 #include <linux/init.h>
93882 #include <linux/list.h>
93883 #include <linux/slab.h>
93884-#include <linux/prefetch.h>
93885 #include <linux/export.h>
93886 #include <net/net_namespace.h>
93887 #include <net/ip.h>
93888@@ -1761,10 +1760,8 @@ static struct leaf *leaf_walk_rcu(struct tnode *p, struct rt_trie_node *c)
93889 if (!c)
93890 continue;
93891
93892- if (IS_LEAF(c)) {
93893- prefetch(rcu_dereference_rtnl(p->child[idx]));
93894+ if (IS_LEAF(c))
93895 return (struct leaf *) c;
93896- }
93897
93898 /* Rescan start scanning in new node */
93899 p = (struct tnode *) c;
93900diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
93901index 6acb541..9ea617d 100644
93902--- a/net/ipv4/inet_connection_sock.c
93903+++ b/net/ipv4/inet_connection_sock.c
93904@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
93905 .range = { 32768, 61000 },
93906 };
93907
93908-unsigned long *sysctl_local_reserved_ports;
93909+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
93910 EXPORT_SYMBOL(sysctl_local_reserved_ports);
93911
93912 void inet_get_local_port_range(int *low, int *high)
93913diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
93914index 6af375a..c493c74 100644
93915--- a/net/ipv4/inet_hashtables.c
93916+++ b/net/ipv4/inet_hashtables.c
93917@@ -18,12 +18,15 @@
93918 #include <linux/sched.h>
93919 #include <linux/slab.h>
93920 #include <linux/wait.h>
93921+#include <linux/security.h>
93922
93923 #include <net/inet_connection_sock.h>
93924 #include <net/inet_hashtables.h>
93925 #include <net/secure_seq.h>
93926 #include <net/ip.h>
93927
93928+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
93929+
93930 /*
93931 * Allocate and initialize a new local port bind bucket.
93932 * The bindhash mutex for snum's hash chain must be held here.
93933@@ -554,6 +557,8 @@ ok:
93934 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
93935 spin_unlock(&head->lock);
93936
93937+ gr_update_task_in_ip_table(current, inet_sk(sk));
93938+
93939 if (tw) {
93940 inet_twsk_deschedule(tw, death_row);
93941 while (twrefcnt) {
93942diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
93943index 000e3d2..5472da3 100644
93944--- a/net/ipv4/inetpeer.c
93945+++ b/net/ipv4/inetpeer.c
93946@@ -503,8 +503,8 @@ relookup:
93947 if (p) {
93948 p->daddr = *daddr;
93949 atomic_set(&p->refcnt, 1);
93950- atomic_set(&p->rid, 0);
93951- atomic_set(&p->ip_id_count,
93952+ atomic_set_unchecked(&p->rid, 0);
93953+ atomic_set_unchecked(&p->ip_id_count,
93954 (daddr->family == AF_INET) ?
93955 secure_ip_id(daddr->addr.a4) :
93956 secure_ipv6_id(daddr->addr.a6));
93957diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
93958index b66910a..cfe416e 100644
93959--- a/net/ipv4/ip_fragment.c
93960+++ b/net/ipv4/ip_fragment.c
93961@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
93962 return 0;
93963
93964 start = qp->rid;
93965- end = atomic_inc_return(&peer->rid);
93966+ end = atomic_inc_return_unchecked(&peer->rid);
93967 qp->rid = end;
93968
93969 rc = qp->q.fragments && (end - start) > max;
93970@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
93971
93972 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
93973 {
93974- struct ctl_table *table;
93975+ ctl_table_no_const *table = NULL;
93976 struct ctl_table_header *hdr;
93977
93978- table = ip4_frags_ns_ctl_table;
93979 if (!net_eq(net, &init_net)) {
93980- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
93981+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
93982 if (table == NULL)
93983 goto err_alloc;
93984
93985@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
93986 /* Don't export sysctls to unprivileged users */
93987 if (net->user_ns != &init_user_ns)
93988 table[0].procname = NULL;
93989- }
93990+ hdr = register_net_sysctl(net, "net/ipv4", table);
93991+ } else
93992+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
93993
93994- hdr = register_net_sysctl(net, "net/ipv4", table);
93995 if (hdr == NULL)
93996 goto err_reg;
93997
93998@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
93999 return 0;
94000
94001 err_reg:
94002- if (!net_eq(net, &init_net))
94003- kfree(table);
94004+ kfree(table);
94005 err_alloc:
94006 return -ENOMEM;
94007 }
94008diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
94009index 855004f..9644112 100644
94010--- a/net/ipv4/ip_gre.c
94011+++ b/net/ipv4/ip_gre.c
94012@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
94013 module_param(log_ecn_error, bool, 0644);
94014 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
94015
94016-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
94017+static struct rtnl_link_ops ipgre_link_ops;
94018 static int ipgre_tunnel_init(struct net_device *dev);
94019
94020 static int ipgre_net_id __read_mostly;
94021@@ -572,7 +572,7 @@ static int ipgre_header(struct sk_buff *skb, struct net_device *dev,
94022 if (daddr)
94023 memcpy(&iph->daddr, daddr, 4);
94024 if (iph->daddr)
94025- return t->hlen;
94026+ return t->hlen + sizeof(*iph);
94027
94028 return -(t->hlen + sizeof(*iph));
94029 }
94030@@ -919,7 +919,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
94031 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
94032 };
94033
94034-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
94035+static struct rtnl_link_ops ipgre_link_ops = {
94036 .kind = "gre",
94037 .maxtype = IFLA_GRE_MAX,
94038 .policy = ipgre_policy,
94039@@ -933,7 +933,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
94040 .fill_info = ipgre_fill_info,
94041 };
94042
94043-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
94044+static struct rtnl_link_ops ipgre_tap_ops = {
94045 .kind = "gretap",
94046 .maxtype = IFLA_GRE_MAX,
94047 .policy = ipgre_policy,
94048diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
94049index d9c4f11..02b82dbc 100644
94050--- a/net/ipv4/ip_sockglue.c
94051+++ b/net/ipv4/ip_sockglue.c
94052@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
94053 len = min_t(unsigned int, len, opt->optlen);
94054 if (put_user(len, optlen))
94055 return -EFAULT;
94056- if (copy_to_user(optval, opt->__data, len))
94057+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
94058+ copy_to_user(optval, opt->__data, len))
94059 return -EFAULT;
94060 return 0;
94061 }
94062@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
94063 if (sk->sk_type != SOCK_STREAM)
94064 return -ENOPROTOOPT;
94065
94066- msg.msg_control = optval;
94067+ msg.msg_control = (void __force_kernel *)optval;
94068 msg.msg_controllen = len;
94069 msg.msg_flags = flags;
94070
94071diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
94072index 17cc0ff..63856c4 100644
94073--- a/net/ipv4/ip_vti.c
94074+++ b/net/ipv4/ip_vti.c
94075@@ -47,7 +47,7 @@
94076 #define HASH_SIZE 16
94077 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
94078
94079-static struct rtnl_link_ops vti_link_ops __read_mostly;
94080+static struct rtnl_link_ops vti_link_ops;
94081
94082 static int vti_net_id __read_mostly;
94083 struct vti_net {
94084@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
94085 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
94086 };
94087
94088-static struct rtnl_link_ops vti_link_ops __read_mostly = {
94089+static struct rtnl_link_ops vti_link_ops = {
94090 .kind = "vti",
94091 .maxtype = IFLA_VTI_MAX,
94092 .policy = vti_policy,
94093diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
94094index 59cb8c7..a72160c 100644
94095--- a/net/ipv4/ipcomp.c
94096+++ b/net/ipv4/ipcomp.c
94097@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
94098 return;
94099
94100 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
94101- atomic_inc(&flow_cache_genid);
94102+ atomic_inc_unchecked(&flow_cache_genid);
94103 rt_genid_bump(net);
94104
94105 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
94106diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
94107index efa1138..20dbba0 100644
94108--- a/net/ipv4/ipconfig.c
94109+++ b/net/ipv4/ipconfig.c
94110@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
94111
94112 mm_segment_t oldfs = get_fs();
94113 set_fs(get_ds());
94114- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
94115+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
94116 set_fs(oldfs);
94117 return res;
94118 }
94119@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
94120
94121 mm_segment_t oldfs = get_fs();
94122 set_fs(get_ds());
94123- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
94124+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
94125 set_fs(oldfs);
94126 return res;
94127 }
94128@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
94129
94130 mm_segment_t oldfs = get_fs();
94131 set_fs(get_ds());
94132- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
94133+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
94134 set_fs(oldfs);
94135 return res;
94136 }
94137diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
94138index 7cfc456..e726868 100644
94139--- a/net/ipv4/ipip.c
94140+++ b/net/ipv4/ipip.c
94141@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
94142 static int ipip_net_id __read_mostly;
94143
94144 static int ipip_tunnel_init(struct net_device *dev);
94145-static struct rtnl_link_ops ipip_link_ops __read_mostly;
94146+static struct rtnl_link_ops ipip_link_ops;
94147
94148 static int ipip_err(struct sk_buff *skb, u32 info)
94149 {
94150@@ -406,7 +406,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
94151 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
94152 };
94153
94154-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
94155+static struct rtnl_link_ops ipip_link_ops = {
94156 .kind = "ipip",
94157 .maxtype = IFLA_IPTUN_MAX,
94158 .policy = ipip_policy,
94159diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
94160index 85a4f21..1beb1f5 100644
94161--- a/net/ipv4/netfilter/arp_tables.c
94162+++ b/net/ipv4/netfilter/arp_tables.c
94163@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
94164 #endif
94165
94166 static int get_info(struct net *net, void __user *user,
94167- const int *len, int compat)
94168+ int len, int compat)
94169 {
94170 char name[XT_TABLE_MAXNAMELEN];
94171 struct xt_table *t;
94172 int ret;
94173
94174- if (*len != sizeof(struct arpt_getinfo)) {
94175- duprintf("length %u != %Zu\n", *len,
94176+ if (len != sizeof(struct arpt_getinfo)) {
94177+ duprintf("length %u != %Zu\n", len,
94178 sizeof(struct arpt_getinfo));
94179 return -EINVAL;
94180 }
94181@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
94182 info.size = private->size;
94183 strcpy(info.name, name);
94184
94185- if (copy_to_user(user, &info, *len) != 0)
94186+ if (copy_to_user(user, &info, len) != 0)
94187 ret = -EFAULT;
94188 else
94189 ret = 0;
94190@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
94191
94192 switch (cmd) {
94193 case ARPT_SO_GET_INFO:
94194- ret = get_info(sock_net(sk), user, len, 1);
94195+ ret = get_info(sock_net(sk), user, *len, 1);
94196 break;
94197 case ARPT_SO_GET_ENTRIES:
94198 ret = compat_get_entries(sock_net(sk), user, len);
94199@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
94200
94201 switch (cmd) {
94202 case ARPT_SO_GET_INFO:
94203- ret = get_info(sock_net(sk), user, len, 0);
94204+ ret = get_info(sock_net(sk), user, *len, 0);
94205 break;
94206
94207 case ARPT_SO_GET_ENTRIES:
94208diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
94209index d23118d..6ad7277 100644
94210--- a/net/ipv4/netfilter/ip_tables.c
94211+++ b/net/ipv4/netfilter/ip_tables.c
94212@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
94213 #endif
94214
94215 static int get_info(struct net *net, void __user *user,
94216- const int *len, int compat)
94217+ int len, int compat)
94218 {
94219 char name[XT_TABLE_MAXNAMELEN];
94220 struct xt_table *t;
94221 int ret;
94222
94223- if (*len != sizeof(struct ipt_getinfo)) {
94224- duprintf("length %u != %zu\n", *len,
94225+ if (len != sizeof(struct ipt_getinfo)) {
94226+ duprintf("length %u != %zu\n", len,
94227 sizeof(struct ipt_getinfo));
94228 return -EINVAL;
94229 }
94230@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
94231 info.size = private->size;
94232 strcpy(info.name, name);
94233
94234- if (copy_to_user(user, &info, *len) != 0)
94235+ if (copy_to_user(user, &info, len) != 0)
94236 ret = -EFAULT;
94237 else
94238 ret = 0;
94239@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
94240
94241 switch (cmd) {
94242 case IPT_SO_GET_INFO:
94243- ret = get_info(sock_net(sk), user, len, 1);
94244+ ret = get_info(sock_net(sk), user, *len, 1);
94245 break;
94246 case IPT_SO_GET_ENTRIES:
94247 ret = compat_get_entries(sock_net(sk), user, len);
94248@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
94249
94250 switch (cmd) {
94251 case IPT_SO_GET_INFO:
94252- ret = get_info(sock_net(sk), user, len, 0);
94253+ ret = get_info(sock_net(sk), user, *len, 0);
94254 break;
94255
94256 case IPT_SO_GET_ENTRIES:
94257diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
94258index 7d93d62..cbbf2a3 100644
94259--- a/net/ipv4/ping.c
94260+++ b/net/ipv4/ping.c
94261@@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
94262 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
94263 0, sock_i_ino(sp),
94264 atomic_read(&sp->sk_refcnt), sp,
94265- atomic_read(&sp->sk_drops), len);
94266+ atomic_read_unchecked(&sp->sk_drops), len);
94267 }
94268
94269 static int ping_seq_show(struct seq_file *seq, void *v)
94270diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
94271index dd44e0a..06dcca4 100644
94272--- a/net/ipv4/raw.c
94273+++ b/net/ipv4/raw.c
94274@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
94275 int raw_rcv(struct sock *sk, struct sk_buff *skb)
94276 {
94277 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
94278- atomic_inc(&sk->sk_drops);
94279+ atomic_inc_unchecked(&sk->sk_drops);
94280 kfree_skb(skb);
94281 return NET_RX_DROP;
94282 }
94283@@ -745,16 +745,20 @@ static int raw_init(struct sock *sk)
94284
94285 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
94286 {
94287+ struct icmp_filter filter;
94288+
94289 if (optlen > sizeof(struct icmp_filter))
94290 optlen = sizeof(struct icmp_filter);
94291- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
94292+ if (copy_from_user(&filter, optval, optlen))
94293 return -EFAULT;
94294+ raw_sk(sk)->filter = filter;
94295 return 0;
94296 }
94297
94298 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
94299 {
94300 int len, ret = -EFAULT;
94301+ struct icmp_filter filter;
94302
94303 if (get_user(len, optlen))
94304 goto out;
94305@@ -764,8 +768,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
94306 if (len > sizeof(struct icmp_filter))
94307 len = sizeof(struct icmp_filter);
94308 ret = -EFAULT;
94309- if (put_user(len, optlen) ||
94310- copy_to_user(optval, &raw_sk(sk)->filter, len))
94311+ filter = raw_sk(sk)->filter;
94312+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
94313 goto out;
94314 ret = 0;
94315 out: return ret;
94316@@ -994,7 +998,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
94317 0, 0L, 0,
94318 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
94319 0, sock_i_ino(sp),
94320- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
94321+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
94322 }
94323
94324 static int raw_seq_show(struct seq_file *seq, void *v)
94325diff --git a/net/ipv4/route.c b/net/ipv4/route.c
94326index d35bbf0..faa3ab8 100644
94327--- a/net/ipv4/route.c
94328+++ b/net/ipv4/route.c
94329@@ -2558,34 +2558,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
94330 .maxlen = sizeof(int),
94331 .mode = 0200,
94332 .proc_handler = ipv4_sysctl_rtcache_flush,
94333+ .extra1 = &init_net,
94334 },
94335 { },
94336 };
94337
94338 static __net_init int sysctl_route_net_init(struct net *net)
94339 {
94340- struct ctl_table *tbl;
94341+ ctl_table_no_const *tbl = NULL;
94342
94343- tbl = ipv4_route_flush_table;
94344 if (!net_eq(net, &init_net)) {
94345- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
94346+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
94347 if (tbl == NULL)
94348 goto err_dup;
94349
94350 /* Don't export sysctls to unprivileged users */
94351 if (net->user_ns != &init_user_ns)
94352 tbl[0].procname = NULL;
94353- }
94354- tbl[0].extra1 = net;
94355+ tbl[0].extra1 = net;
94356+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
94357+ } else
94358+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
94359
94360- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
94361 if (net->ipv4.route_hdr == NULL)
94362 goto err_reg;
94363 return 0;
94364
94365 err_reg:
94366- if (tbl != ipv4_route_flush_table)
94367- kfree(tbl);
94368+ kfree(tbl);
94369 err_dup:
94370 return -ENOMEM;
94371 }
94372@@ -2608,7 +2608,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
94373
94374 static __net_init int rt_genid_init(struct net *net)
94375 {
94376- atomic_set(&net->rt_genid, 0);
94377+ atomic_set_unchecked(&net->rt_genid, 0);
94378 get_random_bytes(&net->ipv4.dev_addr_genid,
94379 sizeof(net->ipv4.dev_addr_genid));
94380 return 0;
94381diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
94382index 3f25e75..3ae0f4d 100644
94383--- a/net/ipv4/sysctl_net_ipv4.c
94384+++ b/net/ipv4/sysctl_net_ipv4.c
94385@@ -57,7 +57,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
94386 {
94387 int ret;
94388 int range[2];
94389- ctl_table tmp = {
94390+ ctl_table_no_const tmp = {
94391 .data = &range,
94392 .maxlen = sizeof(range),
94393 .mode = table->mode,
94394@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
94395 int ret;
94396 gid_t urange[2];
94397 kgid_t low, high;
94398- ctl_table tmp = {
94399+ ctl_table_no_const tmp = {
94400 .data = &urange,
94401 .maxlen = sizeof(urange),
94402 .mode = table->mode,
94403@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
94404 void __user *buffer, size_t *lenp, loff_t *ppos)
94405 {
94406 char val[TCP_CA_NAME_MAX];
94407- ctl_table tbl = {
94408+ ctl_table_no_const tbl = {
94409 .data = val,
94410 .maxlen = TCP_CA_NAME_MAX,
94411 };
94412@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
94413 void __user *buffer, size_t *lenp,
94414 loff_t *ppos)
94415 {
94416- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
94417+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
94418 int ret;
94419
94420 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
94421@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
94422 void __user *buffer, size_t *lenp,
94423 loff_t *ppos)
94424 {
94425- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
94426+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
94427 int ret;
94428
94429 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
94430@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
94431 struct mem_cgroup *memcg;
94432 #endif
94433
94434- ctl_table tmp = {
94435+ ctl_table_no_const tmp = {
94436 .data = &vec,
94437 .maxlen = sizeof(vec),
94438 .mode = ctl->mode,
94439 };
94440
94441 if (!write) {
94442- ctl->data = &net->ipv4.sysctl_tcp_mem;
94443- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
94444+ ctl_table_no_const tcp_mem = *ctl;
94445+
94446+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
94447+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
94448 }
94449
94450 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
94451@@ -238,7 +240,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
94452 static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
94453 size_t *lenp, loff_t *ppos)
94454 {
94455- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
94456+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
94457 struct tcp_fastopen_context *ctxt;
94458 int ret;
94459 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
94460@@ -481,7 +483,7 @@ static struct ctl_table ipv4_table[] = {
94461 },
94462 {
94463 .procname = "ip_local_reserved_ports",
94464- .data = NULL, /* initialized in sysctl_ipv4_init */
94465+ .data = sysctl_local_reserved_ports,
94466 .maxlen = 65536,
94467 .mode = 0644,
94468 .proc_handler = proc_do_large_bitmap,
94469@@ -846,11 +848,10 @@ static struct ctl_table ipv4_net_table[] = {
94470
94471 static __net_init int ipv4_sysctl_init_net(struct net *net)
94472 {
94473- struct ctl_table *table;
94474+ ctl_table_no_const *table = NULL;
94475
94476- table = ipv4_net_table;
94477 if (!net_eq(net, &init_net)) {
94478- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
94479+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
94480 if (table == NULL)
94481 goto err_alloc;
94482
94483@@ -885,15 +886,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
94484
94485 tcp_init_mem(net);
94486
94487- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
94488+ if (!net_eq(net, &init_net))
94489+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
94490+ else
94491+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
94492 if (net->ipv4.ipv4_hdr == NULL)
94493 goto err_reg;
94494
94495 return 0;
94496
94497 err_reg:
94498- if (!net_eq(net, &init_net))
94499- kfree(table);
94500+ kfree(table);
94501 err_alloc:
94502 return -ENOMEM;
94503 }
94504@@ -915,16 +918,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
94505 static __init int sysctl_ipv4_init(void)
94506 {
94507 struct ctl_table_header *hdr;
94508- struct ctl_table *i;
94509-
94510- for (i = ipv4_table; i->procname; i++) {
94511- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
94512- i->data = sysctl_local_reserved_ports;
94513- break;
94514- }
94515- }
94516- if (!i->procname)
94517- return -EINVAL;
94518
94519 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
94520 if (hdr == NULL)
94521diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
94522index 9c62257..651cc27 100644
94523--- a/net/ipv4/tcp_input.c
94524+++ b/net/ipv4/tcp_input.c
94525@@ -4436,7 +4436,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
94526 * simplifies code)
94527 */
94528 static void
94529-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
94530+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
94531 struct sk_buff *head, struct sk_buff *tail,
94532 u32 start, u32 end)
94533 {
94534@@ -5522,6 +5522,7 @@ discard:
94535 tcp_paws_reject(&tp->rx_opt, 0))
94536 goto discard_and_undo;
94537
94538+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
94539 if (th->syn) {
94540 /* We see SYN without ACK. It is attempt of
94541 * simultaneous connect with crossed SYNs.
94542@@ -5572,6 +5573,7 @@ discard:
94543 goto discard;
94544 #endif
94545 }
94546+#endif
94547 /* "fifth, if neither of the SYN or RST bits is set then
94548 * drop the segment and return."
94549 */
94550@@ -5616,7 +5618,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
94551 goto discard;
94552
94553 if (th->syn) {
94554- if (th->fin)
94555+ if (th->fin || th->urg || th->psh)
94556 goto discard;
94557 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
94558 return 1;
94559diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
94560index 7999fc5..c812f42 100644
94561--- a/net/ipv4/tcp_ipv4.c
94562+++ b/net/ipv4/tcp_ipv4.c
94563@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
94564 EXPORT_SYMBOL(sysctl_tcp_low_latency);
94565
94566
94567+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94568+extern int grsec_enable_blackhole;
94569+#endif
94570+
94571 #ifdef CONFIG_TCP_MD5SIG
94572 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
94573 __be32 daddr, __be32 saddr, const struct tcphdr *th);
94574@@ -1855,6 +1859,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
94575 return 0;
94576
94577 reset:
94578+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94579+ if (!grsec_enable_blackhole)
94580+#endif
94581 tcp_v4_send_reset(rsk, skb);
94582 discard:
94583 kfree_skb(skb);
94584@@ -2000,12 +2007,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
94585 TCP_SKB_CB(skb)->sacked = 0;
94586
94587 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
94588- if (!sk)
94589+ if (!sk) {
94590+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94591+ ret = 1;
94592+#endif
94593 goto no_tcp_socket;
94594-
94595+ }
94596 process:
94597- if (sk->sk_state == TCP_TIME_WAIT)
94598+ if (sk->sk_state == TCP_TIME_WAIT) {
94599+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94600+ ret = 2;
94601+#endif
94602 goto do_time_wait;
94603+ }
94604
94605 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
94606 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
94607@@ -2058,6 +2072,10 @@ csum_error:
94608 bad_packet:
94609 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
94610 } else {
94611+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94612+ if (!grsec_enable_blackhole || (ret == 1 &&
94613+ (skb->dev->flags & IFF_LOOPBACK)))
94614+#endif
94615 tcp_v4_send_reset(NULL, skb);
94616 }
94617
94618diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
94619index 0f01788..d52a859 100644
94620--- a/net/ipv4/tcp_minisocks.c
94621+++ b/net/ipv4/tcp_minisocks.c
94622@@ -27,6 +27,10 @@
94623 #include <net/inet_common.h>
94624 #include <net/xfrm.h>
94625
94626+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94627+extern int grsec_enable_blackhole;
94628+#endif
94629+
94630 int sysctl_tcp_syncookies __read_mostly = 1;
94631 EXPORT_SYMBOL(sysctl_tcp_syncookies);
94632
94633@@ -717,7 +721,10 @@ embryonic_reset:
94634 * avoid becoming vulnerable to outside attack aiming at
94635 * resetting legit local connections.
94636 */
94637- req->rsk_ops->send_reset(sk, skb);
94638+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94639+ if (!grsec_enable_blackhole)
94640+#endif
94641+ req->rsk_ops->send_reset(sk, skb);
94642 } else if (fastopen) { /* received a valid RST pkt */
94643 reqsk_fastopen_remove(sk, req, true);
94644 tcp_reset(sk);
94645diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
94646index d4943f6..e7a74a5 100644
94647--- a/net/ipv4/tcp_probe.c
94648+++ b/net/ipv4/tcp_probe.c
94649@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
94650 if (cnt + width >= len)
94651 break;
94652
94653- if (copy_to_user(buf + cnt, tbuf, width))
94654+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
94655 return -EFAULT;
94656 cnt += width;
94657 }
94658diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
94659index 4b85e6f..22f9ac9 100644
94660--- a/net/ipv4/tcp_timer.c
94661+++ b/net/ipv4/tcp_timer.c
94662@@ -22,6 +22,10 @@
94663 #include <linux/gfp.h>
94664 #include <net/tcp.h>
94665
94666+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94667+extern int grsec_lastack_retries;
94668+#endif
94669+
94670 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
94671 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
94672 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
94673@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
94674 }
94675 }
94676
94677+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94678+ if ((sk->sk_state == TCP_LAST_ACK) &&
94679+ (grsec_lastack_retries > 0) &&
94680+ (grsec_lastack_retries < retry_until))
94681+ retry_until = grsec_lastack_retries;
94682+#endif
94683+
94684 if (retransmits_timed_out(sk, retry_until,
94685 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
94686 /* Has it gone just too far? */
94687diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
94688index 93b731d..5a2dd92 100644
94689--- a/net/ipv4/udp.c
94690+++ b/net/ipv4/udp.c
94691@@ -87,6 +87,7 @@
94692 #include <linux/types.h>
94693 #include <linux/fcntl.h>
94694 #include <linux/module.h>
94695+#include <linux/security.h>
94696 #include <linux/socket.h>
94697 #include <linux/sockios.h>
94698 #include <linux/igmp.h>
94699@@ -111,6 +112,10 @@
94700 #include <trace/events/skb.h>
94701 #include "udp_impl.h"
94702
94703+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94704+extern int grsec_enable_blackhole;
94705+#endif
94706+
94707 struct udp_table udp_table __read_mostly;
94708 EXPORT_SYMBOL(udp_table);
94709
94710@@ -594,6 +599,9 @@ found:
94711 return s;
94712 }
94713
94714+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
94715+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
94716+
94717 /*
94718 * This routine is called by the ICMP module when it gets some
94719 * sort of error condition. If err < 0 then the socket should
94720@@ -890,9 +898,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
94721 dport = usin->sin_port;
94722 if (dport == 0)
94723 return -EINVAL;
94724+
94725+ err = gr_search_udp_sendmsg(sk, usin);
94726+ if (err)
94727+ return err;
94728 } else {
94729 if (sk->sk_state != TCP_ESTABLISHED)
94730 return -EDESTADDRREQ;
94731+
94732+ err = gr_search_udp_sendmsg(sk, NULL);
94733+ if (err)
94734+ return err;
94735+
94736 daddr = inet->inet_daddr;
94737 dport = inet->inet_dport;
94738 /* Open fast path for connected socket.
94739@@ -1136,7 +1153,7 @@ static unsigned int first_packet_length(struct sock *sk)
94740 IS_UDPLITE(sk));
94741 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
94742 IS_UDPLITE(sk));
94743- atomic_inc(&sk->sk_drops);
94744+ atomic_inc_unchecked(&sk->sk_drops);
94745 __skb_unlink(skb, rcvq);
94746 __skb_queue_tail(&list_kill, skb);
94747 }
94748@@ -1222,6 +1239,10 @@ try_again:
94749 if (!skb)
94750 goto out;
94751
94752+ err = gr_search_udp_recvmsg(sk, skb);
94753+ if (err)
94754+ goto out_free;
94755+
94756 ulen = skb->len - sizeof(struct udphdr);
94757 copied = len;
94758 if (copied > ulen)
94759@@ -1255,7 +1276,7 @@ try_again:
94760 if (unlikely(err)) {
94761 trace_kfree_skb(skb, udp_recvmsg);
94762 if (!peeked) {
94763- atomic_inc(&sk->sk_drops);
94764+ atomic_inc_unchecked(&sk->sk_drops);
94765 UDP_INC_STATS_USER(sock_net(sk),
94766 UDP_MIB_INERRORS, is_udplite);
94767 }
94768@@ -1542,7 +1563,7 @@ csum_error:
94769 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
94770 drop:
94771 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
94772- atomic_inc(&sk->sk_drops);
94773+ atomic_inc_unchecked(&sk->sk_drops);
94774 kfree_skb(skb);
94775 return -1;
94776 }
94777@@ -1561,7 +1582,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
94778 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
94779
94780 if (!skb1) {
94781- atomic_inc(&sk->sk_drops);
94782+ atomic_inc_unchecked(&sk->sk_drops);
94783 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
94784 IS_UDPLITE(sk));
94785 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
94786@@ -1730,6 +1751,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
94787 goto csum_error;
94788
94789 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
94790+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94791+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
94792+#endif
94793 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
94794
94795 /*
94796@@ -2160,7 +2184,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
94797 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
94798 0, sock_i_ino(sp),
94799 atomic_read(&sp->sk_refcnt), sp,
94800- atomic_read(&sp->sk_drops), len);
94801+ atomic_read_unchecked(&sp->sk_drops), len);
94802 }
94803
94804 int udp4_seq_show(struct seq_file *seq, void *v)
94805diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
94806index 9a459be..086b866 100644
94807--- a/net/ipv4/xfrm4_policy.c
94808+++ b/net/ipv4/xfrm4_policy.c
94809@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
94810
94811 static int __net_init xfrm4_net_init(struct net *net)
94812 {
94813- struct ctl_table *table;
94814+ ctl_table_no_const *table = NULL;
94815 struct ctl_table_header *hdr;
94816
94817- table = xfrm4_policy_table;
94818 if (!net_eq(net, &init_net)) {
94819- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
94820+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
94821 if (!table)
94822 goto err_alloc;
94823
94824 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
94825- }
94826-
94827- hdr = register_net_sysctl(net, "net/ipv4", table);
94828+ hdr = register_net_sysctl(net, "net/ipv4", table);
94829+ } else
94830+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
94831 if (!hdr)
94832 goto err_reg;
94833
94834@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
94835 return 0;
94836
94837 err_reg:
94838- if (!net_eq(net, &init_net))
94839- kfree(table);
94840+ kfree(table);
94841 err_alloc:
94842 return -ENOMEM;
94843 }
94844diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
94845index fb8c94c..80a31d8 100644
94846--- a/net/ipv6/addrconf.c
94847+++ b/net/ipv6/addrconf.c
94848@@ -621,7 +621,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
94849 idx = 0;
94850 head = &net->dev_index_head[h];
94851 rcu_read_lock();
94852- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
94853+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
94854 net->dev_base_seq;
94855 hlist_for_each_entry_rcu(dev, head, index_hlist) {
94856 if (idx < s_idx)
94857@@ -1124,12 +1124,10 @@ retry:
94858 if (ifp->flags & IFA_F_OPTIMISTIC)
94859 addr_flags |= IFA_F_OPTIMISTIC;
94860
94861- ift = !max_addresses ||
94862- ipv6_count_addresses(idev) < max_addresses ?
94863- ipv6_add_addr(idev, &addr, tmp_plen,
94864- ipv6_addr_type(&addr)&IPV6_ADDR_SCOPE_MASK,
94865- addr_flags) : NULL;
94866- if (IS_ERR_OR_NULL(ift)) {
94867+ ift = ipv6_add_addr(idev, &addr, tmp_plen,
94868+ ipv6_addr_type(&addr)&IPV6_ADDR_SCOPE_MASK,
94869+ addr_flags);
94870+ if (IS_ERR(ift)) {
94871 in6_ifa_put(ifp);
94872 in6_dev_put(idev);
94873 pr_info("%s: retry temporary address regeneration\n", __func__);
94874@@ -2380,7 +2378,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
94875 p.iph.ihl = 5;
94876 p.iph.protocol = IPPROTO_IPV6;
94877 p.iph.ttl = 64;
94878- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
94879+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
94880
94881 if (ops->ndo_do_ioctl) {
94882 mm_segment_t oldfs = get_fs();
94883@@ -4002,7 +4000,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
94884 s_ip_idx = ip_idx = cb->args[2];
94885
94886 rcu_read_lock();
94887- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
94888+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
94889 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
94890 idx = 0;
94891 head = &net->dev_index_head[h];
94892@@ -4587,7 +4585,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
94893 dst_free(&ifp->rt->dst);
94894 break;
94895 }
94896- atomic_inc(&net->ipv6.dev_addr_genid);
94897+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
94898 }
94899
94900 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
94901@@ -4607,7 +4605,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
94902 int *valp = ctl->data;
94903 int val = *valp;
94904 loff_t pos = *ppos;
94905- ctl_table lctl;
94906+ ctl_table_no_const lctl;
94907 int ret;
94908
94909 /*
94910@@ -4689,7 +4687,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
94911 int *valp = ctl->data;
94912 int val = *valp;
94913 loff_t pos = *ppos;
94914- ctl_table lctl;
94915+ ctl_table_no_const lctl;
94916 int ret;
94917
94918 /*
94919diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
94920index 40ffd72..aeac0dc 100644
94921--- a/net/ipv6/esp6.c
94922+++ b/net/ipv6/esp6.c
94923@@ -425,7 +425,7 @@ static u32 esp6_get_mtu(struct xfrm_state *x, int mtu)
94924 net_adj = 0;
94925
94926 return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) -
94927- net_adj) & ~(align - 1)) + (net_adj - 2);
94928+ net_adj) & ~(align - 1)) + net_adj - 2;
94929 }
94930
94931 static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
94932diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
94933index b4ff0a4..db9b764 100644
94934--- a/net/ipv6/icmp.c
94935+++ b/net/ipv6/icmp.c
94936@@ -980,7 +980,7 @@ ctl_table ipv6_icmp_table_template[] = {
94937
94938 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
94939 {
94940- struct ctl_table *table;
94941+ ctl_table_no_const *table;
94942
94943 table = kmemdup(ipv6_icmp_table_template,
94944 sizeof(ipv6_icmp_table_template),
94945diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
94946index ecd6073..58162ae 100644
94947--- a/net/ipv6/ip6_gre.c
94948+++ b/net/ipv6/ip6_gre.c
94949@@ -74,7 +74,7 @@ struct ip6gre_net {
94950 struct net_device *fb_tunnel_dev;
94951 };
94952
94953-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
94954+static struct rtnl_link_ops ip6gre_link_ops;
94955 static int ip6gre_tunnel_init(struct net_device *dev);
94956 static void ip6gre_tunnel_setup(struct net_device *dev);
94957 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
94958@@ -1283,7 +1283,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
94959 }
94960
94961
94962-static struct inet6_protocol ip6gre_protocol __read_mostly = {
94963+static struct inet6_protocol ip6gre_protocol = {
94964 .handler = ip6gre_rcv,
94965 .err_handler = ip6gre_err,
94966 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
94967@@ -1617,7 +1617,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
94968 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
94969 };
94970
94971-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
94972+static struct rtnl_link_ops ip6gre_link_ops = {
94973 .kind = "ip6gre",
94974 .maxtype = IFLA_GRE_MAX,
94975 .policy = ip6gre_policy,
94976@@ -1630,7 +1630,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
94977 .fill_info = ip6gre_fill_info,
94978 };
94979
94980-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
94981+static struct rtnl_link_ops ip6gre_tap_ops = {
94982 .kind = "ip6gretap",
94983 .maxtype = IFLA_GRE_MAX,
94984 .policy = ip6gre_policy,
94985diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
94986index 1e55866..b398dab 100644
94987--- a/net/ipv6/ip6_tunnel.c
94988+++ b/net/ipv6/ip6_tunnel.c
94989@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
94990
94991 static int ip6_tnl_dev_init(struct net_device *dev);
94992 static void ip6_tnl_dev_setup(struct net_device *dev);
94993-static struct rtnl_link_ops ip6_link_ops __read_mostly;
94994+static struct rtnl_link_ops ip6_link_ops;
94995
94996 static int ip6_tnl_net_id __read_mostly;
94997 struct ip6_tnl_net {
94998@@ -1672,7 +1672,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
94999 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
95000 };
95001
95002-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
95003+static struct rtnl_link_ops ip6_link_ops = {
95004 .kind = "ip6tnl",
95005 .maxtype = IFLA_IPTUN_MAX,
95006 .policy = ip6_tnl_policy,
95007diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
95008index d1e2e8e..51c19ae 100644
95009--- a/net/ipv6/ipv6_sockglue.c
95010+++ b/net/ipv6/ipv6_sockglue.c
95011@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
95012 if (sk->sk_type != SOCK_STREAM)
95013 return -ENOPROTOOPT;
95014
95015- msg.msg_control = optval;
95016+ msg.msg_control = (void __force_kernel *)optval;
95017 msg.msg_controllen = len;
95018 msg.msg_flags = flags;
95019
95020diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
95021index 44400c2..8e11f52 100644
95022--- a/net/ipv6/netfilter/ip6_tables.c
95023+++ b/net/ipv6/netfilter/ip6_tables.c
95024@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
95025 #endif
95026
95027 static int get_info(struct net *net, void __user *user,
95028- const int *len, int compat)
95029+ int len, int compat)
95030 {
95031 char name[XT_TABLE_MAXNAMELEN];
95032 struct xt_table *t;
95033 int ret;
95034
95035- if (*len != sizeof(struct ip6t_getinfo)) {
95036- duprintf("length %u != %zu\n", *len,
95037+ if (len != sizeof(struct ip6t_getinfo)) {
95038+ duprintf("length %u != %zu\n", len,
95039 sizeof(struct ip6t_getinfo));
95040 return -EINVAL;
95041 }
95042@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
95043 info.size = private->size;
95044 strcpy(info.name, name);
95045
95046- if (copy_to_user(user, &info, *len) != 0)
95047+ if (copy_to_user(user, &info, len) != 0)
95048 ret = -EFAULT;
95049 else
95050 ret = 0;
95051@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95052
95053 switch (cmd) {
95054 case IP6T_SO_GET_INFO:
95055- ret = get_info(sock_net(sk), user, len, 1);
95056+ ret = get_info(sock_net(sk), user, *len, 1);
95057 break;
95058 case IP6T_SO_GET_ENTRIES:
95059 ret = compat_get_entries(sock_net(sk), user, len);
95060@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95061
95062 switch (cmd) {
95063 case IP6T_SO_GET_INFO:
95064- ret = get_info(sock_net(sk), user, len, 0);
95065+ ret = get_info(sock_net(sk), user, *len, 0);
95066 break;
95067
95068 case IP6T_SO_GET_ENTRIES:
95069diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
95070index dffdc1a..ccc6678 100644
95071--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
95072+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
95073@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
95074
95075 static int nf_ct_frag6_sysctl_register(struct net *net)
95076 {
95077- struct ctl_table *table;
95078+ ctl_table_no_const *table = NULL;
95079 struct ctl_table_header *hdr;
95080
95081- table = nf_ct_frag6_sysctl_table;
95082 if (!net_eq(net, &init_net)) {
95083- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
95084+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
95085 GFP_KERNEL);
95086 if (table == NULL)
95087 goto err_alloc;
95088@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
95089 table[0].data = &net->nf_frag.frags.timeout;
95090 table[1].data = &net->nf_frag.frags.low_thresh;
95091 table[2].data = &net->nf_frag.frags.high_thresh;
95092- }
95093-
95094- hdr = register_net_sysctl(net, "net/netfilter", table);
95095+ hdr = register_net_sysctl(net, "net/netfilter", table);
95096+ } else
95097+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
95098 if (hdr == NULL)
95099 goto err_reg;
95100
95101@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
95102 return 0;
95103
95104 err_reg:
95105- if (!net_eq(net, &init_net))
95106- kfree(table);
95107+ kfree(table);
95108 err_alloc:
95109 return -ENOMEM;
95110 }
95111diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
95112index c2e73e6..12cca6f 100644
95113--- a/net/ipv6/output_core.c
95114+++ b/net/ipv6/output_core.c
95115@@ -8,8 +8,8 @@
95116
95117 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
95118 {
95119- static atomic_t ipv6_fragmentation_id;
95120- int old, new;
95121+ static atomic_unchecked_t ipv6_fragmentation_id;
95122+ int id;
95123
95124 #if IS_ENABLED(CONFIG_IPV6)
95125 if (rt && !(rt->dst.flags & DST_NOPEER)) {
95126@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
95127 }
95128 }
95129 #endif
95130- do {
95131- old = atomic_read(&ipv6_fragmentation_id);
95132- new = old + 1;
95133- if (!new)
95134- new = 1;
95135- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
95136- fhdr->identification = htonl(new);
95137+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
95138+ if (!id)
95139+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
95140+ fhdr->identification = htonl(id);
95141 }
95142 EXPORT_SYMBOL(ipv6_select_ident);
95143
95144diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
95145index eedff8c..7d7e24a 100644
95146--- a/net/ipv6/raw.c
95147+++ b/net/ipv6/raw.c
95148@@ -108,7 +108,7 @@ found:
95149 */
95150 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
95151 {
95152- struct icmp6hdr *_hdr;
95153+ struct icmp6hdr _hdr;
95154 const struct icmp6hdr *hdr;
95155
95156 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
95157@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
95158 {
95159 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
95160 skb_checksum_complete(skb)) {
95161- atomic_inc(&sk->sk_drops);
95162+ atomic_inc_unchecked(&sk->sk_drops);
95163 kfree_skb(skb);
95164 return NET_RX_DROP;
95165 }
95166@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
95167 struct raw6_sock *rp = raw6_sk(sk);
95168
95169 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
95170- atomic_inc(&sk->sk_drops);
95171+ atomic_inc_unchecked(&sk->sk_drops);
95172 kfree_skb(skb);
95173 return NET_RX_DROP;
95174 }
95175@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
95176
95177 if (inet->hdrincl) {
95178 if (skb_checksum_complete(skb)) {
95179- atomic_inc(&sk->sk_drops);
95180+ atomic_inc_unchecked(&sk->sk_drops);
95181 kfree_skb(skb);
95182 return NET_RX_DROP;
95183 }
95184@@ -602,7 +602,7 @@ out:
95185 return err;
95186 }
95187
95188-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
95189+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
95190 struct flowi6 *fl6, struct dst_entry **dstp,
95191 unsigned int flags)
95192 {
95193@@ -914,12 +914,15 @@ do_confirm:
95194 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
95195 char __user *optval, int optlen)
95196 {
95197+ struct icmp6_filter filter;
95198+
95199 switch (optname) {
95200 case ICMPV6_FILTER:
95201 if (optlen > sizeof(struct icmp6_filter))
95202 optlen = sizeof(struct icmp6_filter);
95203- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
95204+ if (copy_from_user(&filter, optval, optlen))
95205 return -EFAULT;
95206+ raw6_sk(sk)->filter = filter;
95207 return 0;
95208 default:
95209 return -ENOPROTOOPT;
95210@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
95211 char __user *optval, int __user *optlen)
95212 {
95213 int len;
95214+ struct icmp6_filter filter;
95215
95216 switch (optname) {
95217 case ICMPV6_FILTER:
95218@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
95219 len = sizeof(struct icmp6_filter);
95220 if (put_user(len, optlen))
95221 return -EFAULT;
95222- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
95223+ filter = raw6_sk(sk)->filter;
95224+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
95225 return -EFAULT;
95226 return 0;
95227 default:
95228@@ -1251,7 +1256,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
95229 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
95230 0,
95231 sock_i_ino(sp),
95232- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
95233+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
95234 }
95235
95236 static int raw6_seq_show(struct seq_file *seq, void *v)
95237diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
95238index 790d9f4..68ae078 100644
95239--- a/net/ipv6/reassembly.c
95240+++ b/net/ipv6/reassembly.c
95241@@ -621,12 +621,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
95242
95243 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
95244 {
95245- struct ctl_table *table;
95246+ ctl_table_no_const *table = NULL;
95247 struct ctl_table_header *hdr;
95248
95249- table = ip6_frags_ns_ctl_table;
95250 if (!net_eq(net, &init_net)) {
95251- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
95252+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
95253 if (table == NULL)
95254 goto err_alloc;
95255
95256@@ -637,9 +636,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
95257 /* Don't export sysctls to unprivileged users */
95258 if (net->user_ns != &init_user_ns)
95259 table[0].procname = NULL;
95260- }
95261+ hdr = register_net_sysctl(net, "net/ipv6", table);
95262+ } else
95263+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
95264
95265- hdr = register_net_sysctl(net, "net/ipv6", table);
95266 if (hdr == NULL)
95267 goto err_reg;
95268
95269@@ -647,8 +647,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
95270 return 0;
95271
95272 err_reg:
95273- if (!net_eq(net, &init_net))
95274- kfree(table);
95275+ kfree(table);
95276 err_alloc:
95277 return -ENOMEM;
95278 }
95279diff --git a/net/ipv6/route.c b/net/ipv6/route.c
95280index bacce6c..9d1741a 100644
95281--- a/net/ipv6/route.c
95282+++ b/net/ipv6/route.c
95283@@ -2903,7 +2903,7 @@ ctl_table ipv6_route_table_template[] = {
95284
95285 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
95286 {
95287- struct ctl_table *table;
95288+ ctl_table_no_const *table;
95289
95290 table = kmemdup(ipv6_route_table_template,
95291 sizeof(ipv6_route_table_template),
95292diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
95293index 60df36d..f3ab7c8 100644
95294--- a/net/ipv6/sit.c
95295+++ b/net/ipv6/sit.c
95296@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
95297 static void ipip6_dev_free(struct net_device *dev);
95298 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
95299 __be32 *v4dst);
95300-static struct rtnl_link_ops sit_link_ops __read_mostly;
95301+static struct rtnl_link_ops sit_link_ops;
95302
95303 static int sit_net_id __read_mostly;
95304 struct sit_net {
95305@@ -1453,7 +1453,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
95306 #endif
95307 };
95308
95309-static struct rtnl_link_ops sit_link_ops __read_mostly = {
95310+static struct rtnl_link_ops sit_link_ops = {
95311 .kind = "sit",
95312 .maxtype = IFLA_IPTUN_MAX,
95313 .policy = ipip6_policy,
95314diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
95315index e85c48b..b8268d3 100644
95316--- a/net/ipv6/sysctl_net_ipv6.c
95317+++ b/net/ipv6/sysctl_net_ipv6.c
95318@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
95319
95320 static int __net_init ipv6_sysctl_net_init(struct net *net)
95321 {
95322- struct ctl_table *ipv6_table;
95323+ ctl_table_no_const *ipv6_table;
95324 struct ctl_table *ipv6_route_table;
95325 struct ctl_table *ipv6_icmp_table;
95326 int err;
95327diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
95328index 0a17ed9..5600868 100644
95329--- a/net/ipv6/tcp_ipv6.c
95330+++ b/net/ipv6/tcp_ipv6.c
95331@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
95332 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
95333 }
95334
95335+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95336+extern int grsec_enable_blackhole;
95337+#endif
95338+
95339 static void tcp_v6_hash(struct sock *sk)
95340 {
95341 if (sk->sk_state != TCP_CLOSE) {
95342@@ -1398,6 +1402,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
95343 return 0;
95344
95345 reset:
95346+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95347+ if (!grsec_enable_blackhole)
95348+#endif
95349 tcp_v6_send_reset(sk, skb);
95350 discard:
95351 if (opt_skb)
95352@@ -1426,7 +1433,7 @@ ipv6_pktoptions:
95353 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
95354 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
95355 if (np->rxopt.bits.rxtclass)
95356- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
95357+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
95358 if (ipv6_opt_accepted(sk, opt_skb)) {
95359 skb_set_owner_r(opt_skb, sk);
95360 opt_skb = xchg(&np->pktoptions, opt_skb);
95361@@ -1480,12 +1487,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
95362 TCP_SKB_CB(skb)->sacked = 0;
95363
95364 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
95365- if (!sk)
95366+ if (!sk) {
95367+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95368+ ret = 1;
95369+#endif
95370 goto no_tcp_socket;
95371+ }
95372
95373 process:
95374- if (sk->sk_state == TCP_TIME_WAIT)
95375+ if (sk->sk_state == TCP_TIME_WAIT) {
95376+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95377+ ret = 2;
95378+#endif
95379 goto do_time_wait;
95380+ }
95381
95382 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
95383 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
95384@@ -1536,6 +1551,10 @@ csum_error:
95385 bad_packet:
95386 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
95387 } else {
95388+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95389+ if (!grsec_enable_blackhole || (ret == 1 &&
95390+ (skb->dev->flags & IFF_LOOPBACK)))
95391+#endif
95392 tcp_v6_send_reset(NULL, skb);
95393 }
95394
95395diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
95396index e7b28f9..d09c290 100644
95397--- a/net/ipv6/udp.c
95398+++ b/net/ipv6/udp.c
95399@@ -52,6 +52,10 @@
95400 #include <trace/events/skb.h>
95401 #include "udp_impl.h"
95402
95403+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95404+extern int grsec_enable_blackhole;
95405+#endif
95406+
95407 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
95408 {
95409 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
95410@@ -419,7 +423,7 @@ try_again:
95411 if (unlikely(err)) {
95412 trace_kfree_skb(skb, udpv6_recvmsg);
95413 if (!peeked) {
95414- atomic_inc(&sk->sk_drops);
95415+ atomic_inc_unchecked(&sk->sk_drops);
95416 if (is_udp4)
95417 UDP_INC_STATS_USER(sock_net(sk),
95418 UDP_MIB_INERRORS,
95419@@ -665,7 +669,7 @@ csum_error:
95420 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
95421 drop:
95422 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
95423- atomic_inc(&sk->sk_drops);
95424+ atomic_inc_unchecked(&sk->sk_drops);
95425 kfree_skb(skb);
95426 return -1;
95427 }
95428@@ -723,7 +727,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
95429 if (likely(skb1 == NULL))
95430 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
95431 if (!skb1) {
95432- atomic_inc(&sk->sk_drops);
95433+ atomic_inc_unchecked(&sk->sk_drops);
95434 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
95435 IS_UDPLITE(sk));
95436 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
95437@@ -860,6 +864,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
95438 goto csum_error;
95439
95440 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
95441+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95442+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
95443+#endif
95444 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
95445
95446 kfree_skb(skb);
95447@@ -1392,7 +1399,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
95448 0,
95449 sock_i_ino(sp),
95450 atomic_read(&sp->sk_refcnt), sp,
95451- atomic_read(&sp->sk_drops));
95452+ atomic_read_unchecked(&sp->sk_drops));
95453 }
95454
95455 int udp6_seq_show(struct seq_file *seq, void *v)
95456diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
95457index 23ed03d..465a71d 100644
95458--- a/net/ipv6/xfrm6_policy.c
95459+++ b/net/ipv6/xfrm6_policy.c
95460@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
95461
95462 static int __net_init xfrm6_net_init(struct net *net)
95463 {
95464- struct ctl_table *table;
95465+ ctl_table_no_const *table = NULL;
95466 struct ctl_table_header *hdr;
95467
95468- table = xfrm6_policy_table;
95469 if (!net_eq(net, &init_net)) {
95470- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
95471+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
95472 if (!table)
95473 goto err_alloc;
95474
95475 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
95476- }
95477+ hdr = register_net_sysctl(net, "net/ipv6", table);
95478+ } else
95479+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
95480
95481- hdr = register_net_sysctl(net, "net/ipv6", table);
95482 if (!hdr)
95483 goto err_reg;
95484
95485@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
95486 return 0;
95487
95488 err_reg:
95489- if (!net_eq(net, &init_net))
95490- kfree(table);
95491+ kfree(table);
95492 err_alloc:
95493 return -ENOMEM;
95494 }
95495diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
95496index 41ac7938..75e3bb1 100644
95497--- a/net/irda/ircomm/ircomm_tty.c
95498+++ b/net/irda/ircomm/ircomm_tty.c
95499@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95500 add_wait_queue(&port->open_wait, &wait);
95501
95502 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
95503- __FILE__, __LINE__, tty->driver->name, port->count);
95504+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95505
95506 spin_lock_irqsave(&port->lock, flags);
95507 if (!tty_hung_up_p(filp))
95508- port->count--;
95509+ atomic_dec(&port->count);
95510 port->blocked_open++;
95511 spin_unlock_irqrestore(&port->lock, flags);
95512
95513@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95514 }
95515
95516 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
95517- __FILE__, __LINE__, tty->driver->name, port->count);
95518+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95519
95520 schedule();
95521 }
95522@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95523
95524 spin_lock_irqsave(&port->lock, flags);
95525 if (!tty_hung_up_p(filp))
95526- port->count++;
95527+ atomic_inc(&port->count);
95528 port->blocked_open--;
95529 spin_unlock_irqrestore(&port->lock, flags);
95530
95531 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
95532- __FILE__, __LINE__, tty->driver->name, port->count);
95533+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95534
95535 if (!retval)
95536 port->flags |= ASYNC_NORMAL_ACTIVE;
95537@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
95538
95539 /* ++ is not atomic, so this should be protected - Jean II */
95540 spin_lock_irqsave(&self->port.lock, flags);
95541- self->port.count++;
95542+ atomic_inc(&self->port.count);
95543 spin_unlock_irqrestore(&self->port.lock, flags);
95544 tty_port_tty_set(&self->port, tty);
95545
95546 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
95547- self->line, self->port.count);
95548+ self->line, atomic_read(&self->port.count));
95549
95550 /* Not really used by us, but lets do it anyway */
95551 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
95552@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
95553 tty_kref_put(port->tty);
95554 }
95555 port->tty = NULL;
95556- port->count = 0;
95557+ atomic_set(&port->count, 0);
95558 spin_unlock_irqrestore(&port->lock, flags);
95559
95560 wake_up_interruptible(&port->open_wait);
95561@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
95562 seq_putc(m, '\n');
95563
95564 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
95565- seq_printf(m, "Open count: %d\n", self->port.count);
95566+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
95567 seq_printf(m, "Max data size: %d\n", self->max_data_size);
95568 seq_printf(m, "Max header size: %d\n", self->max_header_size);
95569
95570diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
95571index ae69165..c8b82d8 100644
95572--- a/net/iucv/af_iucv.c
95573+++ b/net/iucv/af_iucv.c
95574@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
95575
95576 write_lock_bh(&iucv_sk_list.lock);
95577
95578- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
95579+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
95580 while (__iucv_get_sock_by_name(name)) {
95581 sprintf(name, "%08x",
95582- atomic_inc_return(&iucv_sk_list.autobind_name));
95583+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
95584 }
95585
95586 write_unlock_bh(&iucv_sk_list.lock);
95587diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
95588index 4fe76ff..426a904 100644
95589--- a/net/iucv/iucv.c
95590+++ b/net/iucv/iucv.c
95591@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
95592 return NOTIFY_OK;
95593 }
95594
95595-static struct notifier_block __refdata iucv_cpu_notifier = {
95596+static struct notifier_block iucv_cpu_notifier = {
95597 .notifier_call = iucv_cpu_notify,
95598 };
95599
95600diff --git a/net/key/af_key.c b/net/key/af_key.c
95601index ab8bd2c..cd2d641 100644
95602--- a/net/key/af_key.c
95603+++ b/net/key/af_key.c
95604@@ -3048,10 +3048,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
95605 static u32 get_acqseq(void)
95606 {
95607 u32 res;
95608- static atomic_t acqseq;
95609+ static atomic_unchecked_t acqseq;
95610
95611 do {
95612- res = atomic_inc_return(&acqseq);
95613+ res = atomic_inc_return_unchecked(&acqseq);
95614 } while (!res);
95615 return res;
95616 }
95617diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
95618index ae36f8e..09d42ac 100644
95619--- a/net/mac80211/cfg.c
95620+++ b/net/mac80211/cfg.c
95621@@ -806,7 +806,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
95622 ret = ieee80211_vif_use_channel(sdata, chandef,
95623 IEEE80211_CHANCTX_EXCLUSIVE);
95624 }
95625- } else if (local->open_count == local->monitors) {
95626+ } else if (local_read(&local->open_count) == local->monitors) {
95627 local->_oper_chandef = *chandef;
95628 ieee80211_hw_config(local, 0);
95629 }
95630@@ -2922,7 +2922,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
95631 else
95632 local->probe_req_reg--;
95633
95634- if (!local->open_count)
95635+ if (!local_read(&local->open_count))
95636 break;
95637
95638 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
95639@@ -3385,8 +3385,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
95640 if (chanctx_conf) {
95641 *chandef = chanctx_conf->def;
95642 ret = 0;
95643- } else if (local->open_count > 0 &&
95644- local->open_count == local->monitors &&
95645+ } else if (local_read(&local->open_count) > 0 &&
95646+ local_read(&local->open_count) == local->monitors &&
95647 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
95648 if (local->use_chanctx)
95649 *chandef = local->monitor_chandef;
95650diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
95651index 9ca8e32..48e4a9b 100644
95652--- a/net/mac80211/ieee80211_i.h
95653+++ b/net/mac80211/ieee80211_i.h
95654@@ -28,6 +28,7 @@
95655 #include <net/ieee80211_radiotap.h>
95656 #include <net/cfg80211.h>
95657 #include <net/mac80211.h>
95658+#include <asm/local.h>
95659 #include "key.h"
95660 #include "sta_info.h"
95661 #include "debug.h"
95662@@ -891,7 +892,7 @@ struct ieee80211_local {
95663 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
95664 spinlock_t queue_stop_reason_lock;
95665
95666- int open_count;
95667+ local_t open_count;
95668 int monitors, cooked_mntrs;
95669 /* number of interfaces with corresponding FIF_ flags */
95670 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
95671diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
95672index 514e90f..56f22bf 100644
95673--- a/net/mac80211/iface.c
95674+++ b/net/mac80211/iface.c
95675@@ -502,7 +502,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95676 break;
95677 }
95678
95679- if (local->open_count == 0) {
95680+ if (local_read(&local->open_count) == 0) {
95681 res = drv_start(local);
95682 if (res)
95683 goto err_del_bss;
95684@@ -545,7 +545,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95685 break;
95686 }
95687
95688- if (local->monitors == 0 && local->open_count == 0) {
95689+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
95690 res = ieee80211_add_virtual_monitor(local);
95691 if (res)
95692 goto err_stop;
95693@@ -653,7 +653,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95694 atomic_inc(&local->iff_promiscs);
95695
95696 if (coming_up)
95697- local->open_count++;
95698+ local_inc(&local->open_count);
95699
95700 if (hw_reconf_flags)
95701 ieee80211_hw_config(local, hw_reconf_flags);
95702@@ -691,7 +691,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95703 err_del_interface:
95704 drv_remove_interface(local, sdata);
95705 err_stop:
95706- if (!local->open_count)
95707+ if (!local_read(&local->open_count))
95708 drv_stop(local);
95709 err_del_bss:
95710 sdata->bss = NULL;
95711@@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95712 }
95713
95714 if (going_down)
95715- local->open_count--;
95716+ local_dec(&local->open_count);
95717
95718 switch (sdata->vif.type) {
95719 case NL80211_IFTYPE_AP_VLAN:
95720@@ -895,7 +895,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95721 }
95722 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
95723
95724- if (local->open_count == 0)
95725+ if (local_read(&local->open_count) == 0)
95726 ieee80211_clear_tx_pending(local);
95727
95728 /*
95729@@ -931,7 +931,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95730
95731 ieee80211_recalc_ps(local, -1);
95732
95733- if (local->open_count == 0) {
95734+ if (local_read(&local->open_count) == 0) {
95735 ieee80211_stop_device(local);
95736
95737 /* no reconfiguring after stop! */
95738@@ -942,7 +942,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95739 ieee80211_configure_filter(local);
95740 ieee80211_hw_config(local, hw_reconf_flags);
95741
95742- if (local->monitors == local->open_count)
95743+ if (local->monitors == local_read(&local->open_count))
95744 ieee80211_add_virtual_monitor(local);
95745 }
95746
95747diff --git a/net/mac80211/main.c b/net/mac80211/main.c
95748index 8a7bfc4..be07e86 100644
95749--- a/net/mac80211/main.c
95750+++ b/net/mac80211/main.c
95751@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
95752 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
95753 IEEE80211_CONF_CHANGE_POWER);
95754
95755- if (changed && local->open_count) {
95756+ if (changed && local_read(&local->open_count)) {
95757 ret = drv_config(local, changed);
95758 /*
95759 * Goal:
95760@@ -921,7 +921,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
95761 hw->queues = IEEE80211_MAX_QUEUES;
95762
95763 local->workqueue =
95764- alloc_ordered_workqueue(wiphy_name(local->hw.wiphy), 0);
95765+ alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
95766 if (!local->workqueue) {
95767 result = -ENOMEM;
95768 goto fail_workqueue;
95769diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
95770index 3401262..d5cd68d 100644
95771--- a/net/mac80211/pm.c
95772+++ b/net/mac80211/pm.c
95773@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
95774 struct ieee80211_sub_if_data *sdata;
95775 struct sta_info *sta;
95776
95777- if (!local->open_count)
95778+ if (!local_read(&local->open_count))
95779 goto suspend;
95780
95781 ieee80211_scan_cancel(local);
95782@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
95783 cancel_work_sync(&local->dynamic_ps_enable_work);
95784 del_timer_sync(&local->dynamic_ps_timer);
95785
95786- local->wowlan = wowlan && local->open_count;
95787+ local->wowlan = wowlan && local_read(&local->open_count);
95788 if (local->wowlan) {
95789 int err = drv_suspend(local, wowlan);
95790 if (err < 0) {
95791@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
95792 WARN_ON(!list_empty(&local->chanctx_list));
95793
95794 /* stop hardware - this must stop RX */
95795- if (local->open_count)
95796+ if (local_read(&local->open_count))
95797 ieee80211_stop_device(local);
95798
95799 suspend:
95800diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
95801index a02bef3..f2f38dd 100644
95802--- a/net/mac80211/rate.c
95803+++ b/net/mac80211/rate.c
95804@@ -712,7 +712,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
95805
95806 ASSERT_RTNL();
95807
95808- if (local->open_count)
95809+ if (local_read(&local->open_count))
95810 return -EBUSY;
95811
95812 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
95813diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
95814index c97a065..ff61928 100644
95815--- a/net/mac80211/rc80211_pid_debugfs.c
95816+++ b/net/mac80211/rc80211_pid_debugfs.c
95817@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
95818
95819 spin_unlock_irqrestore(&events->lock, status);
95820
95821- if (copy_to_user(buf, pb, p))
95822+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
95823 return -EFAULT;
95824
95825 return p;
95826diff --git a/net/mac80211/util.c b/net/mac80211/util.c
95827index 72e6292..e6319eb 100644
95828--- a/net/mac80211/util.c
95829+++ b/net/mac80211/util.c
95830@@ -1472,7 +1472,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
95831 }
95832 #endif
95833 /* everything else happens only if HW was up & running */
95834- if (!local->open_count)
95835+ if (!local_read(&local->open_count))
95836 goto wake_up;
95837
95838 /*
95839@@ -1696,7 +1696,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
95840 local->in_reconfig = false;
95841 barrier();
95842
95843- if (local->monitors == local->open_count && local->monitors > 0)
95844+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
95845 ieee80211_add_virtual_monitor(local);
95846
95847 /*
95848diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
95849index 56d22ca..87c778f 100644
95850--- a/net/netfilter/Kconfig
95851+++ b/net/netfilter/Kconfig
95852@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
95853
95854 To compile it as a module, choose M here. If unsure, say N.
95855
95856+config NETFILTER_XT_MATCH_GRADM
95857+ tristate '"gradm" match support'
95858+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
95859+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
95860+ ---help---
95861+ The gradm match allows to match on grsecurity RBAC being enabled.
95862+ It is useful when iptables rules are applied early on bootup to
95863+ prevent connections to the machine (except from a trusted host)
95864+ while the RBAC system is disabled.
95865+
95866 config NETFILTER_XT_MATCH_HASHLIMIT
95867 tristate '"hashlimit" match support'
95868 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
95869diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
95870index a1abf87..dbcb7ee 100644
95871--- a/net/netfilter/Makefile
95872+++ b/net/netfilter/Makefile
95873@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
95874 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
95875 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
95876 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
95877+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
95878 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
95879 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
95880 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
95881diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
95882index f771390..145b765 100644
95883--- a/net/netfilter/ipset/ip_set_core.c
95884+++ b/net/netfilter/ipset/ip_set_core.c
95885@@ -1820,7 +1820,7 @@ done:
95886 return ret;
95887 }
95888
95889-static struct nf_sockopt_ops so_set __read_mostly = {
95890+static struct nf_sockopt_ops so_set = {
95891 .pf = PF_INET,
95892 .get_optmin = SO_IP_SET,
95893 .get_optmax = SO_IP_SET + 1,
95894diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
95895index a083bda..da661c3 100644
95896--- a/net/netfilter/ipvs/ip_vs_conn.c
95897+++ b/net/netfilter/ipvs/ip_vs_conn.c
95898@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
95899 /* Increase the refcnt counter of the dest */
95900 ip_vs_dest_hold(dest);
95901
95902- conn_flags = atomic_read(&dest->conn_flags);
95903+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
95904 if (cp->protocol != IPPROTO_UDP)
95905 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
95906 flags = cp->flags;
95907@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
95908
95909 cp->control = NULL;
95910 atomic_set(&cp->n_control, 0);
95911- atomic_set(&cp->in_pkts, 0);
95912+ atomic_set_unchecked(&cp->in_pkts, 0);
95913
95914 cp->packet_xmit = NULL;
95915 cp->app = NULL;
95916@@ -1190,7 +1190,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
95917
95918 /* Don't drop the entry if its number of incoming packets is not
95919 located in [0, 8] */
95920- i = atomic_read(&cp->in_pkts);
95921+ i = atomic_read_unchecked(&cp->in_pkts);
95922 if (i > 8 || i < 0) return 0;
95923
95924 if (!todrop_rate[i]) return 0;
95925diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
95926index 23b8eb5..48a8959 100644
95927--- a/net/netfilter/ipvs/ip_vs_core.c
95928+++ b/net/netfilter/ipvs/ip_vs_core.c
95929@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
95930 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
95931 /* do not touch skb anymore */
95932
95933- atomic_inc(&cp->in_pkts);
95934+ atomic_inc_unchecked(&cp->in_pkts);
95935 ip_vs_conn_put(cp);
95936 return ret;
95937 }
95938@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
95939 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
95940 pkts = sysctl_sync_threshold(ipvs);
95941 else
95942- pkts = atomic_add_return(1, &cp->in_pkts);
95943+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
95944
95945 if (ipvs->sync_state & IP_VS_STATE_MASTER)
95946 ip_vs_sync_conn(net, cp, pkts);
95947diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
95948index 9e6c2a0..28552e2 100644
95949--- a/net/netfilter/ipvs/ip_vs_ctl.c
95950+++ b/net/netfilter/ipvs/ip_vs_ctl.c
95951@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
95952 */
95953 ip_vs_rs_hash(ipvs, dest);
95954 }
95955- atomic_set(&dest->conn_flags, conn_flags);
95956+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
95957
95958 /* bind the service */
95959 if (!dest->svc) {
95960@@ -1657,7 +1657,7 @@ proc_do_sync_ports(ctl_table *table, int write,
95961 * align with netns init in ip_vs_control_net_init()
95962 */
95963
95964-static struct ctl_table vs_vars[] = {
95965+static ctl_table_no_const vs_vars[] __read_only = {
95966 {
95967 .procname = "amemthresh",
95968 .maxlen = sizeof(int),
95969@@ -2060,7 +2060,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
95970 " %-7s %-6d %-10d %-10d\n",
95971 &dest->addr.in6,
95972 ntohs(dest->port),
95973- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
95974+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
95975 atomic_read(&dest->weight),
95976 atomic_read(&dest->activeconns),
95977 atomic_read(&dest->inactconns));
95978@@ -2071,7 +2071,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
95979 "%-7s %-6d %-10d %-10d\n",
95980 ntohl(dest->addr.ip),
95981 ntohs(dest->port),
95982- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
95983+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
95984 atomic_read(&dest->weight),
95985 atomic_read(&dest->activeconns),
95986 atomic_read(&dest->inactconns));
95987@@ -2549,7 +2549,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
95988
95989 entry.addr = dest->addr.ip;
95990 entry.port = dest->port;
95991- entry.conn_flags = atomic_read(&dest->conn_flags);
95992+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
95993 entry.weight = atomic_read(&dest->weight);
95994 entry.u_threshold = dest->u_threshold;
95995 entry.l_threshold = dest->l_threshold;
95996@@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
95997 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
95998 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
95999 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
96000- (atomic_read(&dest->conn_flags) &
96001+ (atomic_read_unchecked(&dest->conn_flags) &
96002 IP_VS_CONN_F_FWD_MASK)) ||
96003 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
96004 atomic_read(&dest->weight)) ||
96005@@ -3682,7 +3682,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
96006 {
96007 int idx;
96008 struct netns_ipvs *ipvs = net_ipvs(net);
96009- struct ctl_table *tbl;
96010+ ctl_table_no_const *tbl;
96011
96012 atomic_set(&ipvs->dropentry, 0);
96013 spin_lock_init(&ipvs->dropentry_lock);
96014diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
96015index 5ea26bd..c9bc65f 100644
96016--- a/net/netfilter/ipvs/ip_vs_lblc.c
96017+++ b/net/netfilter/ipvs/ip_vs_lblc.c
96018@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
96019 * IPVS LBLC sysctl table
96020 */
96021 #ifdef CONFIG_SYSCTL
96022-static ctl_table vs_vars_table[] = {
96023+static ctl_table_no_const vs_vars_table[] __read_only = {
96024 {
96025 .procname = "lblc_expiration",
96026 .data = NULL,
96027diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
96028index 50123c2..067c773 100644
96029--- a/net/netfilter/ipvs/ip_vs_lblcr.c
96030+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
96031@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
96032 * IPVS LBLCR sysctl table
96033 */
96034
96035-static ctl_table vs_vars_table[] = {
96036+static ctl_table_no_const vs_vars_table[] __read_only = {
96037 {
96038 .procname = "lblcr_expiration",
96039 .data = NULL,
96040diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
96041index f6046d9..4f10cfd 100644
96042--- a/net/netfilter/ipvs/ip_vs_sync.c
96043+++ b/net/netfilter/ipvs/ip_vs_sync.c
96044@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
96045 cp = cp->control;
96046 if (cp) {
96047 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
96048- pkts = atomic_add_return(1, &cp->in_pkts);
96049+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
96050 else
96051 pkts = sysctl_sync_threshold(ipvs);
96052 ip_vs_sync_conn(net, cp->control, pkts);
96053@@ -758,7 +758,7 @@ control:
96054 if (!cp)
96055 return;
96056 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
96057- pkts = atomic_add_return(1, &cp->in_pkts);
96058+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
96059 else
96060 pkts = sysctl_sync_threshold(ipvs);
96061 goto sloop;
96062@@ -882,7 +882,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
96063
96064 if (opt)
96065 memcpy(&cp->in_seq, opt, sizeof(*opt));
96066- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
96067+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
96068 cp->state = state;
96069 cp->old_state = cp->state;
96070 /*
96071diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
96072index b75ff64..0c51bbe 100644
96073--- a/net/netfilter/ipvs/ip_vs_xmit.c
96074+++ b/net/netfilter/ipvs/ip_vs_xmit.c
96075@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
96076 else
96077 rc = NF_ACCEPT;
96078 /* do not touch skb anymore */
96079- atomic_inc(&cp->in_pkts);
96080+ atomic_inc_unchecked(&cp->in_pkts);
96081 goto out;
96082 }
96083
96084@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
96085 else
96086 rc = NF_ACCEPT;
96087 /* do not touch skb anymore */
96088- atomic_inc(&cp->in_pkts);
96089+ atomic_inc_unchecked(&cp->in_pkts);
96090 goto out;
96091 }
96092
96093diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
96094index 2d3030a..7ba1c0a 100644
96095--- a/net/netfilter/nf_conntrack_acct.c
96096+++ b/net/netfilter/nf_conntrack_acct.c
96097@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
96098 #ifdef CONFIG_SYSCTL
96099 static int nf_conntrack_acct_init_sysctl(struct net *net)
96100 {
96101- struct ctl_table *table;
96102+ ctl_table_no_const *table;
96103
96104 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
96105 GFP_KERNEL);
96106diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
96107index 0283bae..5febcb0 100644
96108--- a/net/netfilter/nf_conntrack_core.c
96109+++ b/net/netfilter/nf_conntrack_core.c
96110@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
96111 #define DYING_NULLS_VAL ((1<<30)+1)
96112 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
96113
96114+#ifdef CONFIG_GRKERNSEC_HIDESYM
96115+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
96116+#endif
96117+
96118 int nf_conntrack_init_net(struct net *net)
96119 {
96120 int ret;
96121@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
96122 goto err_stat;
96123 }
96124
96125+#ifdef CONFIG_GRKERNSEC_HIDESYM
96126+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
96127+#else
96128 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
96129+#endif
96130 if (!net->ct.slabname) {
96131 ret = -ENOMEM;
96132 goto err_slabname;
96133diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
96134index 1df1761..ce8b88a 100644
96135--- a/net/netfilter/nf_conntrack_ecache.c
96136+++ b/net/netfilter/nf_conntrack_ecache.c
96137@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
96138 #ifdef CONFIG_SYSCTL
96139 static int nf_conntrack_event_init_sysctl(struct net *net)
96140 {
96141- struct ctl_table *table;
96142+ ctl_table_no_const *table;
96143
96144 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
96145 GFP_KERNEL);
96146diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
96147index 974a2a4..52cc6ff 100644
96148--- a/net/netfilter/nf_conntrack_helper.c
96149+++ b/net/netfilter/nf_conntrack_helper.c
96150@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
96151
96152 static int nf_conntrack_helper_init_sysctl(struct net *net)
96153 {
96154- struct ctl_table *table;
96155+ ctl_table_no_const *table;
96156
96157 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
96158 GFP_KERNEL);
96159diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
96160index 0ab9636..cea3c6a 100644
96161--- a/net/netfilter/nf_conntrack_proto.c
96162+++ b/net/netfilter/nf_conntrack_proto.c
96163@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
96164
96165 static void
96166 nf_ct_unregister_sysctl(struct ctl_table_header **header,
96167- struct ctl_table **table,
96168+ ctl_table_no_const **table,
96169 unsigned int users)
96170 {
96171 if (users > 0)
96172diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
96173index a99b6c3..cb372f9 100644
96174--- a/net/netfilter/nf_conntrack_proto_dccp.c
96175+++ b/net/netfilter/nf_conntrack_proto_dccp.c
96176@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
96177 const char *msg;
96178 u_int8_t state;
96179
96180- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
96181+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
96182 BUG_ON(dh == NULL);
96183
96184 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
96185@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
96186 out_invalid:
96187 if (LOG_INVALID(net, IPPROTO_DCCP))
96188 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
96189- NULL, msg);
96190+ NULL, "%s", msg);
96191 return false;
96192 }
96193
96194@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
96195 u_int8_t type, old_state, new_state;
96196 enum ct_dccp_roles role;
96197
96198- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
96199+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
96200 BUG_ON(dh == NULL);
96201 type = dh->dccph_type;
96202
96203@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
96204 unsigned int cscov;
96205 const char *msg;
96206
96207- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
96208+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
96209 if (dh == NULL) {
96210 msg = "nf_ct_dccp: short packet ";
96211 goto out_invalid;
96212@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
96213
96214 out_invalid:
96215 if (LOG_INVALID(net, IPPROTO_DCCP))
96216- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
96217+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
96218 return -NF_ACCEPT;
96219 }
96220
96221diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
96222index 4d4d8f1..e0f9a32 100644
96223--- a/net/netfilter/nf_conntrack_proto_tcp.c
96224+++ b/net/netfilter/nf_conntrack_proto_tcp.c
96225@@ -526,7 +526,7 @@ static bool tcp_in_window(const struct nf_conn *ct,
96226 const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
96227 __u32 seq, ack, sack, end, win, swin;
96228 s16 receiver_offset;
96229- bool res;
96230+ bool res, in_recv_win;
96231
96232 /*
96233 * Get the required data from the packet.
96234@@ -649,14 +649,18 @@ static bool tcp_in_window(const struct nf_conn *ct,
96235 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
96236 receiver->td_scale);
96237
96238+ /* Is the ending sequence in the receive window (if available)? */
96239+ in_recv_win = !receiver->td_maxwin ||
96240+ after(end, sender->td_end - receiver->td_maxwin - 1);
96241+
96242 pr_debug("tcp_in_window: I=%i II=%i III=%i IV=%i\n",
96243 before(seq, sender->td_maxend + 1),
96244- after(end, sender->td_end - receiver->td_maxwin - 1),
96245+ (in_recv_win ? 1 : 0),
96246 before(sack, receiver->td_end + 1),
96247 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1));
96248
96249 if (before(seq, sender->td_maxend + 1) &&
96250- after(end, sender->td_end - receiver->td_maxwin - 1) &&
96251+ in_recv_win &&
96252 before(sack, receiver->td_end + 1) &&
96253 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1)) {
96254 /*
96255@@ -725,7 +729,7 @@ static bool tcp_in_window(const struct nf_conn *ct,
96256 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
96257 "nf_ct_tcp: %s ",
96258 before(seq, sender->td_maxend + 1) ?
96259- after(end, sender->td_end - receiver->td_maxwin - 1) ?
96260+ in_recv_win ?
96261 before(sack, receiver->td_end + 1) ?
96262 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1) ? "BUG"
96263 : "ACK is under the lower bound (possible overly delayed ACK)"
96264diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
96265index bd700b4..4a3dc61 100644
96266--- a/net/netfilter/nf_conntrack_standalone.c
96267+++ b/net/netfilter/nf_conntrack_standalone.c
96268@@ -471,7 +471,7 @@ static ctl_table nf_ct_netfilter_table[] = {
96269
96270 static int nf_conntrack_standalone_init_sysctl(struct net *net)
96271 {
96272- struct ctl_table *table;
96273+ ctl_table_no_const *table;
96274
96275 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
96276 GFP_KERNEL);
96277diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
96278index 902fb0a..87f7fdb 100644
96279--- a/net/netfilter/nf_conntrack_timestamp.c
96280+++ b/net/netfilter/nf_conntrack_timestamp.c
96281@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
96282 #ifdef CONFIG_SYSCTL
96283 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
96284 {
96285- struct ctl_table *table;
96286+ ctl_table_no_const *table;
96287
96288 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
96289 GFP_KERNEL);
96290diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
96291index 3b18dd1..f79e0ca 100644
96292--- a/net/netfilter/nf_log.c
96293+++ b/net/netfilter/nf_log.c
96294@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
96295
96296 #ifdef CONFIG_SYSCTL
96297 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
96298-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
96299+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
96300
96301 static int nf_log_proc_dostring(ctl_table *table, int write,
96302 void __user *buffer, size_t *lenp, loff_t *ppos)
96303@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
96304 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
96305 mutex_unlock(&nf_log_mutex);
96306 } else {
96307+ ctl_table_no_const nf_log_table = *table;
96308+
96309 mutex_lock(&nf_log_mutex);
96310 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
96311 lockdep_is_held(&nf_log_mutex));
96312 if (!logger)
96313- table->data = "NONE";
96314+ nf_log_table.data = "NONE";
96315 else
96316- table->data = logger->name;
96317- r = proc_dostring(table, write, buffer, lenp, ppos);
96318+ nf_log_table.data = logger->name;
96319+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
96320 mutex_unlock(&nf_log_mutex);
96321 }
96322
96323diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
96324index f042ae5..30ea486 100644
96325--- a/net/netfilter/nf_sockopt.c
96326+++ b/net/netfilter/nf_sockopt.c
96327@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
96328 }
96329 }
96330
96331- list_add(&reg->list, &nf_sockopts);
96332+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
96333 out:
96334 mutex_unlock(&nf_sockopt_mutex);
96335 return ret;
96336@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
96337 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
96338 {
96339 mutex_lock(&nf_sockopt_mutex);
96340- list_del(&reg->list);
96341+ pax_list_del((struct list_head *)&reg->list);
96342 mutex_unlock(&nf_sockopt_mutex);
96343 }
96344 EXPORT_SYMBOL(nf_unregister_sockopt);
96345diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
96346index 962e979..e46f350 100644
96347--- a/net/netfilter/nfnetlink_log.c
96348+++ b/net/netfilter/nfnetlink_log.c
96349@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
96350 struct nfnl_log_net {
96351 spinlock_t instances_lock;
96352 struct hlist_head instance_table[INSTANCE_BUCKETS];
96353- atomic_t global_seq;
96354+ atomic_unchecked_t global_seq;
96355 };
96356
96357 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
96358@@ -419,6 +419,7 @@ __build_packet_message(struct nfnl_log_net *log,
96359 nfmsg->version = NFNETLINK_V0;
96360 nfmsg->res_id = htons(inst->group_num);
96361
96362+ memset(&pmsg, 0, sizeof(pmsg));
96363 pmsg.hw_protocol = skb->protocol;
96364 pmsg.hook = hooknum;
96365
96366@@ -498,7 +499,10 @@ __build_packet_message(struct nfnl_log_net *log,
96367 if (indev && skb->dev &&
96368 skb->mac_header != skb->network_header) {
96369 struct nfulnl_msg_packet_hw phw;
96370- int len = dev_parse_header(skb, phw.hw_addr);
96371+ int len;
96372+
96373+ memset(&phw, 0, sizeof(phw));
96374+ len = dev_parse_header(skb, phw.hw_addr);
96375 if (len > 0) {
96376 phw.hw_addrlen = htons(len);
96377 if (nla_put(inst->skb, NFULA_HWADDR, sizeof(phw), &phw))
96378@@ -559,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
96379 /* global sequence number */
96380 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
96381 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
96382- htonl(atomic_inc_return(&log->global_seq))))
96383+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
96384 goto nla_put_failure;
96385
96386 if (data_len) {
96387diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
96388index 5352b2d..e0083ce 100644
96389--- a/net/netfilter/nfnetlink_queue_core.c
96390+++ b/net/netfilter/nfnetlink_queue_core.c
96391@@ -444,7 +444,10 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
96392 if (indev && entskb->dev &&
96393 entskb->mac_header != entskb->network_header) {
96394 struct nfqnl_msg_packet_hw phw;
96395- int len = dev_parse_header(entskb, phw.hw_addr);
96396+ int len;
96397+
96398+ memset(&phw, 0, sizeof(phw));
96399+ len = dev_parse_header(entskb, phw.hw_addr);
96400 if (len) {
96401 phw.hw_addrlen = htons(len);
96402 if (nla_put(skb, NFQA_HWADDR, sizeof(phw), &phw))
96403diff --git a/net/netfilter/xt_TCPMSS.c b/net/netfilter/xt_TCPMSS.c
96404index 7011c71..6113cc7 100644
96405--- a/net/netfilter/xt_TCPMSS.c
96406+++ b/net/netfilter/xt_TCPMSS.c
96407@@ -52,7 +52,8 @@ tcpmss_mangle_packet(struct sk_buff *skb,
96408 {
96409 const struct xt_tcpmss_info *info = par->targinfo;
96410 struct tcphdr *tcph;
96411- unsigned int tcplen, i;
96412+ int len, tcp_hdrlen;
96413+ unsigned int i;
96414 __be16 oldval;
96415 u16 newmss;
96416 u8 *opt;
96417@@ -64,11 +65,14 @@ tcpmss_mangle_packet(struct sk_buff *skb,
96418 if (!skb_make_writable(skb, skb->len))
96419 return -1;
96420
96421- tcplen = skb->len - tcphoff;
96422+ len = skb->len - tcphoff;
96423+ if (len < (int)sizeof(struct tcphdr))
96424+ return -1;
96425+
96426 tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
96427+ tcp_hdrlen = tcph->doff * 4;
96428
96429- /* Header cannot be larger than the packet */
96430- if (tcplen < tcph->doff*4)
96431+ if (len < tcp_hdrlen)
96432 return -1;
96433
96434 if (info->mss == XT_TCPMSS_CLAMP_PMTU) {
96435@@ -87,9 +91,8 @@ tcpmss_mangle_packet(struct sk_buff *skb,
96436 newmss = info->mss;
96437
96438 opt = (u_int8_t *)tcph;
96439- for (i = sizeof(struct tcphdr); i < tcph->doff*4; i += optlen(opt, i)) {
96440- if (opt[i] == TCPOPT_MSS && tcph->doff*4 - i >= TCPOLEN_MSS &&
96441- opt[i+1] == TCPOLEN_MSS) {
96442+ for (i = sizeof(struct tcphdr); i <= tcp_hdrlen - TCPOLEN_MSS; i += optlen(opt, i)) {
96443+ if (opt[i] == TCPOPT_MSS && opt[i+1] == TCPOLEN_MSS) {
96444 u_int16_t oldmss;
96445
96446 oldmss = (opt[i+2] << 8) | opt[i+3];
96447@@ -112,9 +115,10 @@ tcpmss_mangle_packet(struct sk_buff *skb,
96448 }
96449
96450 /* There is data after the header so the option can't be added
96451- without moving it, and doing so may make the SYN packet
96452- itself too large. Accept the packet unmodified instead. */
96453- if (tcplen > tcph->doff*4)
96454+ * without moving it, and doing so may make the SYN packet
96455+ * itself too large. Accept the packet unmodified instead.
96456+ */
96457+ if (len > tcp_hdrlen)
96458 return 0;
96459
96460 /*
96461@@ -143,10 +147,10 @@ tcpmss_mangle_packet(struct sk_buff *skb,
96462 newmss = min(newmss, (u16)1220);
96463
96464 opt = (u_int8_t *)tcph + sizeof(struct tcphdr);
96465- memmove(opt + TCPOLEN_MSS, opt, tcplen - sizeof(struct tcphdr));
96466+ memmove(opt + TCPOLEN_MSS, opt, len - sizeof(struct tcphdr));
96467
96468 inet_proto_csum_replace2(&tcph->check, skb,
96469- htons(tcplen), htons(tcplen + TCPOLEN_MSS), 1);
96470+ htons(len), htons(len + TCPOLEN_MSS), 1);
96471 opt[0] = TCPOPT_MSS;
96472 opt[1] = TCPOLEN_MSS;
96473 opt[2] = (newmss & 0xff00) >> 8;
96474diff --git a/net/netfilter/xt_TCPOPTSTRIP.c b/net/netfilter/xt_TCPOPTSTRIP.c
96475index b68fa19..625fa1d 100644
96476--- a/net/netfilter/xt_TCPOPTSTRIP.c
96477+++ b/net/netfilter/xt_TCPOPTSTRIP.c
96478@@ -38,7 +38,7 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
96479 struct tcphdr *tcph;
96480 u_int16_t n, o;
96481 u_int8_t *opt;
96482- int len;
96483+ int len, tcp_hdrlen;
96484
96485 /* This is a fragment, no TCP header is available */
96486 if (par->fragoff != 0)
96487@@ -52,7 +52,9 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
96488 return NF_DROP;
96489
96490 tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
96491- if (tcph->doff * 4 > len)
96492+ tcp_hdrlen = tcph->doff * 4;
96493+
96494+ if (len < tcp_hdrlen)
96495 return NF_DROP;
96496
96497 opt = (u_int8_t *)tcph;
96498@@ -61,10 +63,10 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
96499 * Walk through all TCP options - if we find some option to remove,
96500 * set all octets to %TCPOPT_NOP and adjust checksum.
96501 */
96502- for (i = sizeof(struct tcphdr); i < tcp_hdrlen(skb); i += optl) {
96503+ for (i = sizeof(struct tcphdr); i < tcp_hdrlen - 1; i += optl) {
96504 optl = optlen(opt, i);
96505
96506- if (i + optl > tcp_hdrlen(skb))
96507+ if (i + optl > tcp_hdrlen)
96508 break;
96509
96510 if (!tcpoptstrip_test_bit(info->strip_bmap, opt[i]))
96511diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
96512new file mode 100644
96513index 0000000..c566332
96514--- /dev/null
96515+++ b/net/netfilter/xt_gradm.c
96516@@ -0,0 +1,51 @@
96517+/*
96518+ * gradm match for netfilter
96519